Files
Rosea/e2e/planet.spec.ts

84 lines
3.7 KiB
TypeScript

import AxeBuilder from '@axe-core/playwright';
import { expect, test, type Page } from '@playwright/test';
import { PRODUCT_NAME } from '@rosea/schema';
import { en } from '@rosea/ui/copy';
import { startStaticServer, type StaticServer } from './static-server.js';
import { storedCare } from './stored.js';
/**
* Her planet in the BUILT app (.agents/features/planet-garden.md): the first-open choice of
* gardener, the ring of care, and care by the player's own hand on the can.
*/
test.use({ timezoneId: 'Europe/Prague', locale: 'en-US' });
const MORNING = Date.parse('2026-03-01T08:00:00+01:00');
let server: StaticServer;
test.beforeEach(async () => {
server = await startStaticServer();
});
test.afterEach(async () => {
await server.close();
});
const axe = async (page: Page): Promise<string[]> => (await new AxeBuilder({ page }).analyze()).violations.map((v) => `${v.id}: ${v.help}`);
test('the first open asks who tends her; the chosen gardener stays after a reload', async ({ page }) => {
await page.clock.setFixedTime(MORNING);
await page.goto(server.url);
await expect(page.getByRole('heading', { level: 1 })).toHaveText(PRODUCT_NAME);
await expect(page.getByRole('heading', { level: 2, name: en.gardener.question })).toBeVisible();
await expect(page.getByRole('img', { name: en.gardener.preview })).toBeVisible();
expect(await axe(page)).toEqual([]);
await page.getByText(en.gardener.values.presentation.boy, { exact: true }).click();
await page.getByText(en.gardener.values.hat.cap, { exact: true }).click();
await page.getByRole('button', { name: en.gardener.done }).click();
await expect(page.getByRole('group', { name: en.scene.planet })).toBeVisible();
expect(await axe(page)).toEqual([]);
await page.waitForFunction(
() =>
new Promise<boolean>((resolve) => {
const req = indexedDB.open('rosea');
req.onsuccess = () => {
const get = req.result.transaction('profile').objectStore('profile').get('gardener');
get.onsuccess = () => resolve((get.result as { value?: { presentation?: string } } | undefined)?.value?.presentation === 'boy');
get.onerror = () => resolve(false);
};
req.onerror = () => resolve(false);
})
);
await page.reload();
await expect(page.getByRole('group', { name: en.scene.planet })).toBeVisible();
await expect(page.getByRole('heading', { name: en.gardener.question })).toHaveCount(0);
});
test('a tap on her opens the ring of what she needs; Escape closes it', async ({ page }) => {
await page.clock.setFixedTime(MORNING);
await page.goto(server.url);
await page.getByRole('button', { name: en.gardener.done }).click();
await page.getByRole('button', { name: en.rose.care }).click();
const ring = page.getByRole('group', { name: en.scene.ring });
await expect(ring).toBeVisible();
await expect(ring.getByRole('button', { name: en.rose.water })).toBeFocused();
expect(await axe(page)).toEqual([]);
await page.keyboard.press('Escape');
await expect(ring).toHaveCount(0);
await expect(page.getByRole('button', { name: en.rose.care })).toBeFocused();
});
test('pressing the can and tilting it pours: she thanks the player, and it is kept', async ({ page }) => {
await page.clock.setFixedTime(MORNING);
await page.goto(server.url);
await page.getByRole('button', { name: en.gardener.done }).click();
const can = page.getByRole('img', { name: en.scene.can });
const box = (await can.boundingBox())!;
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
await page.mouse.down();
await page.mouse.move(box.x + box.width / 2 + 90, box.y + box.height / 2, { steps: 5 });
await page.waitForTimeout(1300);
await page.mouse.up();
await expect(page.getByText(en.rose.says.thanks)).toBeVisible();
await storedCare(page, 1);
});