[app] Rose: Wire identity and the care log into the garden; e2e and offline tend the rose
This commit is contained in:
+12
-1
@@ -2,7 +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 { storedTown } from './stored.js';
|
||||
import { storedCare, storedTown } from './stored.js';
|
||||
|
||||
/**
|
||||
* The offline suite. CLAUDE.md §3 describes its full shape: tend the rose, walk
|
||||
@@ -66,6 +66,14 @@ test('the shell opens from the service worker with the server gone', async ({ br
|
||||
await expect(page.locator('.sun p').first()).toHaveText(/in Plzeň\.$/);
|
||||
await storedTown(page, 'Plzeň');
|
||||
|
||||
// Tending the rose offline: hold Water, as a finger would (rose.md).
|
||||
await page.getByRole('button', { name: en.rose.water }).hover();
|
||||
await page.mouse.down();
|
||||
await page.waitForTimeout(1500);
|
||||
await page.mouse.up();
|
||||
await expect(page.getByText(en.rose.says.thanks)).toBeVisible();
|
||||
await storedCare(page, 1);
|
||||
|
||||
// 2. Close the tab and open a fresh one: a cold start, the shape of a player
|
||||
// coming back days later with no signal.
|
||||
await page.close();
|
||||
@@ -74,6 +82,9 @@ test('the shell opens from the service worker with the server gone', async ({ br
|
||||
await again.goto(server.url);
|
||||
await expect(again.getByRole('heading', { level: 1 })).toHaveText(PRODUCT_NAME);
|
||||
await expect(again.locator('.sun p').first()).toHaveText(/in Plzeň\.$/);
|
||||
// The care given offline survived the closed tab.
|
||||
await again.getByRole('button', { name: en.rose.numbers }).click();
|
||||
await expect(again.locator('#rose-numbers')).toContainText(`${en.rose.daysOfCare}1`);
|
||||
|
||||
// 3. A deep link inside the scope falls back to the shell, not an error page.
|
||||
await again.goto(`${server.url}somewhere/deeper`);
|
||||
|
||||
+41
-1
@@ -7,7 +7,7 @@ import { nextInvitation } from '@rosea/engine';
|
||||
import { searchTowns } from '@rosea/content/places';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { BASE, startStaticServer, type StaticServer } from './static-server.js';
|
||||
import { storedTown } from './stored.js';
|
||||
import { storedCare, storedTown } from './stored.js';
|
||||
|
||||
let server: StaticServer;
|
||||
|
||||
@@ -182,3 +182,43 @@ test.describe('the sunset place, in Prague\'s time zone at noon on 29 March 2026
|
||||
expect((await new AxeBuilder({ page }).analyze()).violations.map((v) => `${v.id}: ${v.help}`)).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
// --- The rose (.agents/features/rose.md) -------------------------------------
|
||||
test.describe('the rose, in Prague at 08:00 on 1 March 2026', () => {
|
||||
test.use({ timezoneId: 'Europe/Prague', locale: 'en-US' });
|
||||
const MORNING = Date.parse('2026-03-01T08:00:00+01:00');
|
||||
|
||||
/** 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 page.getByRole('button', { name: en.rose.water }).hover();
|
||||
await page.mouse.down();
|
||||
await page.waitForTimeout(ms);
|
||||
await page.mouse.up();
|
||||
}
|
||||
|
||||
test('a new rose is a bud; holding Water is one day of care; a reload keeps it', async ({ page }) => {
|
||||
await page.clock.setFixedTime(MORNING);
|
||||
const { requests } = await open(page);
|
||||
await expect(page.getByRole('img', { name: 'The rose, a bud.' })).toBeVisible();
|
||||
await expect(page.getByText(en.rose.says.dry)).toBeVisible();
|
||||
|
||||
await pour(page, 1500);
|
||||
await expect(page.getByText(en.rose.says.thanks)).toBeVisible();
|
||||
await page.getByRole('button', { name: en.rose.numbers }).click();
|
||||
await expect(page.locator('#rose-numbers')).toContainText(`${en.rose.daysOfCare}1`);
|
||||
|
||||
await storedCare(page, 1);
|
||||
await page.reload();
|
||||
await page.getByRole('button', { name: en.rose.numbers }).click();
|
||||
await expect(page.locator('#rose-numbers')).toContainText(`${en.rose.daysOfCare}1`);
|
||||
expect(requests.filter((url) => !url.startsWith(server.origin + '/'))).toEqual([]);
|
||||
});
|
||||
|
||||
test('the rose and her care have no accessibility violations', async ({ page }) => {
|
||||
await page.clock.setFixedTime(MORNING);
|
||||
await open(page);
|
||||
await page.getByRole('button', { name: en.rose.numbers }).click();
|
||||
await expect(page.locator('#rose-numbers')).toBeVisible();
|
||||
expect((await new AxeBuilder({ page }).analyze()).violations.map((v) => `${v.id}: ${v.help}`)).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -34,3 +34,33 @@ export async function storedTown(page: Page, name: string): Promise<void> {
|
||||
{ timeout: 5_000 }
|
||||
);
|
||||
}
|
||||
|
||||
/** Waits until the care log holds at least `count` events, for the same reason as above. */
|
||||
export async function storedCare(page: Page, count: number): Promise<void> {
|
||||
await page.waitForFunction(
|
||||
(expected) =>
|
||||
new Promise<boolean>((resolve) => {
|
||||
const req = indexedDB.open('rosea');
|
||||
req.onerror = () => resolve(false);
|
||||
req.onsuccess = () => {
|
||||
const db = req.result;
|
||||
if (!db.objectStoreNames.contains('events')) {
|
||||
db.close();
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
const n = db.transaction('events').objectStore('events').count();
|
||||
n.onsuccess = () => {
|
||||
db.close();
|
||||
resolve(n.result >= expected);
|
||||
};
|
||||
n.onerror = () => {
|
||||
db.close();
|
||||
resolve(false);
|
||||
};
|
||||
};
|
||||
}),
|
||||
count,
|
||||
{ timeout: 5_000 }
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user