diff --git a/e2e/shell.spec.ts b/e2e/shell.spec.ts index ce39632..034ac5e 100644 --- a/e2e/shell.spec.ts +++ b/e2e/shell.spec.ts @@ -214,6 +214,24 @@ test.describe('the rose, in Prague at 08:00 on 1 March 2026', () => { expect(requests.filter((url) => !url.startsWith(server.origin + '/'))).toEqual([]); }); + test('touch her: a fond answer; three quick taps, and she says she has thorns (thorns.md)', async ({ page }) => { + // The clock is driven, not frozen: taps at one frozen instant would be one touch. + await page.clock.install({ time: MORNING }); + await open(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]!); + await page.clock.runFor(5_000); + for (let i = 0; i < 3; i++) { + await touch.click(); + await page.clock.runFor(400); + } + await expect(page.locator('.bubble')).toHaveText(en.rose.touch.thorns); + await expect(page.getByRole('img', { name: 'The rose, a bud.' })).toBeVisible(); + await touch.focus(); + expect((await new AxeBuilder({ page }).analyze()).violations.map((v) => `${v.id}: ${v.help}`)).toEqual([]); + }); + test('the rose and her care have no accessibility violations', async ({ page }) => { await page.clock.setFixedTime(MORNING); await open(page); diff --git a/packages/ui/src/copy/en.ts b/packages/ui/src/copy/en.ts index 70c8493..67ba21b 100644 --- a/packages/ui/src/copy/en.ts +++ b/packages/ui/src/copy/en.ts @@ -50,6 +50,12 @@ export const en = { tooFull: 'That was a lot of water. I will be fine by tomorrow.' }, notKept: 'This device could not keep today’s care, so it lasts only until the garden closes.', + /** Touching her (thorns.md). Her thorns are about herself, never about the player. */ + touch: { + label: 'Touch her', + fond: ['Oh. Hello.', 'That tickles.'], + thorns: 'Gently. I have thorns.' + }, /** * The day's sentence (day-sentence.md). She offers; she never counts, and never * mentions a day the petal was not opened. diff --git a/packages/ui/src/rose/Rose.svelte b/packages/ui/src/rose/Rose.svelte index 40a86d8..7be3f8e 100644 --- a/packages/ui/src/rose/Rose.svelte +++ b/packages/ui/src/rose/Rose.svelte @@ -1,7 +1,7 @@ {#if rose}
- 0} /> +
+ 0} /> + + +
{#if says}
{says}
{/if} @@ -246,6 +285,19 @@ transition: transform 0.6s ease; } + .picture { + position: relative; + } + + .touch { + position: absolute; + inset: 0; + border: none; + border-radius: 1rem; + background: transparent; + cursor: pointer; + } + /* Drift is drawn as waiting: turned a little away, never hurt (CLAUDE.md §8). */ img.turned { transform: rotate(-4deg) scaleX(-1); diff --git a/packages/ui/test/touch.test.ts b/packages/ui/test/touch.test.ts new file mode 100644 index 0000000..6ba08f9 --- /dev/null +++ b/packages/ui/test/touch.test.ts @@ -0,0 +1,109 @@ +import { careEvent, TOUCH } from '@rosea/engine'; +import type { CareEvent } from '@rosea/schema'; +import { cleanup, fireEvent, render, screen } from '@testing-library/svelte'; +import { tick } from 'svelte'; +import { afterEach, describe, expect, it, vi } from 'vitest'; +import { en } from '../src/copy/en.js'; +import Rose from '../src/rose/Rose.svelte'; +import type { RoseWiring } from '../src/rose/types.js'; + +const ZONE = 'Europe/Prague'; +const ME = 'M'.repeat(87); +const MORNING = Date.parse('2026-03-01T08:00:00+01:00'); +const DAY = 86_400_000; + +/** A clock the test moves, and every write the rose tries. */ +function wiring(log: CareEvent[] = []): RoseWiring & { clock: { now: number }; writes: unknown[] } { + const clock = { now: MORNING }; + const writes: unknown[] = []; + return { + identity: async () => ({ publicKey: ME, kept: true }), + loadCare: async () => log, + appendCare: async (e) => void writes.push(e), + sentences: [], + loadOpened: async () => [], + appendOpened: async (e) => void writes.push(e), + clientVersion: '0.1.0', + deviceZone: ZONE, + now: () => clock.now, + pastKeys: async () => [], + exportRose: async () => ({}), + importRose: async () => ({ added: 0, petals: 0 }), + saveFile: () => undefined, + keeping: { persisted: async () => false, persist: async () => true }, + installHint: false, + clock, + writes + }; +} + +const bubble = (): string => document.querySelector('.bubble')?.textContent ?? ''; + +async function touchAt(w: ReturnType, at: number): Promise { + w.clock.now = at; + await fireEvent.click(screen.getByRole('button', { name: en.rose.touch.label })); + await tick(); +} + +afterEach(() => { + vi.useRealTimers(); + cleanup(); +}); + +describe('touching her (thorns.md)', () => { + it('a touch is answered fondly, then her usual line returns; nothing is written', async () => { + const w = wiring(); + render(Rose, { wiring: w, timeZone: ZONE }); + await screen.findByRole('button', { name: en.rose.touch.label }); + const usual = bubble(); + vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] }); + await touchAt(w, MORNING); + expect(bubble()).toBe(en.rose.touch.fond[0]); + await touchAt(w, MORNING + 5000); + expect(bubble()).toBe(en.rose.touch.fond[1]); + vi.advanceTimersByTime(TOUCH.restMs); + await tick(); + expect(bubble()).toBe(usual); + expect(w.writes).toEqual([]); + }); + + it('three quick taps: Gently. I have thorns. Taps while she rests change nothing', async () => { + const w = wiring(); + render(Rose, { wiring: w, timeZone: ZONE }); + await screen.findByRole('button', { name: en.rose.touch.label }); + vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] }); + await touchAt(w, MORNING); + await touchAt(w, MORNING + 500); + await touchAt(w, MORNING + 1000); + expect(bubble()).toBe(en.rose.touch.thorns); + await touchAt(w, MORNING + 2000); + expect(bubble()).toBe(en.rose.touch.thorns); + expect(w.writes).toEqual([]); + }); + + it('a held key is one touch, not a rush', async () => { + const w = wiring(); + render(Rose, { wiring: w, timeZone: ZONE }); + const button = await screen.findByRole('button', { name: en.rose.touch.label }); + const repeat = new KeyboardEvent('keydown', { key: 'Enter', repeat: true, cancelable: true, bubbles: true }); + button.dispatchEvent(repeat); + expect(repeat.defaultPrevented).toBe(true); + const first = new KeyboardEvent('keydown', { key: 'Enter', cancelable: true, bubbles: true }); + button.dispatchEvent(first); + expect(first.defaultPrevented).toBe(false); + }); + + it('in full bloom the first touch of a visit makes her blush; her picture keeps its description', async () => { + // 25 days of helpful morning watering: full bloom. + const log = Array.from({ length: 25 }, (_, i) => + careEvent({ now: MORNING + i * DAY, timeZone: ZONE, from: ME, to: ME, act: 'water', amount: 0.5, clientVersion: '0.1.0' }) + ); + const w = wiring(log); + w.clock.now = MORNING + 25 * DAY + 3 * 3_600_000; + render(Rose, { wiring: w, timeZone: ZONE }); + const img = await screen.findByRole('img', { name: /full bloom/ }); + expect(img.getAttribute('alt')).not.toMatch(/blushing/); + await touchAt(w, w.clock.now); + expect(screen.getByRole('img', { name: /full bloom, blushing/ })).toBeTruthy(); + }); +});