From 7a6cf4c6d1c96c4163bc9c33c96329f09811d14e Mon Sep 17 00:00:00 2001 From: mnovak Date: Mon, 2 Nov 2026 07:35:30 +0100 Subject: [PATCH] [ui] ChairSunset: Move the chair, half a minute of sunset with nothing to press, then the real one's time --- packages/ui/src/Shell.svelte | 14 ++ packages/ui/src/copy/en.ts | 9 + packages/ui/src/sunset/ChairSunset.svelte | 219 ++++++++++++++++++++++ packages/ui/test/chair-sunset.test.ts | 100 ++++++++++ 4 files changed, 342 insertions(+) create mode 100644 packages/ui/src/sunset/ChairSunset.svelte create mode 100644 packages/ui/test/chair-sunset.test.ts diff --git a/packages/ui/src/Shell.svelte b/packages/ui/src/Shell.svelte index e9a9785..f031126 100644 --- a/packages/ui/src/Shell.svelte +++ b/packages/ui/src/Shell.svelte @@ -6,6 +6,7 @@ import { parseLetter } from './letter/parse.js'; import Rose from './rose/Rose.svelte'; import type { RoseWiring } from './rose/types.js'; + import ChairSunset from './sunset/ChairSunset.svelte'; import SunsetLine from './sunset/SunsetLine.svelte'; import SunsetPlace from './sunset/SunsetPlace.svelte'; import type { SunsetChoice, SunsetWiring } from './sunset/types.js'; @@ -37,6 +38,15 @@ let kept = $state(true); let now = $state(0); let sunLine = $state(); + /** The in-game sunset is showing (chair-sunset.md). */ + let watching = $state(false); + let chairButton = $state(); + + async function stopWatching(): Promise { + watching = false; + await tick(); + chairButton?.focus(); + } const place = $derived(choice?.kind === 'town' ? choice.town : (sunset?.guess ?? null)); // One zone for the sunset and the rose's days: the chosen town's, else the device's (rose.md R8). @@ -141,7 +151,11 @@

{en.sunset.notKept}

