Files
Rosea/e2e/look.spec.ts
T

91 lines
3.6 KiB
TypeScript

import { mkdirSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { expect, test, type Browser, type Page } from '@playwright/test';
import { en } from '@rosea/ui/copy';
import { openRing, pastGardener } from './garden.js';
import { startStaticServer, type StaticServer } from './static-server.js';
/**
* Every screen with a control, photographed from the BUILT PWA in the light and the dark, on a phone and a desktop:
* the before-and-after pictures a change of look needs (domi-ui.md; @domi/ui docs/INTEGRATE.md §0). This makes
* pictures, not assertions, so it has its own config and `pnpm test:e2e` never runs it.
*
* ROSEA_LOOK=before pnpm look:shots writes e2e/look/before/<theme>-<device>-<screen>.png (git-ignored)
*
* Nothing is read from a player: a fresh garden, no town until the search is shown, a fixed day in March.
*/
const LABEL = process.env['ROSEA_LOOK'] ?? 'now';
const OUT = fileURLToPath(new URL(`./look/${LABEL}/`, import.meta.url));
const ZONE = 'Europe/Prague';
const DAY = Date.parse('2026-03-10T08:00:00+01:00');
let server: StaticServer;
test.beforeAll(async () => {
mkdirSync(OUT, { recursive: true });
server = await startStaticServer();
});
test.afterAll(async () => {
await server.close();
});
test.describe.configure({ mode: 'serial', timeout: 240_000 });
async function photograph(browser: Browser, theme: 'light' | 'dark', phone: boolean): Promise<void> {
const device = phone ? 'phone' : 'desktop';
const context = await browser.newContext({
timezoneId: ZONE,
locale: 'en-US',
colorScheme: theme,
reducedMotion: 'reduce',
...(phone
? { viewport: { width: 360, height: 800 }, deviceScaleFactor: 2, isMobile: true, hasTouch: true }
: { viewport: { width: 1280, height: 800 }, deviceScaleFactor: 1 })
});
const shot = (page: Page, screen: string): Promise<Buffer> =>
page.screenshot({ path: `${OUT}${theme}-${device}-${screen}.png`, animations: 'disabled', caret: 'hide' });
try {
const page = await context.newPage();
await page.clock.install({ time: DAY });
await page.goto(server.url);
await expect(page.getByRole('heading', { level: 2, name: en.gardener.question })).toBeVisible({ timeout: 20_000 });
await shot(page, '1-gardener');
await pastGardener(page);
const search = page.getByLabel(en.sunset.searchLabel);
await expect(search).toBeVisible();
await shot(page, '2-town-empty');
await search.fill('prague');
await expect(page.getByRole('button', { name: /^Prague/ }).first()).toBeVisible();
await shot(page, '3-town-results');
await page.getByRole('button', { name: /^Prague/ }).first().click();
await expect(page.getByRole('button', { name: en.rose.care })).toBeVisible();
await shot(page, '4-garden');
await openRing(page);
await shot(page, '5-ring');
await page.keyboard.press('Escape');
await page.getByRole('button', { name: en.rose.numbers }).click();
await page.getByRole('button', { name: en.rose.safe.title }).click();
await page.getByRole('button', { name: en.rose.safe.save }).scrollIntoViewIfNeeded();
await shot(page, '6-numbers-safe');
await page.reload();
await page.getByRole('button', { name: en.chair.move }).click();
const scene = page.getByRole('dialog', { name: en.chair.scene });
await expect(scene).toBeVisible();
await page.clock.runFor(30_000);
await shot(page, '7-sunset');
} finally {
await context.close();
}
}
for (const theme of ['light', 'dark'] as const) {
for (const phone of [true, false]) {
test(`${theme}, ${phone ? 'phone' : 'desktop'}`, async ({ browser }) => {
await photograph(browser, theme, phone);
});
}
}