release / govulncheck (push) Successful in 23s
release / web (push) Successful in 1m22s
release / go (push) Successful in 1m41s
release / integration (push) Successful in 4m49s
release / android (push) Successful in 5m32s
release / Build signed APK (releases and dev) (push) Successful in 5m39s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 28s
release / Verify release artifacts (tag releases only) (push) Skipped
CI run 8789 warned on both: - kit 3 deprecates `config.alias`. The $test-utils alias becomes a `#test-utils/*` subpath import, matching #lib, and its 43 import sites move with it. - Vite's coming native config loader needs the extension on vitest.config.ts's import of vite.config. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
89 lines
2.6 KiB
TypeScript
89 lines
2.6 KiB
TypeScript
import { describe, expect, test, beforeEach } from 'vitest';
|
|
import type { TrackRef } from '#lib/api/types.js';
|
|
import { makeTrack } from '#test-utils/fixtures/track.js';
|
|
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);
|
|
});
|
|
});
|