mirror of
https://github.com/storybookjs/storybook.git
synced 2025-03-16 05:03:11 +08:00
Add test for trimming group/component names.
This commit is contained in:
parent
0f7a3a07be
commit
627a127851
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user