Add a test for order, fix existing tests

This commit is contained in:
Rob Snow 2019-05-06 21:10:33 -07:00
parent 453bb5dd4f
commit d3a04d5a65
2 changed files with 27 additions and 2 deletions

View File

@ -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');
});
});
});

View File

@ -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']);
});
});