[app] SunsetPlace: Wire the town list, the guess and storage into the garden; e2e and offline cover it
This commit is contained in:
+21
-1
@@ -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 { storedTown } from './stored.js';
|
||||
|
||||
/**
|
||||
* The offline suite. CLAUDE.md §3 describes its full shape: tend the rose, walk
|
||||
@@ -14,14 +15,22 @@ import { startStaticServer } from './static-server.js';
|
||||
*/
|
||||
test('the shell opens from the service worker with the server gone', async ({ browser }) => {
|
||||
const server = await startStaticServer();
|
||||
const context = await browser.newContext();
|
||||
// A fixed place and day, so the sunset line is the same on every run.
|
||||
const context = await browser.newContext({ timezoneId: 'Europe/Prague', locale: 'en-US' });
|
||||
let serverOpen = true;
|
||||
|
||||
try {
|
||||
const page = await context.newPage();
|
||||
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);
|
||||
|
||||
// The player answers the sunset question while online (sunset-place.md).
|
||||
await page.getByRole('searchbox', { name: en.sunset.searchLabel }).fill('brno');
|
||||
await page.getByRole('button', { name: /^Brno/ }).first().click();
|
||||
await expect(page.locator('.sun p').first()).toHaveText(/^Tonight the sun sets at .* in Brno\.$/);
|
||||
await storedTown(page, 'Brno');
|
||||
|
||||
// `clientsClaim` makes the FIRST worker control the page that registered it.
|
||||
// Without it, a player who opens the link once and loses signal has nothing.
|
||||
await page.waitForFunction(() => navigator.serviceWorker.controller !== null, null, { timeout: 20_000 });
|
||||
@@ -47,13 +56,24 @@ test('the shell opens from the service worker with the server gone', async ({ br
|
||||
await page.reload();
|
||||
await expect(page.getByRole('heading', { level: 1 })).toHaveText(PRODUCT_NAME);
|
||||
await expect(page.getByText(en.shell.preparing)).toBeVisible();
|
||||
// The town survived in IndexedDB, and the sun is computed with no network.
|
||||
await expect(page.locator('.sun p').first()).toHaveText(/^Tonight the sun sets at .* in Brno\.$/);
|
||||
|
||||
// Changing the town offline: the town list was precached with the shell.
|
||||
await page.getByRole('button', { name: en.sunset.change }).click();
|
||||
await page.getByRole('searchbox').fill('plzen');
|
||||
await page.getByRole('button', { name: /^Plzeň/ }).first().click();
|
||||
await expect(page.locator('.sun p').first()).toHaveText(/in Plzeň\.$/);
|
||||
await storedTown(page, 'Plzeň');
|
||||
|
||||
// 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();
|
||||
const again = await context.newPage();
|
||||
await again.clock.setFixedTime(Date.parse('2026-03-29T12:00:00+02:00'));
|
||||
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ň\.$/);
|
||||
|
||||
// 3. A deep link inside the scope falls back to the shell, not an error page.
|
||||
await again.goto(`${server.url}somewhere/deeper`);
|
||||
|
||||
Reference in New Issue
Block a user