feat(web): multi-select + bulk actions on track lists (Tier A3)
test-web / test (push) Successful in 31s
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:
@@ -1,4 +1,4 @@
|
||||
import { afterEach, describe, expect, test, vi } from 'vitest';
|
||||
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
|
||||
import { render, screen, fireEvent } from '@testing-library/svelte';
|
||||
import type { TrackRef } from '$lib/api/types';
|
||||
import { emptyLikesMock } from '../../test-utils/mocks/likes';
|
||||
@@ -18,12 +18,14 @@ vi.mock('$lib/api/quarantine', () => emptyQuarantineMock());
|
||||
|
||||
import TrackRow from './TrackRow.svelte';
|
||||
import { playQueue, enqueueTrack, playRadio } from '$lib/player/store.svelte';
|
||||
import { selection, clearSelection } from '$lib/selection/store.svelte';
|
||||
|
||||
const tracks: TrackRef[] = [
|
||||
makeTrack({ title: 'So What', duration_sec: 545 }),
|
||||
makeTrack({ id: 't2', title: 'Freddie Freeloader', track_number: 2, duration_sec: 565, stream_url: '/api/tracks/t2/stream' })
|
||||
];
|
||||
|
||||
beforeEach(() => clearSelection());
|
||||
afterEach(() => vi.clearAllMocks());
|
||||
|
||||
describe('TrackRow', () => {
|
||||
@@ -86,4 +88,40 @@ describe('TrackRow', () => {
|
||||
screen.getByRole('button', { name: /track actions for/i })
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
describe('selection mode', () => {
|
||||
test('clicking the checkbox toggles selection without playing', async () => {
|
||||
render(TrackRow, { props: { tracks, index: 0 } });
|
||||
const box = screen.getByRole('checkbox', { name: /select so what/i });
|
||||
await fireEvent.click(box);
|
||||
expect(selection.isSelected('t1')).toBe(true);
|
||||
expect(playQueue).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('row click toggles selection (not play) once any row is selected', async () => {
|
||||
render(TrackRow, { props: { tracks, index: 0 } });
|
||||
const box = screen.getByRole('checkbox', { name: /select so what/i });
|
||||
await fireEvent.click(box);
|
||||
|
||||
// Re-render at index 1 — selection mode is now active globally.
|
||||
const { container } = render(TrackRow, { props: { tracks, index: 1 } });
|
||||
const row = container.querySelector('[role="button"][aria-label="Freddie Freeloader"]')!;
|
||||
await fireEvent.click(row);
|
||||
expect(selection.isSelected('t2')).toBe(true);
|
||||
expect(playQueue).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('shift+click on the row extends the range from the anchor', async () => {
|
||||
render(TrackRow, { props: { tracks, index: 0 } });
|
||||
const box = screen.getByRole('checkbox', { name: /select so what/i });
|
||||
await fireEvent.click(box);
|
||||
|
||||
const { container } = render(TrackRow, { props: { tracks, index: 1 } });
|
||||
const row = container.querySelector('[role="button"][aria-label="Freddie Freeloader"]')!;
|
||||
await fireEvent.click(row, { shiftKey: true });
|
||||
expect(selection.isSelected('t1')).toBe(true);
|
||||
expect(selection.isSelected('t2')).toBe(true);
|
||||
expect(selection.count).toBe(2);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user