diff --git a/lib/api/src/tests/stories.test.js b/lib/api/src/tests/stories.test.js index 5ba12abfe525..b700c9be51d6 100644 --- a/lib/api/src/tests/stories.test.js +++ b/lib/api/src/tests/stories.test.js @@ -205,6 +205,48 @@ describe('stories API', () => { }); }); + it('trims whitespace of group/component names (which originate from the kind)', () => { + const navigate = jest.fn(); + const store = createMockStore(); + + const { + api: { setStories }, + } = initStories({ store, navigate, provider }); + + setStories({ + 'design-system-some-component--my-story': { + kind: ' Design System / Some Component ', // note the leading/trailing whitespace around each part of the path + name: ' My Story ', // we only trim the path, so this will be kept as-is (it may intentionally have whitespace) + parameters, + path: 'design-system-some-component--my-story', + id: 'design-system-some-component--my-story', + args: {}, + }, + }); + + const { storiesHash: storedStoriesHash } = store.getState(); + + // We need exact key ordering, even if in theory JS doesn't guarantee it + expect(Object.keys(storedStoriesHash)).toEqual([ + 'design-system', + 'design-system-some-component', + 'design-system-some-component--my-story', + ]); + expect(storedStoriesHash['design-system']).toMatchObject({ + isRoot: true, + name: 'Design System', // root name originates from `kind`, so it gets trimmed + }); + expect(storedStoriesHash['design-system-some-component']).toMatchObject({ + isComponent: true, + name: 'Some Component', // component name originates from `kind`, so it gets trimmed + }); + expect(storedStoriesHash['design-system-some-component--my-story']).toMatchObject({ + isLeaf: true, + kind: ' Design System / Some Component ', // kind is kept as-is, because it may be used as identifier + name: ' My Story ', // story name is kept as-is, because it's set directly on the story + }); + }); + it('sets roots when showRoots = true', () => { const navigate = jest.fn(); const store = createMockStore();