feat(web): multi-select + bulk actions on track lists (Tier A3)
test-web / test (push) Successful in 31s

Add a global selection store backing a checkbox per track row and a
floating SelectionBar above PlayerBar with Play next / Add to queue /
Add to playlist / Like all / Clear.

- selection/store.svelte.ts: id Set + TrackRef Map + anchor index;
  toggleOne, selectRange (shift+click), clearSelection. Singleton —
  layout effect clears on pathname change.
- TrackRow: checkbox slot replaces the track number on hover; row
  click toggles selection once any row is picked; shift+click extends
  the range. Esc clears (takes priority over closing the queue
  drawer).
- SelectionBar: floating pill above PlayerBar, mounted inside the
  QueryClientProvider so the Like-all action can resolve.
- player.playNextMany: bulk variant of playNext for "Play next" on a
  multi-track selection.

Covered by selection-store unit tests and three new TrackRow tests
(checkbox toggle, sticky select-mode row click, shift+click range).
This commit is contained in:
2026-06-01 11:41:29 -04:00
parent bbc1036f77
commit fd12a145c8
7 changed files with 409 additions and 15 deletions
@@ -0,0 +1,88 @@
import { describe, expect, test, beforeEach } from 'vitest';
import type { TrackRef } from '$lib/api/types';
import { makeTrack } from '$test-utils/fixtures/track';
import {
selection, toggleOne, selectRange, clearSelection
} from './store.svelte';
function tracks(): TrackRef[] {
return [
makeTrack({ id: 'a', title: 'A' }),
makeTrack({ id: 'b', title: 'B' }),
makeTrack({ id: 'c', title: 'C' }),
makeTrack({ id: 'd', title: 'D' })
];
}
beforeEach(() => clearSelection());
describe('selection store', () => {
test('starts empty + inactive', () => {
expect(selection.count).toBe(0);
expect(selection.active).toBe(false);
expect(selection.tracks).toEqual([]);
});
test('toggleOne selects and deselects', () => {
const ts = tracks();
toggleOne(ts[1], 1);
expect(selection.isSelected('b')).toBe(true);
expect(selection.count).toBe(1);
expect(selection.active).toBe(true);
toggleOne(ts[1], 1);
expect(selection.isSelected('b')).toBe(false);
expect(selection.count).toBe(0);
expect(selection.active).toBe(false);
});
test('selectRange extends from the last anchor inclusive', () => {
const ts = tracks();
toggleOne(ts[0], 0);
selectRange(2, ts);
expect(selection.isSelected('a')).toBe(true);
expect(selection.isSelected('b')).toBe(true);
expect(selection.isSelected('c')).toBe(true);
expect(selection.isSelected('d')).toBe(false);
expect(selection.count).toBe(3);
});
test('selectRange handles reverse direction', () => {
const ts = tracks();
toggleOne(ts[3], 3);
selectRange(1, ts);
expect(selection.isSelected('b')).toBe(true);
expect(selection.isSelected('c')).toBe(true);
expect(selection.isSelected('d')).toBe(true);
expect(selection.isSelected('a')).toBe(false);
});
test('selectRange with no anchor collapses to a single toggle', () => {
const ts = tracks();
selectRange(2, ts);
expect(selection.isSelected('c')).toBe(true);
expect(selection.count).toBe(1);
});
test('selection.tracks returns the full TrackRef payloads', () => {
const ts = tracks();
toggleOne(ts[0], 0);
toggleOne(ts[2], 2);
const picked = selection.tracks;
const titles = picked.map((t) => t.title).sort();
expect(titles).toEqual(['A', 'C']);
});
test('clearSelection resets state', () => {
const ts = tracks();
toggleOne(ts[0], 0);
toggleOne(ts[1], 1);
clearSelection();
expect(selection.count).toBe(0);
expect(selection.active).toBe(false);
// Anchor is reset too — a follow-up range collapses to one.
selectRange(2, ts);
expect(selection.count).toBe(1);
});
});