Skip to content

Commit

Permalink
test: playwright update change theme and add providers (#302)
Browse files Browse the repository at this point in the history
  • Loading branch information
NasgulNexus authored Aug 26, 2024
1 parent 4f85d70 commit 0613e66
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 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
2 changes: 1 addition & 1 deletion playwright/playwright/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Test component page</title>
</head>
<body id="root" class="g-root g-root_theme_light"></body>
<body id="root" class="g-root"></body>
<script type="module" src="./index.tsx"></script>
</html>
9 changes: 6 additions & 3 deletions playwright/playwright/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import React from 'react';

import {MobileProvider, ThemeProvider} from '@gravity-ui/uikit';
import {MobileProvider, ThemeProvider, ToasterComponent, ToasterProvider} from '@gravity-ui/uikit';
import {beforeMount} from '@playwright/experimental-ct-react/hooks';

import './index.scss';

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

0 comments on commit 0613e66

Please sign in to comment.