-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathstorybook-smart.test.ts
39 lines (34 loc) · 1.27 KB
/
storybook-smart.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { expect, Page } from '@playwright/test';
import componentList from './componentList.json';
import { openStory, storybookTest } from './storybook-fixture';
for (const [component, stories] of Object.entries(componentList)) {
storybookTest.describe(`Smart tests for component: ${component}`, () => {
for (const story of stories) {
const storyName = story.split('--')[1];
storybookTest(
`Smart test for story: ${storyName}`,
async ({ page, browserName }, testInfo) => {
function getScreenshotName(postfix?: string) {
return `${component}-${story.split('--')[1]}-${
postfix ? postfix : ''
}.png`;
}
await openStory(page, story);
expect(await page.screenshot()).toMatchSnapshot(
getScreenshotName('1'),
);
await clickOnSingleButtonIfExists(page, getScreenshotName('2'));
},
);
}
});
}
async function clickOnSingleButtonIfExists(page: Page, screenshotName: string) {
const singleButtonLocator = page.getByRole('button');
if ((await singleButtonLocator.count()) === 1) {
await singleButtonLocator.click();
expect(await page.screenshot({ animations: 'disabled' })).toMatchSnapshot(
screenshotName,
);
}
}