Skip to content

Commit

Permalink
Add e2e tests to verify parameters.docs.source.type === 'code' behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinpalkovic committed Apr 12, 2023
1 parent afcd828 commit e9540bc
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
10 changes: 10 additions & 0 deletions code/addons/docs/template/stories/docspage/basic.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,14 @@ export const Disabled = {
*/
export const Another = {
args: { label: 'Another' },
parameters: {
docs: {
source: {
type: 'code',
},
},
},
play: async () => {
await new Promise((resolve) => resolve('Play function'));
},
};
45 changes: 45 additions & 0 deletions code/e2e-tests/addon-docs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,51 @@ test.describe('addon-docs', () => {
await new SbPage(page).waitUntilLoaded();
});

test('should show descriptions for stories', async ({ page }) => {
const skipped = [
// SSv6 does not render stories in the correct order in our sandboxes
'internal\\/ssv6',
];
test.skip(
new RegExp(`^${skipped.join('|')}`, 'i').test(`${templateName}`),
`Skipping ${templateName}, because of wrong ordering of stories on docs page`
);

const sbPage = new SbPage(page);
await sbPage.navigateToStory('addons/docs/docspage/basic', 'docs');
const root = sbPage.previewRoot();

const basicStories = root.locator('#anchor--addons-docs-docspage-basic--basic');
const secondBasicStory = (await basicStories.all())[1];
await expect(secondBasicStory).toContainText('A basic button');

const anotherStory = root.locator('#anchor--addons-docs-docspage-basic--another');
await expect(anotherStory).toContainText('Another button, just to show multiple stories');
});

test('should show source=code view for stories', async ({ page }) => {
const skipped = [
// SSv6 does not render stories in the correct order in our sandboxes
'internal\\/ssv6',
];
test.skip(
new RegExp(`^${skipped.join('|')}`, 'i').test(`${templateName}`),
`Skipping ${templateName}, because of wrong ordering of stories on docs page`
);

const sbPage = new SbPage(page);
await sbPage.navigateToStory('addons/docs/docspage/basic', 'docs');
const root = sbPage.previewRoot();

// Click on the third button which has the text "Show code"
const showCodeButton = (await root.locator('button', { hasText: 'Show Code' }).all())[2];
await showCodeButton.click();
const copyButton = root.locator('button', { hasText: 'Copy' });
await copyButton.click();
const sourceCode = root.locator('.language-html');
await expect(sourceCode.textContent()).resolves.toMatchSnapshot();
});

test('should render errors', async ({ page }) => {
const sbPage = new SbPage(page);
await sbPage.navigateToStory('addons/docs/docspage/error', 'docs');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
args: {
label: 'Another'
},
parameters: {
docs: {
source: {
type: 'code'
}
}
},
play: async () => {
await new Promise(resolve => resolve('Play function'));
}
}

0 comments on commit e9540bc

Please sign in to comment.