From e5c82c56c63f52d4c899fde3b5425dd90e18e2f5 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Mon, 1 Jun 2026 11:21:35 -0400 Subject: [PATCH] fix(web): align shortcut tests with the actual playQueue state CI on 4362233d caught it: playQueue leaves the store at 'loading' (intent-to-play; jsdom never advances to 'playing' because there's no real audio). togglePlay's contract is loading|playing -> paused, anything else -> loading. So Space round-trips loading <-> paused, not paused <-> playing. Three changes: - "Space toggles" expects loading -> paused -> loading. - "K alias" expects loading -> paused. - "shortcuts ignored when focus in input" + "modifier keys disable" capture state before the press and assert no change, instead of hard-coding 'paused'. --- web/src/lib/player/shortcuts.svelte.test.ts | 23 +++++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/web/src/lib/player/shortcuts.svelte.test.ts b/web/src/lib/player/shortcuts.svelte.test.ts index 434bc81b..c2922040 100644 --- a/web/src/lib/player/shortcuts.svelte.test.ts +++ b/web/src/lib/player/shortcuts.svelte.test.ts @@ -35,21 +35,25 @@ describe('useGlobalShortcuts', () => { test('Space toggles play/pause', async () => { const store = await import('./store.svelte'); - expect(store.player.state).toBe('paused'); - press(' '); - flushSync(); - expect(store.player.state).toBe('playing'); + // playQueue leaves the store at 'loading' (intent-to-play; jsdom + // never moves it to 'playing' because there's no real audio). The + // togglePlay contract is: loading|playing -> paused, anything else + // -> loading. So Space round-trips loading <-> paused. + expect(store.player.state).toBe('loading'); press(' '); flushSync(); expect(store.player.state).toBe('paused'); + press(' '); + flushSync(); + expect(store.player.state).toBe('loading'); }); test('K is an alias for Space (YouTube convention)', async () => { const store = await import('./store.svelte'); - expect(store.player.state).toBe('paused'); + expect(store.player.state).toBe('loading'); press('k'); flushSync(); - expect(store.player.state).toBe('playing'); + expect(store.player.state).toBe('paused'); }); test('ArrowRight advances to the next track', async () => { @@ -97,19 +101,20 @@ describe('useGlobalShortcuts', () => { test('shortcuts are ignored when focus is in an input', async () => { const store = await import('./store.svelte'); - expect(store.player.state).toBe('paused'); + const before = store.player.state; const input = document.createElement('input'); document.body.appendChild(input); input.focus(); press(' ', input); flushSync(); // No state change — Space should pass through to the input. - expect(store.player.state).toBe('paused'); + expect(store.player.state).toBe(before); input.remove(); }); test('modifier keys disable the shortcut (browser hotkey passthrough)', async () => { const store = await import('./store.svelte'); + const before = store.player.state; const event = new KeyboardEvent('keydown', { key: ' ', ctrlKey: true, @@ -118,6 +123,6 @@ describe('useGlobalShortcuts', () => { }); window.dispatchEvent(event); flushSync(); - expect(store.player.state).toBe('paused'); + expect(store.player.state).toBe(before); }); });