fix(web): align shortcut tests with the actual playQueue state
test-web / test (push) Successful in 31s

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'.
This commit is contained in:
2026-06-01 11:21:35 -04:00
parent 4362233d7c
commit e5c82c56c6
+14 -9
View File
@@ -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);
});
});