[ui] PlanetGarden: Her round planet, the player's gardener, the ring of care, and care by gesture

This commit is contained in:
2026-11-17 19:07:57 +01:00
parent 9eef8a3bf7
commit 5576af4fac
18 changed files with 1268 additions and 79 deletions
+17 -7
View File
@@ -44,8 +44,16 @@ function wiring(over: Partial<RoseWiring> & { log?: CareEvent[]; at?: number } =
}
const water = (now: number, amount: number): CareEvent => careEvent({ now, timeZone: ZONE, from: ME, to: ME, act: 'water', amount, clientVersion: '0.1.0' });
/** Opens the ring of care, as a tap on her, or Enter on her, does (planet-garden.md G7). */
async function openRing(): Promise<void> {
if (screen.queryByRole('group', { name: en.scene.ring })) return;
await fireEvent.keyDown(await screen.findByRole('button', { name: en.rose.care }), { key: 'Enter' });
await tick();
}
/** Holds the Water button for `ms`, with the pour's own timer under control. */
async function hold(ms: number, how: 'pointer' | 'keyboard' = 'pointer'): Promise<void> {
await openRing();
const button = screen.getByRole('button', { name: en.rose.water });
vi.useFakeTimers({ toFake: ['setInterval', 'clearInterval'] });
try {
@@ -79,7 +87,7 @@ describe('the rose', () => {
it('hold Water: the leaves lift while pouring; let go and it is one act of care, and she thanks you', async () => {
const w = wiring();
render(Rose, { wiring: w, timeZone: ZONE });
await screen.findByRole('img');
await screen.findByRole('img', { name: /^The rose/ });
await hold(1500); // half a can
expect(screen.getByRole('status').textContent).toBe(en.rose.leavesLift);
await release();
@@ -95,7 +103,7 @@ describe('the rose', () => {
it('pouring too long says that is plenty', async () => {
render(Rose, { wiring: wiring({ log: [water(MORNING - 60_000, 0.5)] }), timeZone: ZONE });
await screen.findByRole('img');
await screen.findByRole('img', { name: /^The rose/ });
await hold(3000);
expect(screen.getByRole('status').textContent).toBe(en.rose.plenty);
});
@@ -103,7 +111,7 @@ describe('the rose', () => {
it('pours with the keyboard too: hold Space, let go', async () => {
const w = wiring();
render(Rose, { wiring: w, timeZone: ZONE });
await screen.findByRole('img');
await screen.findByRole('img', { name: /^The rose/ });
await hold(1200, 'keyboard');
await release('keyboard');
expect(w.appended[0]).toMatchObject({ act: 'water', amount: 0.4 });
@@ -114,6 +122,7 @@ describe('the rose', () => {
while (!weedsOn(ME, localDay(day, ZONE))) day += DAY;
const w = wiring({ at: day });
render(Rose, { wiring: w, timeZone: ZONE });
await openRing();
await fireEvent.click(await screen.findByRole('button', { name: en.rose.weed }));
expect(w.appended[0]?.act).toBe('weed');
await waitFor(() => expect(screen.queryByRole('button', { name: en.rose.weed })).toBeNull());
@@ -122,7 +131,8 @@ describe('the rose', () => {
while (weedsOn(ME, localDay(clear, ZONE))) clear += DAY;
cleanup();
render(Rose, { wiring: wiring({ at: clear }), timeZone: ZONE });
await screen.findByRole('img');
await screen.findByRole('img', { name: /^The rose/ });
await openRing();
expect(screen.queryByRole('button', { name: en.rose.weed })).toBeNull();
});
@@ -130,7 +140,7 @@ describe('the rose', () => {
const log = [water(MORNING - 30 * DAY, 0.5)];
render(Rose, { wiring: wiring({ log }), timeZone: ZONE });
const img = await screen.findByRole('img', { name: /waiting/ });
expect(img.className).toContain('turned');
expect(img.getAttribute('class')).toContain('turned');
expect(screen.getByText(new RegExp(`^${en.rose.says.back}`))).toBeTruthy();
await fireEvent.click(screen.getByRole('button', { name: en.rose.numbers }));
expect(document.getElementById('rose-numbers')?.textContent).toContain(en.rose.warmthDays(0));
@@ -141,7 +151,7 @@ describe('the rose', () => {
const error = vi.spyOn(console, 'error').mockImplementation(() => undefined);
const w = wiring({ appendCare: () => Promise.reject(new Error('IndexedDB blocked')) });
render(Rose, { wiring: w, timeZone: ZONE });
await screen.findByRole('img');
await screen.findByRole('img', { name: /^The rose/ });
await hold(1500);
await release();
expect(await screen.findByText(en.rose.says.thanks)).toBeTruthy();
@@ -165,7 +175,7 @@ if (typeof File.prototype.text !== 'function') {
describe('keep her safe (keep-her-safe.md)', () => {
const OLD = 'O'.repeat(87);
const open = async (): Promise<void> => {
await screen.findByRole('img');
await screen.findByRole('img', { name: /^The rose/ });
await fireEvent.click(screen.getByRole('button', { name: en.rose.safe.title }));
};