Skip to content

Commit

Permalink
[e2e stability] Check for data-theme before taking a screenshot (#3523)
Browse files Browse the repository at this point in the history
* Check for data-theme before taking a screenshot

* Release notes

* Update playwright.config.js

* Fix error

* Updates VRT

* VRT

* Revert VRT

---------

Co-authored-by: youngcw <calebyoung94@gmail.com>
  • Loading branch information
joel-jeremy and youngcw authored Sep 29, 2024
1 parent 545c8d5 commit 3b97d1e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions packages/desktop-client/playwright.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,17 @@ expect.extend({
maxDiffPixels: 5,
};

// Get the data-theme attribute from page.
// If there is a page() function, it means that the locator
// is not a page object but a locator object.
const dataThemeLocator =
typeof locator.page === 'function'
? locator.page().locator('[data-theme]')
: locator.locator('[data-theme]');

// Check lightmode
await locator.evaluate(() => window.Actual.setTheme('auto'));
await expect(dataThemeLocator).toHaveAttribute('data-theme', 'auto');
const lightmode = await expect(locator).toHaveScreenshot(config);

if (lightmode && !lightmode.pass) {
Expand All @@ -27,6 +36,7 @@ expect.extend({

// Switch to darkmode and check
await locator.evaluate(() => window.Actual.setTheme('dark'));
await expect(dataThemeLocator).toHaveAttribute('data-theme', 'dark');
const darkmode = await expect(locator).toHaveScreenshot(config);

// Assert on
Expand All @@ -36,6 +46,7 @@ expect.extend({

// Switch to midnight theme and check
await locator.evaluate(() => window.Actual.setTheme('midnight'));
await expect(dataThemeLocator).toHaveAttribute('data-theme', 'midnight');
const midnightMode = await expect(locator).toHaveScreenshot(config);

// Assert on
Expand Down
5 changes: 4 additions & 1 deletion packages/desktop-client/src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
import { useMetadataPref } from '../hooks/useMetadataPref';
import { installPolyfills } from '../polyfills';
import { ResponsiveProvider } from '../ResponsiveProvider';
import { styles, hasHiddenScrollbars, ThemeStyle } from '../style';
import { styles, hasHiddenScrollbars, ThemeStyle, useTheme } from '../style';
import { ExposeNavigate } from '../util/router-tools';

import { AppBackground } from './AppBackground';
Expand Down Expand Up @@ -155,6 +155,8 @@ export function App() {
};
}, [dispatch]);

const [theme] = useTheme();

return (
<BrowserRouter>
<ExposeNavigate />
Expand All @@ -166,6 +168,7 @@ export function App() {
<DndProvider backend={HTML5Backend}>
<ScrollProvider>
<View
data-theme={theme}
style={{
height: '100%',
display: 'flex',
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/3523.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Maintenance
authors: [joel-jeremy]
---

e2e stability: wait for data-theme to switch before taking a screenshot

0 comments on commit 3b97d1e

Please sign in to comment.