diff --git a/code/lib/preview-api/src/modules/store/autoTitle.test.ts b/code/lib/preview-api/src/modules/store/autoTitle.test.ts index cc0c0f42dc64..e753db93b15e 100644 --- a/code/lib/preview-api/src/modules/store/autoTitle.test.ts +++ b/code/lib/preview-api/src/modules/store/autoTitle.test.ts @@ -177,6 +177,16 @@ describe('userOrAutoTitleFromSpecifier', () => { ).toMatchInlineSnapshot(`to/button`); }); + it('match with case-insensitive trailing duplicate', () => { + expect( + userOrAuto( + './path/to/button/Button.stories.js', + normalizeStoriesEntry({ directory: './path' }, options), + undefined + ) + ).toMatchInlineSnapshot(`to/Button`); + }); + it('match with trailing index', () => { expect( userOrAuto( diff --git a/code/lib/preview-api/src/modules/store/autoTitle.ts b/code/lib/preview-api/src/modules/store/autoTitle.ts index b925c7fc3d24..e230cb4f10d2 100644 --- a/code/lib/preview-api/src/modules/store/autoTitle.ts +++ b/code/lib/preview-api/src/modules/store/autoTitle.ts @@ -15,11 +15,12 @@ const sanitize = (parts: string[]) => { if (parts.length === 1) return [lastStripped]; const nextToLast = parts[parts.length - 2]; + if (lastStripped && nextToLast && lastStripped.toLowerCase() === nextToLast.toLowerCase()) { + return [...parts.slice(0, -2), lastStripped]; + } + return lastStripped && - nextToLast && - (lastStripped === nextToLast || - /^(story|stories)([.][^.]+)$/i.test(last) || - /^index$/i.test(lastStripped)) + (/^(story|stories)([.][^.]+)$/i.test(last) || /^index$/i.test(lastStripped)) ? parts.slice(0, -1) : [...parts.slice(0, -1), lastStripped]; };