Files
actual/packages/desktop-client/e2e/fixtures.ts
Matt Fiddaman 2d95fe6d03 add some basic linting rules for translation consistency (#5212)
* lint rules

* trans rule

* migrate away from rulesDir config

* fixes

* prefer Trans to t()

* typechecker

* cleanup

* note

* typo

* extend regex to include punctuation

* extend fixer to handle imports

* autofixes from punctuation
2025-07-04 15:17:17 -04:00

56 lines
1.8 KiB
TypeScript

import { expect as baseExpect, type Locator } from '@playwright/test';
export { test } from '@playwright/test';
export const expect = baseExpect.extend({
async toMatchThemeScreenshots(locator: Locator) {
// Disable screenshot assertions in regular e2e tests;
// only enable them when doing VRT tests
if (!process.env.VRT) {
return {
message: () => 'passed',
pass: true,
};
}
const config = {
// eslint-disable-next-line actual/typography
mask: [locator.locator('[data-vrt-mask="true"]')],
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 baseExpect(dataThemeLocator).toHaveAttribute('data-theme', 'auto');
await baseExpect(locator).toHaveScreenshot(config);
// Switch to darkmode and check
await locator.evaluate(() => window.Actual.setTheme('dark'));
await baseExpect(dataThemeLocator).toHaveAttribute('data-theme', 'dark');
await baseExpect(locator).toHaveScreenshot(config);
// Switch to midnight theme and check
await locator.evaluate(() => window.Actual.setTheme('midnight'));
await baseExpect(dataThemeLocator).toHaveAttribute(
'data-theme',
'midnight',
);
await baseExpect(locator).toHaveScreenshot(config);
// Switch back to lightmode
await locator.evaluate(() => window.Actual.setTheme('auto'));
return {
message: () => 'pass',
pass: true,
};
},
});