Skip to content

Commit

Permalink
test: Playwright change theme (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
NasgulNexus authored Aug 23, 2024
1 parent 0fba9c2 commit befb814
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
18 changes: 7 additions & 11 deletions playwright/core/expectScreenshotFixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@ export const expectScreenshotFixture: PlaywrightFixture<ExpectScreenshotFixture>
screenshotName,
...pageScreenshotOptions
} = {}) => {
const captureScreenshot = async (theme: string) => {
const root = page.locator('#root');

await root.evaluate((el, theme) => {
el.classList.value = `g-root g-root_theme_${theme}`;
}, theme);

const captureScreenshot = async () => {
return (component || page.locator('.playwright-wrapper-test')).screenshot({
animations: 'disabled',
...pageScreenshotOptions,
Expand All @@ -27,12 +21,14 @@ export const expectScreenshotFixture: PlaywrightFixture<ExpectScreenshotFixture>

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

expect(await captureScreenshot('dark')).toMatchSnapshot({
name: `${screenshotName || nameScreenshot} dark.png`,
expect(await captureScreenshot()).toMatchSnapshot({
name: `${screenshotName || nameScreenshot} light.png`,
});

expect(await captureScreenshot('light')).toMatchSnapshot({
name: `${screenshotName || nameScreenshot} light.png`,
await page.emulateMedia({colorScheme: 'dark'});

expect(await captureScreenshot()).toMatchSnapshot({
name: `${screenshotName || nameScreenshot} dark.png`,
});
};

Expand Down
8 changes: 3 additions & 5 deletions playwright/playwright/index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<!DOCTYPE html>
<!doctype html>
<html lang="ru">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Test component page</title>
</head>
<body>
<div id="root" class="g-root g-root_theme_light"></div>
<script type="module" src="./index.tsx"></script>
</body>
<body id="root" class="g-root"></body>
<script type="module" src="./index.tsx"></script>
</html>
2 changes: 1 addition & 1 deletion playwright/playwright/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import './index.scss';

beforeMount(async ({App}) => {
return (
<ThemeProvider theme="light">
<ThemeProvider>
<MobileProvider>
<App />
</MobileProvider>
Expand Down

0 comments on commit befb814

Please sign in to comment.