mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-07 07:21:17 +08:00
Add a test for order, fix existing tests
This commit is contained in:
parent
453bb5dd4f
commit
d3a04d5a65
@ -191,4 +191,29 @@ describe('preview.story_store', () => {
|
||||
expect(store.setSelection.mock.calls[0][0].getDecorated()).toEqual(storyFn);
|
||||
});
|
||||
});
|
||||
|
||||
describe('story sorting', () => {
|
||||
const storySort = (a, b) => a[1].id.localeCompare(b[1].id);
|
||||
it('should use the sorting function of the story parameter object', () => {
|
||||
const store = new StoryStore({ channel });
|
||||
store.addStory(
|
||||
...make('kind-2', 'a-story-2.1', () => 0, { fileName: 'bar.js', options: { storySort } })
|
||||
);
|
||||
store.addStory(
|
||||
...make('kind-1', 'z-story-1.1', () => 0, { fileName: 'foo.js', options: { storySort } })
|
||||
);
|
||||
store.addStory(
|
||||
...make('kind-1', 'story-1.2', () => 0, { fileName: 'foo-2.js', options: { storySort } })
|
||||
);
|
||||
store.addStory(
|
||||
...make('kind-2', 'story-2.1', () => 0, { fileName: 'bar.js', options: { storySort } })
|
||||
);
|
||||
|
||||
const stories = Object.values(store.extract());
|
||||
expect(stories[0].id).toBe('kind-1--story-1-2');
|
||||
expect(stories[1].id).toBe('kind-1--z-story-1-1');
|
||||
expect(stories[2].id).toBe('kind-2--a-story-2-1');
|
||||
expect(stories[3].id).toBe('kind-2--story-2-1');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -164,7 +164,7 @@ describe('getPrevious', () => {
|
||||
id: '3-31',
|
||||
...withRoot,
|
||||
});
|
||||
expect(output).toBe(withRoot.dataset['1-12']);
|
||||
expect(output).toBe(withRoot.dataset['2']);
|
||||
});
|
||||
});
|
||||
|
||||
@ -210,7 +210,7 @@ describe('getNext', () => {
|
||||
});
|
||||
test('to next parent with root as parent - skip root', () => {
|
||||
const output = utils.getNext({ id: '1-12', ...withRoot });
|
||||
expect(output).toBe(withRoot.dataset['3-31']);
|
||||
expect(output).toBe(withRoot.dataset['2']);
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user