Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addon-docs: DocsPage story order should match the index #17669

Merged
merged 1 commit into from Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions lib/store/src/StoryStore.test.ts
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
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