Skip to content

Commit befb814

Browse files
authored
test: Playwright change theme (#232)
1 parent 0fba9c2 commit befb814

File tree

3 files changed

+11
-17
lines changed

3 files changed

+11
-17
lines changed

playwright/core/expectScreenshotFixture.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,7 @@ export const expectScreenshotFixture: PlaywrightFixture<ExpectScreenshotFixture>
1212
screenshotName,
1313
...pageScreenshotOptions
1414
} = {}) => {
15-
const captureScreenshot = async (theme: string) => {
16-
const root = page.locator('#root');
17-
18-
await root.evaluate((el, theme) => {
19-
el.classList.value = `g-root g-root_theme_${theme}`;
20-
}, theme);
21-
15+
const captureScreenshot = async () => {
2216
return (component || page.locator('.playwright-wrapper-test')).screenshot({
2317
animations: 'disabled',
2418
...pageScreenshotOptions,
@@ -27,12 +21,14 @@ export const expectScreenshotFixture: PlaywrightFixture<ExpectScreenshotFixture>
2721

2822
const nameScreenshot = testInfo.titlePath.slice(1).join(' ');
2923

30-
expect(await captureScreenshot('dark')).toMatchSnapshot({
31-
name: `${screenshotName || nameScreenshot} dark.png`,
24+
expect(await captureScreenshot()).toMatchSnapshot({
25+
name: `${screenshotName || nameScreenshot} light.png`,
3226
});
3327

34-
expect(await captureScreenshot('light')).toMatchSnapshot({
35-
name: `${screenshotName || nameScreenshot} light.png`,
28+
await page.emulateMedia({colorScheme: 'dark'});
29+
30+
expect(await captureScreenshot()).toMatchSnapshot({
31+
name: `${screenshotName || nameScreenshot} dark.png`,
3632
});
3733
};
3834

playwright/playwright/index.html

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html lang="ru">
33
<head>
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<title>Test component page</title>
77
</head>
8-
<body>
9-
<div id="root" class="g-root g-root_theme_light"></div>
10-
<script type="module" src="./index.tsx"></script>
11-
</body>
8+
<body id="root" class="g-root"></body>
9+
<script type="module" src="./index.tsx"></script>
1210
</html>

playwright/playwright/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import './index.scss';
77

88
beforeMount(async ({App}) => {
99
return (
10-
<ThemeProvider theme="light">
10+
<ThemeProvider>
1111
<MobileProvider>
1212
<App />
1313
</MobileProvider>

0 commit comments

Comments
 (0)