From d15e6f8b86fbba7b14493624f3fbc5a6cb902ec2 Mon Sep 17 00:00:00 2001 From: NasgulNexus Date: Mon, 26 Aug 2024 14:13:37 +0200 Subject: [PATCH] test: changed theme change and connected toaster provider --- playwright/core/expectScreenshotFixture.ts | 20 +++++++++----------- playwright/playwright/index.html | 8 ++++---- playwright/playwright/index.tsx | 8 ++++++-- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/playwright/core/expectScreenshotFixture.ts b/playwright/core/expectScreenshotFixture.ts index bf0a60069e..829126623d 100644 --- a/playwright/core/expectScreenshotFixture.ts +++ b/playwright/core/expectScreenshotFixture.ts @@ -12,13 +12,7 @@ export const expectScreenshotFixture: PlaywrightFixture 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, @@ -28,13 +22,17 @@ export const expectScreenshotFixture: PlaywrightFixture 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); diff --git a/playwright/playwright/index.html b/playwright/playwright/index.html index e8ad4b82fa..3e9c5aa32c 100644 --- a/playwright/playwright/index.html +++ b/playwright/playwright/index.html @@ -1,12 +1,12 @@ - + Test component page - -
- + +
+ diff --git a/playwright/playwright/index.tsx b/playwright/playwright/index.tsx index 2cee79a79e..917d4031cc 100644 --- a/playwright/playwright/index.tsx +++ b/playwright/playwright/index.tsx @@ -2,6 +2,7 @@ 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'; @@ -9,9 +10,12 @@ import './index.scss'; beforeMount(async ({App}) => { return ( - + - + + + + );