|
1 | 1 | import assert from 'node:assert/strict'; |
| 2 | +import { readFile } from 'node:fs/promises'; |
2 | 3 | import test from 'node:test'; |
3 | 4 | import { createWorkbenchWindow } from '../miniapp/client/workbench-window.mjs'; |
4 | 5 |
|
@@ -160,3 +161,22 @@ test('unavailable, inline and non-resizable handles fail without writing geometr |
160 | 161 | assert.deepEqual(await fixed.controller.setExpanded(true), { ok: false, code: 'not_permitted' }); |
161 | 162 | assert.deepEqual(fixed.calls, []); assert.deepEqual(inline.calls, []); |
162 | 163 | }); |
| 164 | + |
| 165 | +test('expanding the companion card never moves the pet sideways', async () => { |
| 166 | + // The pet is centred in the window, so a bottom-right anchored resize only keeps it |
| 167 | + // still if the width is unchanged. A wider card slides the pet and reads as a flicker |
| 168 | + // each time the card opens. |
| 169 | + const source = await readFile(new URL('../miniapp/client/pet-app.js', import.meta.url), 'utf8'); |
| 170 | + const declared = source.match(/const compactBubbleSize = \{ width: (\d+), height: (\d+) \};/u); |
| 171 | + assert.ok(declared, 'compactBubbleSize is where the card size is declared'); |
| 172 | + const expandedSize = { width: Number(declared[1]), height: Number(declared[2]) }; |
| 173 | + const petWidth = 144; |
| 174 | + const petScreenX = (bounds) => bounds.x + (bounds.width - petWidth) / 2; |
| 175 | + const h = harness({ expandedSize, state: { mode: 'window', window: { x: 1640, y: 680, width: 280, height: 340, resizable: true } } }); |
| 176 | + const before = petScreenX(h.state().window); |
| 177 | + await h.controller.setExpanded(true); |
| 178 | + assert.equal(petScreenX(h.state().window), before, 'opening the card must not move the pet'); |
| 179 | + assert.ok(h.state().window.height > 340, 'the card still gets more room'); |
| 180 | + await h.controller.setExpanded(false); |
| 181 | + assert.equal(petScreenX(h.state().window), before, 'closing it must not move the pet either'); |
| 182 | +}); |
0 commit comments