Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: playwright update change theme and add providers #302

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading