Skip to content
Snippets Groups Projects
Unverified Commit af666458 authored by Matiss Janis Aboltins's avatar Matiss Janis Aboltins Committed by GitHub
Browse files

:white_check_mark: (VRT) darkmode visual regression tests (#1860)

parent 184b3022
No related branches found
No related tags found
No related merge requests found
Showing
with 50 additions and 8 deletions
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
import { expect, defineConfig } from '@playwright/test'; import { expect, defineConfig } from '@playwright/test';
// Disable screenshot assertions in regular e2e tests; expect.extend({
// only enable them when doing VRT tests async toMatchThemeScreenshots(locator) {
if (!process.env.VRT) { // Disable screenshot assertions in regular e2e tests;
expect.extend({ // only enable them when doing VRT tests
toHaveScreenshot() { if (!process.env.VRT) {
return { return {
message: () => 'passed', message: () => 'passed',
pass: true, pass: true,
}; };
}, }
});
} const config = {
// eslint-disable-next-line rulesdir/typography
mask: [locator.locator('[data-vrt-mask="true"]')],
};
// Check lightmode
const lightmode = await expect(locator).toHaveScreenshot(config);
if (lightmode && !lightmode.pass) {
return lightmode;
}
// Switch to darkmode and check
await locator.evaluate(() => window.Actual.setTheme('dark'));
const darkmode = await expect(locator).toHaveScreenshot(config);
// Assert on
if (darkmode && !darkmode.pass) {
return darkmode;
}
// Switch back to lightmode
await locator.evaluate(() => window.Actual.setTheme('light'));
return {
message: () => 'pass',
pass: true,
};
},
});
// eslint-disable-next-line import/no-unused-modules // eslint-disable-next-line import/no-unused-modules
export default defineConfig({ export default defineConfig({
......
...@@ -128,6 +128,8 @@ global.Actual = { ...@@ -128,6 +128,8 @@ global.Actual = {
getServerSocket: async () => { getServerSocket: async () => {
return worker; return worker;
}, },
setTheme: () => {},
}; };
document.addEventListener('keydown', e => { document.addEventListener('keydown', e => {
......
...@@ -14,6 +14,10 @@ export function handleGlobalEvents(actions, store) { ...@@ -14,6 +14,10 @@ export function handleGlobalEvents(actions, store) {
// to update. // to update.
}); });
global.Actual.setTheme = theme => {
actions.saveGlobalPrefs({ theme });
};
listen('server-error', info => { listen('server-error', info => {
actions.addGenericErrorNotification(); actions.addGenericErrorNotification();
}); });
......
...@@ -54,4 +54,6 @@ contextBridge.exposeInMainWorld('Actual', { ...@@ -54,4 +54,6 @@ contextBridge.exposeInMainWorld('Actual', {
getServerSocket: () => { getServerSocket: () => {
return socketPromise; return socketPromise;
}, },
setTheme: () => {},
}); });
---
category: Maintenance
authors: [MatissJanis]
---
Added darkmode VRT (screenshot) tests
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment