Skip to content

Commit

Permalink
Merge pull request #22154 from storybookjs/tom/21798-set-docs-paramet…
Browse files Browse the repository at this point in the history
…ers-in-index
  • Loading branch information
tmeasday authored and shilman committed Apr 24, 2023
1 parent 94afe49 commit 2bdb85d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 13 deletions.
38 changes: 26 additions & 12 deletions code/e2e-tests/addon-backgrounds.spec.ts
Expand Up @@ -3,6 +3,7 @@ import process from 'process';
import { SbPage } from './util';

const storybookUrl = process.env.STORYBOOK_URL || 'http://localhost:8001';
const templateName = process.env.STORYBOOK_TEMPLATE_NAME;

test.describe('addon-backgrounds', () => {
test.beforeEach(async ({ page }) => {
Expand Down Expand Up @@ -38,21 +39,34 @@ test.describe('addon-backgrounds', () => {
await expect(sbPage.page.locator(backgroundToolbarSelector)).toBeVisible();
});

test('button should appear for attached docs pages', async ({ page }) => {
const sbPage = new SbPage(page);
test.describe('docs pages', () => {
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();
});
await sbPage.navigateToStory('example/button', 'docs');
await expect(sbPage.page.locator(backgroundToolbarSelector)).toBeVisible();
});

test('button should appear for unattached docs pages', async ({ page }) => {
const sbPage = new SbPage(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

// We start on the introduction page by default.
await sbPage.page.waitForURL((url) =>
url.search.includes(`path=/docs/example-introduction--docs`)
);
// 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'
);

await expect(sbPage.page.locator(backgroundToolbarSelector)).toBeVisible();
const sbPage = new SbPage(page);

// We start on the introduction page by default.
await sbPage.page.waitForURL((url) =>
url.search.includes(`path=/docs/example-introduction--docs`)
);

await expect(sbPage.page.locator(backgroundToolbarSelector)).toBeVisible();
});
});
});
12 changes: 12 additions & 0 deletions code/lib/preview-api/src/modules/core-client/start.test.ts
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
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

0 comments on commit 2bdb85d

Please sign in to comment.