From befb814630b1dc1d351bad08ac6ccd6569a17fb3 Mon Sep 17 00:00:00 2001 From: Egor Mostovoy Date: Fri, 23 Aug 2024 18:14:14 +0200 Subject: [PATCH] test: Playwright change theme (#232) --- playwright/core/expectScreenshotFixture.ts | 18 +++++++----------- playwright/playwright/index.html | 8 +++----- playwright/playwright/index.tsx | 2 +- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/playwright/core/expectScreenshotFixture.ts b/playwright/core/expectScreenshotFixture.ts index 065cb55b..73fab3ae 100644 --- a/playwright/core/expectScreenshotFixture.ts +++ b/playwright/core/expectScreenshotFixture.ts @@ -12,13 +12,7 @@ export const expectScreenshotFixture: PlaywrightFixture 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, @@ -27,12 +21,14 @@ export const expectScreenshotFixture: PlaywrightFixture 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`, }); }; diff --git a/playwright/playwright/index.html b/playwright/playwright/index.html index 6572a36e..a51519b7 100644 --- a/playwright/playwright/index.html +++ b/playwright/playwright/index.html @@ -1,12 +1,10 @@ - + Test component page - -
- - + + diff --git a/playwright/playwright/index.tsx b/playwright/playwright/index.tsx index 9ca09e1c..ed604595 100644 --- a/playwright/playwright/index.tsx +++ b/playwright/playwright/index.tsx @@ -7,7 +7,7 @@ import './index.scss'; beforeMount(async ({App}) => { return ( - +