mirror of
https://github.com/actualbudget/actual.git
synced 2026-03-21 15:36:50 -05:00
* Convert playwright config and tests to TS * Release notes * Update VRT * Dummy commit * Delete js snapshots * Fix call to expect * Move extended expect and test to fixtures * Fix wrong commit * Fix typecheck error * Update VRT * Dummy commit to run GH actions * Delete mobile budget test JS --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
56 lines
1.8 KiB
TypeScript
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 rulesdir/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,
|
|
};
|
|
},
|
|
});
|