{/if} + + {#if watching} + + {/if} {/if} {#if blocks.length > 0} {en.letter.title} diff --git a/packages/ui/src/copy/en.ts b/packages/ui/src/copy/en.ts index daf6b03..1114e36 100644 --- a/packages/ui/src/copy/en.ts +++ b/packages/ui/src/copy/en.ts @@ -88,6 +88,15 @@ export const en = { /** When the device refuses to keep anything (a private window). Calm, and true. */ notKept: 'This device could not keep your choice, so the garden will ask again next time.' }, + chair: { + /** ROADMAP Phase 1: "move the chair, watch it again". */ + move: 'Move the chair', + scene: 'A sunset in the garden', + /** Read by screen readers only: the scene has no buttons on purpose (chair-sunset.md C2). */ + leave: 'Press Escape or tap to come back.', + again: 'Watch it again', + back: 'Back to the rose' + }, update: { /** One quiet line when a new version waits; nothing reloads by itself (calm-refresh.md U2). */ ready: 'A new version of the garden is ready.', diff --git a/packages/ui/src/sunset/ChairSunset.svelte b/packages/ui/src/sunset/ChairSunset.svelte new file mode 100644 index 0000000..4262fac --- /dev/null +++ b/packages/ui/src/sunset/ChairSunset.svelte @@ -0,0 +1,219 @@ + + + + + + + diff --git a/packages/ui/test/chair-sunset.test.ts b/packages/ui/test/chair-sunset.test.ts new file mode 100644 index 0000000..288cdd8 --- /dev/null +++ b/packages/ui/test/chair-sunset.test.ts @@ -0,0 +1,100 @@ +import type { NamedPlace } from '@rosea/engine'; +import { cleanup, fireEvent, render, screen, within } from '@testing-library/svelte'; +import { tick } from 'svelte'; +import { afterEach, describe, expect, it, vi } from 'vitest'; +import Shell from '../src/Shell.svelte'; +import { en } from '../src/copy/en.js'; +import { SUNSET_MS } from '../src/sunset/ChairSunset.svelte'; +import type { SunsetWiring } from '../src/sunset/types.js'; + +const brno: NamedPlace = { name: 'Brno', region: '', country: 'Czechia', lat: 49.2, lon: 16.61, timeZone: 'Europe/Prague' }; +const NOON = Date.parse('2026-03-29T12:00:00+02:00'); + +const wiring = (over: Partial = {}): SunsetWiring => ({ + guess: brno, + search: async () => [], + load: async () => ({ kind: 'town', town: brno }), + save: async () => undefined, + now: () => NOON, + ...over +}); + +/** Renders the garden with a town set and opens the in-game sunset; the scene's own timer is faked. */ +async function openScene(over: Partial = {}): Promise { + render(Shell, { sunset: wiring(over) }); + const move = await screen.findByRole('button', { name: en.chair.move }); + vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] }); + await fireEvent.click(move); + await tick(); + return screen.getByRole('dialog', { name: en.chair.scene }); +} + +afterEach(() => { + vi.useRealTimers(); + cleanup(); +}); + +describe('the in-game sunset (chair-sunset.md)', () => { + it('Move the chair opens a quiet scene: labelled, focused, and with nothing to press', async () => { + const scene = await openScene(); + expect(document.activeElement).toBe(scene); + expect(within(scene).queryAllByRole('button')).toEqual([]); + expect(scene.getAttribute('aria-describedby')).toBeTruthy(); + expect(document.getElementById(scene.getAttribute('aria-describedby')!)?.textContent).toBe(en.chair.leave); + }); + + it('after half a minute, it says when the real one is, and offers to watch again or go back', async () => { + const scene = await openScene(); + vi.advanceTimersByTime(SUNSET_MS - 1); + await tick(); + expect(within(scene).queryAllByRole('button')).toEqual([]); + vi.advanceTimersByTime(1); + await tick(); + expect(within(scene).getByText(/^Tonight the sun sets at .* in Brno\.$/)).toBeTruthy(); + expect(within(scene).getByRole('button', { name: en.chair.again })).toBeTruthy(); + expect(within(scene).getByRole('button', { name: en.chair.back })).toBeTruthy(); + }); + + it('Watch it again starts it over, with nothing to press again', async () => { + const scene = await openScene(); + vi.advanceTimersByTime(SUNSET_MS); + await tick(); + await fireEvent.click(within(scene).getByRole('button', { name: en.chair.again })); + await tick(); + expect(within(scene).queryAllByRole('button')).toEqual([]); + vi.advanceTimersByTime(SUNSET_MS); + await tick(); + expect(within(scene).getByRole('button', { name: en.chair.again })).toBeTruthy(); + }); + + it('Escape comes back early, and focus returns to Move the chair', async () => { + const scene = await openScene(); + await fireEvent.keyDown(scene, { key: 'Escape' }); + await tick(); + expect(screen.queryByRole('dialog')).toBeNull(); + expect(document.activeElement).toBe(screen.getByRole('button', { name: en.chair.move })); + }); + + it('a tap anywhere comes back early too', async () => { + const scene = await openScene(); + await fireEvent.click(scene); + await tick(); + expect(screen.queryByRole('dialog')).toBeNull(); + }); + + it('Back to the rose closes it after the sunset', async () => { + const scene = await openScene(); + vi.advanceTimersByTime(SUNSET_MS); + await tick(); + await fireEvent.click(within(scene).getByRole('button', { name: en.chair.back })); + await tick(); + expect(screen.queryByRole('dialog')).toBeNull(); + }); + + it('with no town and no guess, the words after it ask for a town', async () => { + const scene = await openScene({ guess: null, load: async () => ({ kind: 'device-zone' }) }); + vi.advanceTimersByTime(SUNSET_MS); + await tick(); + expect(within(scene).getByText(en.sunset.noTown)).toBeTruthy(); + }); +});