[app] PlanetGarden: e2e passes the gardener question, opens the ring, and pours by tilting the can

This commit is contained in:
2026-11-17 19:15:24 +01:00
parent 5576af4fac
commit 52d8c0bfd1
7 changed files with 137 additions and 12 deletions
+21
View File
@@ -0,0 +1,21 @@
import { expect, type Page } from '@playwright/test';
import { en } from '@rosea/ui/copy';
/**
* The first open asks *Who tends her?* (planet-garden.md §1). Tests that are not about the
* gardener answer it with the first look, so they reach the garden as a returning player does.
*/
export async function pastGardener(page: Page): Promise<void> {
const question = page.getByRole('heading', { level: 2, name: en.gardener.question });
const garden = page.getByRole('button', { name: en.rose.care });
await expect(question.or(garden)).toBeVisible({ timeout: 20_000 });
if (await question.isVisible()) await page.getByRole('button', { name: en.gardener.done }).click();
await expect(garden).toBeVisible();
}
/** Opens the ring of care, as Enter on her (or a tap) does (planet-garden.md G7). */
export async function openRing(page: Page): Promise<void> {
const ring = page.getByRole('group', { name: en.scene.ring });
if (!(await ring.isVisible())) await page.getByRole('button', { name: en.rose.care }).press('Enter');
await expect(ring).toBeVisible();
}
+3
View File
@@ -2,6 +2,7 @@ import { expect, test } from '@playwright/test';
import { PRODUCT_NAME } from '@rosea/schema';
import { en } from '@rosea/ui/copy';
import { startStaticServer } from './static-server.js';
import { openRing, pastGardener } from './garden.js';
import { storedCare, storedTown } from './stored.js';
/**
@@ -24,6 +25,7 @@ test('the shell opens from the service worker with the server gone', async ({ br
await page.clock.setFixedTime(Date.parse('2026-03-29T12:00:00+02:00'));
await page.goto(server.url);
await expect(page.getByRole('heading', { level: 1 })).toHaveText(PRODUCT_NAME);
await pastGardener(page);
// The player answers the sunset question while online (sunset-place.md).
await page.getByRole('searchbox', { name: en.sunset.searchLabel }).fill('brno');
@@ -67,6 +69,7 @@ test('the shell opens from the service worker with the server gone', async ({ br
await storedTown(page, 'Plzeň');
// Tending the rose offline: hold Water, as a finger would (rose.md).
await openRing(page);
await page.getByRole('button', { name: en.rose.water }).hover();
await page.mouse.down();
await page.waitForTimeout(1500);
+2 -1
View File
@@ -7,6 +7,7 @@ import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { startStaticServer, type StaticServer } from './static-server.js';
import { pastGardener } from './garden.js';
import { storedCare } from './stored.js';
import fixture from './fixtures/library/fixture.json' with { type: 'json' };
@@ -35,7 +36,7 @@ test.afterEach(async () => {
async function open(page: Page): Promise<void> {
await page.clock.setFixedTime(MORNING);
await page.goto(server.url);
await expect(page.getByRole('button', { name: en.rose.water })).toBeVisible();
await pastGardener(page);
}
test('with the shipped library still empty, she holds no petal and says nothing about one', async ({ page }) => {
+83
View File
@@ -0,0 +1,83 @@
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);
});
+1 -1
View File
@@ -7,7 +7,7 @@ import { defineConfig, devices } from '@playwright/test';
*/
export default defineConfig({
testDir: '.',
testMatch: /(shell|update|petal)\.spec\.ts/,
testMatch: /(shell|update|petal|planet)\.spec\.ts/,
fullyParallel: false,
workers: 1,
retries: 0,
+9
View File
@@ -7,6 +7,7 @@ import { nextInvitation, nextSunEvent } from '@rosea/engine';
import { searchTowns } from '@rosea/content/places';
import { readFileSync } from 'node:fs';
import { BASE, startStaticServer, type StaticServer } from './static-server.js';
import { openRing, pastGardener } from './garden.js';
import { storedCare, storedTown } from './stored.js';
let server: StaticServer;
@@ -29,6 +30,7 @@ async function open(page: Page): Promise<{ requests: string[]; cspViolations: st
});
await page.goto(server.url);
await expect(page.getByRole('heading', { level: 1 })).toHaveText(PRODUCT_NAME);
await pastGardener(page);
// Let the worker register and precache, so its requests are counted too.
await page.waitForFunction(() => navigator.serviceWorker.ready.then(() => true), null, { timeout: 20_000 });
return { requests, cspViolations };
@@ -204,6 +206,7 @@ test.describe('the rose, in Prague at 08:00 on 1 March 2026', () => {
/** Holds the Water button with the mouse, as a player holds it with a finger. */
async function pour(page: Page, ms: number): Promise<void> {
await openRing(page);
await page.getByRole('button', { name: en.rose.water }).hover();
await page.mouse.down();
await page.waitForTimeout(ms);
@@ -232,6 +235,7 @@ test.describe('the rose, in Prague at 08:00 on 1 March 2026', () => {
// The clock is driven, not frozen: taps at one frozen instant would be one touch.
await page.clock.install({ time: MORNING });
await open(page);
await openRing(page);
const touch = page.getByRole('button', { name: en.rose.touch.label });
await touch.click();
await expect(page.locator('.bubble')).toHaveText(en.rose.touch.fond[0]!);
@@ -249,6 +253,7 @@ test.describe('the rose, in Prague at 08:00 on 1 March 2026', () => {
test('a touched control shows no browser tap box (seen on a real Android tablet)', async ({ page }) => {
await page.clock.setFixedTime(MORNING);
await open(page);
await openRing(page);
const highlight = await page.getByRole('button', { name: en.rose.water }).evaluate((el) => getComputedStyle(el).getPropertyValue('-webkit-tap-highlight-color'));
expect(highlight.replace(/\s/g, '')).toBe('rgba(0,0,0,0)');
});
@@ -274,6 +279,7 @@ test.describe('two tabs of the garden, in Prague at 08:00 on 1 March 2026', () =
await open(p);
await expect(p.getByText(en.rose.says.dry)).toBeVisible();
}
await openRing(page);
await page.getByRole('button', { name: en.rose.water }).hover();
await page.mouse.down();
await page.waitForTimeout(1500);
@@ -314,8 +320,10 @@ test.describe('keep her safe, in Prague at 08:00 on 1 March 2026', () => {
const page = await first.newPage();
await page.clock.setFixedTime(MORNING);
await page.goto(server.url);
await pastGardener(page);
await page.getByRole('searchbox', { name: en.sunset.searchLabel }).fill('brno');
await page.getByRole('button', { name: /^Brno/ }).first().click();
await openRing(page);
await page.getByRole('button', { name: en.rose.water }).hover();
await page.mouse.down();
await page.waitForTimeout(1500);
@@ -340,6 +348,7 @@ test.describe('keep her safe, in Prague at 08:00 on 1 March 2026', () => {
const page = await second.newPage();
await page.clock.setFixedTime(MORNING + 3_600_000);
await page.goto(server.url);
await pastGardener(page);
await expect(page.getByRole('img', { name: 'The rose, a bud.' })).toBeVisible();
await page.getByRole('button', { name: en.rose.safe.title }).click();
await page.getByLabel(en.rose.safe.bringBack).setInputFiles({ name: 'rose-2026-03-01.json', mimeType: 'application/json', buffer: Buffer.from(saved) });
+18 -10
View File
@@ -102,6 +102,23 @@
touch: { at: -10, pose: 'reach' }
};
const station = $derived(STATION[activity]);
/** Where on the world the gardener stands, in degrees from the top: walked there, or placed at once with reduced motion. */
let walkAt = $state(STATION.idle.at);
$effect(() => {
const target = station.at;
const from = untrack(() => walkAt);
if (reduced || from === target) {
walkAt = target;
return;
}
const t0 = performance.now();
const step = setInterval(() => {
const k = Math.min(1, (performance.now() - t0) / 900);
walkAt = from + (target - from) * (k < 0.5 ? 2 * k * k : 1 - (-2 * k + 2) ** 2 / 2);
if (k >= 1) clearInterval(step);
}, 16);
return () => clearInterval(step);
});
// --- The player's hand ------------------------------------------------------
type Drag =
@@ -248,7 +265,6 @@
<!-- Her small round world: meadow over warm earth, a low dry-stone wall, her bed, the chair. -->
<circle cx={CX} cy={CY} r={R} fill="url(#planet-ground)" stroke="#3a2730" stroke-width="3" />
<path d="M{CX - 70} {CY + 40} q 70 50 140 0" fill="none" stroke="#8a6248" stroke-width="10" opacity=".25" />
{#each [-58, -52, -46, 46, 52] as a (a)}
{@const s = surface(a, 3)}
<ellipse cx={s.x} cy={s.y} rx="6" ry="4" fill="#c9bcae" stroke="#3a2730" stroke-width="1.5" transform="rotate({a} {s.x} {s.y})" />
@@ -343,7 +359,7 @@
{/if}
<!-- The gardener: walks round the world to where the work is. -->
<g class="walker" style:transform="rotate({station.at}deg)" style:transform-origin="{CX}px {CY}px">
<g class="walker" transform="rotate({walkAt} {CX} {CY})">
<g transform="translate({CX} {TOP})">
<Gardener {look} pose={station.pose} {tilt} />
</g>
@@ -382,14 +398,6 @@
transform: rotate(-4deg);
}
.walker {
transition: transform 0.9s ease-in-out;
}
.reduced .walker {
transition: none;
}
.gust path {
animation: gust 2.4s ease-in-out infinite;
}