[app] SunsetPlace: Wire the town list, the guess and storage into the garden; e2e and offline cover it

This commit is contained in:
2026-11-02 00:01:52 +01:00
parent 77a865f625
commit 85df2c43b5
7 changed files with 183 additions and 3 deletions
+55
View File
@@ -3,8 +3,11 @@ import { expect, test, type Page } from '@playwright/test';
import { PRODUCT_NAME } from '@rosea/schema';
import { en } from '@rosea/ui/copy';
import { parseLetter } from '@rosea/ui/letter';
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';
let server: StaticServer;
@@ -127,3 +130,55 @@ test('the Letter: no way to it while empty, and it opens from the garden once wr
await page.getByRole('link', { name: en.letter.back }).click();
await expect(page.getByRole('heading', { level: 1 })).toHaveText(PRODUCT_NAME);
});
// --- Where the sunset is (.agents/features/sunset-place.md) ------------------
test.describe('the sunset place, in Prague\'s time zone at noon on 29 March 2026', () => {
test.use({ timezoneId: 'Europe/Prague', locale: 'en-US' });
const NOON = Date.parse('2026-03-29T12:00:00+02:00');
/** Browsers and Node both put a narrow no-break space before PM; compare words, not spaces. */
const spaced = (s: string): string => s.replace(/\s+/g, ' ');
test('first open asks; choosing Brno shows the sunset the engine computes; a reload keeps it', async ({ page }) => {
await page.clock.setFixedTime(NOON);
const { requests } = await open(page);
await expect(page.getByRole('heading', { level: 2, name: en.sunset.question })).toBeVisible();
await page.getByRole('searchbox', { name: en.sunset.searchLabel }).fill('brno');
await page.getByRole('button', { name: /^Brno/ }).first().click();
const brno = searchTowns('brno')[0]!;
const { at } = nextInvitation(NOON, brno);
const time = new Intl.DateTimeFormat('en-US', { hour: 'numeric', minute: '2-digit', timeZone: brno.timeZone }).format(at);
const line = page.locator('.sun p').first();
await expect(line).toHaveText(/in Brno\.$/);
expect(spaced((await line.textContent()) ?? '')).toBe(spaced(en.sunset.tonight(time, 'Brno')));
await storedTown(page, 'Brno');
await page.reload();
await expect(line).toHaveText(/in Brno\.$/);
await expect(page.getByRole('searchbox')).toHaveCount(0);
// Searching and choosing loaded the town list from this origin and nothing else.
expect(requests.filter((url) => !url.startsWith(server.origin + '/'))).toEqual([]);
expect(requests.some((url) => /\/assets\/places-.*\.js$/.test(url))).toBe(true);
});
test('"not now" guesses Prague from the device\'s zone and says it is a guess', async ({ page }) => {
await page.clock.setFixedTime(NOON);
await open(page);
await page.getByRole('button', { name: en.sunset.skip('Prague') }).click();
await expect(page.locator('.sun p').first()).toHaveText(/^Tonight the sun sets at .* in Prague\.$/);
await expect(page.getByText(en.sunset.guessed)).toBeVisible();
});
test('the question and the answer have no accessibility violations', async ({ page }) => {
await page.clock.setFixedTime(NOON);
await open(page);
await page.getByRole('searchbox').fill('pra');
await expect(page.getByRole('status')).not.toHaveText('');
expect((await new AxeBuilder({ page }).analyze()).violations.map((v) => `${v.id}: ${v.help}`)).toEqual([]);
await page.getByRole('button', { name: /^Prague/ }).first().click();
await expect(page.locator('.sun')).toBeVisible();
expect((await new AxeBuilder({ page }).analyze()).violations.map((v) => `${v.id}: ${v.help}`)).toEqual([]);
});
});