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: changed theme change and connected toaster provider #1788

Merged
merged 1 commit into from
Aug 27, 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
20 changes: 9 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>
nameSuffix,
...pageScreenshotOptions
} = {}) => {
const captureScreenshot = async (theme: string) => {
const body = page.locator('body');

await body.evaluate((el: HTMLElement | SVGElement, newTheme: string) => {
el.setAttribute('class', `g-root g-root_theme_${newTheme}`);
}, theme);

const captureScreenshot = async () => {
return (component || page.locator('.playwright-wrapper-test')).screenshot({
animations: 'disabled',
...pageScreenshotOptions,
Expand All @@ -28,13 +22,17 @@ export const expectScreenshotFixture: PlaywrightFixture<ExpectScreenshotFixture>
const nameScreenshot =
testInfo.titlePath.slice(1).join(' ') + (nameSuffix ? ` ${nameSuffix}` : '');

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

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

await page.emulateMedia({colorScheme: 'dark'});

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

await use(expectScreenshot);
Expand Down
8 changes: 4 additions & 4 deletions playwright/playwright/index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Test component page</title>
</head>
<body class="g-root g-root_theme_light">
<div id="root"></div>
<script type="module" src="./index.tsx"></script>
<body>
<div id="root" class="g-root"></div>
</body>
<script type="module" src="./index.tsx"></script>
</html>
8 changes: 6 additions & 2 deletions playwright/playwright/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@ import React from 'react';

import {beforeMount} from '@playwright/experimental-ct-react/hooks';

import {ToasterComponent, ToasterProvider} from '../../src/components/Toaster';
import {MobileProvider} from '../../src/components/mobile/MobileProvider';
import {ThemeProvider} from '../../src/components/theme/ThemeProvider';

import './index.scss';

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