Skip to content

Commit

Permalink
Ensure we return docs stories in index order
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeasday committed Mar 9, 2022
1 parent ceade78 commit f19c992
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
19 changes: 19 additions & 0 deletions lib/store/src/StoryStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,25 @@ describe('StoryStore', () => {
expect(stories).toHaveLength(2);
expect(stories.map((s) => s.id)).toEqual(['component-one--a', 'component-one--b']);
});

it('returns them in the order they are in the index, not the file', async () => {
const store = new StoryStore();
store.setProjectAnnotations(projectAnnotations);
const reversedIndex = {
v: 3,
stories: {
'component-one--b': storyIndex.stories['component-one--b'],
'component-one--a': storyIndex.stories['component-one--a'],
},
};
store.initialize({ storyIndex: reversedIndex, importFn, cache: false });

const csfFile = await store.loadCSFFileByStoryId('component-one--a');
const stories = store.componentStoriesFromCSFFile({ csfFile });

expect(stories).toHaveLength(2);
expect(stories.map((s) => s.id)).toEqual(['component-one--b', 'component-one--a']);
});
});

describe('getStoryContext', () => {
Expand Down
6 changes: 3 additions & 3 deletions lib/store/src/StoryStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ export class StoryStore<TFramework extends AnyFramework> {

// If we have a CSF file we can get all the stories from it synchronously
componentStoriesFromCSFFile({ csfFile }: { csfFile: CSFFile<TFramework> }): Story<TFramework>[] {
return Object.keys(csfFile.stories).map((storyId: StoryId) =>
this.storyFromCSFFile({ storyId, csfFile })
);
return Object.keys(this.storyIndex.stories)
.filter((storyId: StoryId) => !!csfFile.stories[storyId])
.map((storyId: StoryId) => this.storyFromCSFFile({ storyId, csfFile }));
}

// A prepared story does not include args, globals or hooks. These are stored in the story store
Expand Down

0 comments on commit f19c992

Please sign in to comment.