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

Core: Pass parameters in SET_INDEX for docs entries #22154

Merged
merged 2 commits into from
Apr 19, 2023
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
20 changes: 12 additions & 8 deletions code/e2e-tests/addon-backgrounds.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,25 @@ test.describe('addon-backgrounds', () => {
});

test.describe('docs pages', () => {
// eslint-disable-next-line jest/no-disabled-tests
test.skip(
// eslint-disable-next-line jest/valid-title
templateName.includes('ssv6'),
'Only run this test for Sandboxes with StoryStoreV7 enabled'
);

test('button should appear for attached docs pages', async ({ page }) => {
const sbPage = new SbPage(page);

await sbPage.navigateToStory('example/button', 'docs');
await expect(sbPage.page.locator(backgroundToolbarSelector)).toBeVisible();
});

test('button should appear for unattached docs pages', async ({ page }) => {
test('button should appear for unattached .mdx files', async ({ page }) => {
// SSv6 does not support .mdx files. There is a unattached stories.mdx file
// at /docs/addons-docs-stories-mdx-unattached--docs, but these are functionally
// really attached

// eslint-disable-next-line jest/no-disabled-tests
test.skip(
// eslint-disable-next-line jest/valid-title
templateName.includes('ssv6'),
'Only run this test for Sandboxes with StoryStoreV7 enabled'
);

const sbPage = new SbPage(page);

// We start on the introduction page by default.
Expand Down
12 changes: 12 additions & 0 deletions code/lib/preview-api/src/modules/core-client/start.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,10 @@ describe('start', () => {
"id": "introduction",
"importPath": "./Introduction.stories.mdx",
"name": undefined,
"parameters": Object {
"fileName": "./Introduction.stories.mdx",
"renderer": "test",
},
"storiesImports": Array [],
"tags": Array [
"stories-mdx",
Expand Down Expand Up @@ -1244,6 +1248,10 @@ describe('start', () => {
"id": "component-b--docs",
"importPath": "file2",
"name": "Docs",
"parameters": Object {
"fileName": "file2",
"renderer": "test",
},
"storiesImports": Array [],
"tags": Array [
"autodocs",
Expand Down Expand Up @@ -1277,6 +1285,10 @@ describe('start', () => {
"id": "component-c--docs",
"importPath": "exports-map-0",
"name": "Docs",
"parameters": Object {
"fileName": "exports-map-0",
"renderer": "test",
},
"storiesImports": Array [],
"tags": Array [
"component-tag",
Expand Down
10 changes: 9 additions & 1 deletion code/lib/preview-api/src/modules/store/StoryStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,9 @@ export class StoryStore<TRenderer extends Renderer> {

getSetIndexPayload(): API_PreparedStoryIndex {
if (!this.storyIndex) throw new Error('getSetIndexPayload called before initialization');
if (!this.cachedCSFFiles)
throw new Error('Cannot call getSetIndexPayload() unless you call cacheAllCSFFiles() first');
const { cachedCSFFiles } = this;

const stories = this.extract({ includeDocsOnly: true });

Expand All @@ -404,7 +407,12 @@ export class StoryStore<TRenderer extends Renderer> {
argTypes: stories[id].argTypes,
parameters: stories[id].parameters,
}
: entry,
: {
...entry,
parameters: this.preparedMetaFromCSFFile({
csfFile: cachedCSFFiles[entry.importPath],
}).parameters,
},
])
),
};
Expand Down