test(web): drop URL-echo and scaffold tests, merge repeated cases into tables (#8300)

Client tests that only restated a function's URL, or asserted on the value
their own mock returned, are gone; what those functions do beyond the URL
(escaping an id, leaving out an empty note, paging) keeps a test. Repeated
cases in the player store, row keyboard handling, public routes, register
refusals and others are tables. The shuffle test used an rng that never
swapped, so it could not fail; it now pins the order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-02 16:46:39 -05:00
co-authored by Claude Opus 5.5
parent 5d2c533074
commit 4c4ddf741e
35 changed files with 280 additions and 1508 deletions
@@ -2,35 +2,21 @@ import { describe, test, expect } from 'vitest';
import { render, screen } from '@testing-library/svelte';
import PlaylistPlaceholderCard from './PlaylistPlaceholderCard.svelte';
// A placeholder names the mix and says why it is not there yet. It pulses
// while the mix is still coming, and not once it has failed or needs more
// listening.
describe('PlaylistPlaceholderCard', () => {
test('renders label', () => {
render(PlaylistPlaceholderCard, { props: { label: 'For You', variant: 'pending' } });
test.each([
['pending', undefined, /within 24h/i, true],
['building', 'building', /Building your daily mix/i, true],
['failed', 'failed', /Couldn.t build this mix/i, false],
['seed-needed', 'seed-needed', /Listen to more variety/i, false]
] as const)('%s', (shown, variant, copy, pulses) => {
const { container } = render(PlaylistPlaceholderCard, { props: { label: 'For You', variant } });
expect(screen.getByText('For You')).toBeInTheDocument();
});
test('building variant shows building copy and pulses', () => {
const { container } = render(PlaylistPlaceholderCard, { props: { label: 'For You', variant: 'building' } });
expect(screen.getByText(/Building your daily mix/i)).toBeInTheDocument();
const cover = container.querySelector('[data-variant="building"] .aspect-square');
expect(cover?.className).toMatch(/animate-pulse/);
});
test('failed variant shows failure copy and does NOT pulse', () => {
const { container } = render(PlaylistPlaceholderCard, { props: { label: 'For You', variant: 'failed' } });
expect(screen.getByText(/Couldn.t build this mix/i)).toBeInTheDocument();
const cover = container.querySelector('[data-variant="failed"] .aspect-square');
expect(cover?.className).not.toMatch(/animate-pulse/);
});
test('seed-needed variant shows variety copy', () => {
render(PlaylistPlaceholderCard, { props: { label: 'Songs like…', variant: 'seed-needed' } });
expect(screen.getByText(/Listen to more variety/i)).toBeInTheDocument();
});
test('pending variant (default) shows within-24h copy and pulses', () => {
const { container } = render(PlaylistPlaceholderCard, { props: { label: 'For You' } });
expect(screen.getByText(/within 24h/i)).toBeInTheDocument();
const cover = container.querySelector('[data-variant="pending"] .aspect-square');
expect(cover?.className).toMatch(/animate-pulse/);
expect(screen.getByText(copy)).toBeInTheDocument();
const cover = container.querySelector(`[data-variant="${shown}"] .aspect-square`);
expect(cover).not.toBeNull();
expect(/animate-pulse/.test(cover!.className)).toBe(pulses);
});
});
@@ -93,24 +93,16 @@ describe('PlaylistTrackRow', () => {
).not.toBeInTheDocument();
});
test('ArrowDown on the reorder handle calls onMove(pos, pos+1)', async () => {
test.each([
['ArrowDown', 3],
['ArrowUp', 1]
])('%s on the reorder handle moves the row one place', async (key, to) => {
const onMove = vi.fn();
render(PlaylistTrackRow, {
props: { row: live, isOwner: true, onRemove: vi.fn(), onPlay: vi.fn(), onMove }
});
const handle = screen.getByLabelText(/reorder track/i);
await fireEvent.keyDown(handle, { key: 'ArrowDown' });
expect(onMove).toHaveBeenCalledWith(2, 3);
});
test('ArrowUp on the reorder handle calls onMove(pos, pos-1)', async () => {
const onMove = vi.fn();
render(PlaylistTrackRow, {
props: { row: live, isOwner: true, onRemove: vi.fn(), onPlay: vi.fn(), onMove }
});
const handle = screen.getByLabelText(/reorder track/i);
await fireEvent.keyDown(handle, { key: 'ArrowUp' });
expect(onMove).toHaveBeenCalledWith(2, 1);
await fireEvent.keyDown(screen.getByLabelText(/reorder track/i), { key });
expect(onMove).toHaveBeenCalledWith(2, to);
});
test('greyed-out + strikethrough when track_id is null', () => {
+12 -24
View File
@@ -67,32 +67,20 @@ describe('QueueTrackRow', () => {
expect(playFromQueueIndex).not.toHaveBeenCalled();
});
it('ArrowDown on the drag handle calls moveQueueItem with index+1', async () => {
// The arrows move the row one place. Enter and Space move nothing, and are
// held so Space doesn't scroll the queue.
it.each([
['ArrowDown', [3, 4]],
['ArrowUp', [3, 2]],
['Enter', null],
[' ', null]
] as const)('%s on the drag handle', async (key, move) => {
render(QueueTrackRow, { props: { track: sampleTrack, index: 3, isCurrent: false } });
const handle = screen.getByLabelText(/reorder track/i);
await fireEvent.keyDown(handle, { key: 'ArrowDown' });
expect(moveQueueItem).toHaveBeenCalledWith(3, 4);
});
it('ArrowUp on the drag handle calls moveQueueItem with index-1', async () => {
render(QueueTrackRow, { props: { track: sampleTrack, index: 3, isCurrent: false } });
const handle = screen.getByLabelText(/reorder track/i);
await fireEvent.keyDown(handle, { key: 'ArrowUp' });
expect(moveQueueItem).toHaveBeenCalledWith(3, 2);
});
it('Enter on the drag handle prevents default but does not call moveQueueItem', async () => {
render(QueueTrackRow, { props: { track: sampleTrack, index: 3, isCurrent: false } });
const handle = screen.getByLabelText(/reorder track/i);
await fireEvent.keyDown(handle, { key: 'Enter' });
expect(moveQueueItem).not.toHaveBeenCalled();
});
it('Space on the drag handle prevents default but does not call moveQueueItem', async () => {
render(QueueTrackRow, { props: { track: sampleTrack, index: 3, isCurrent: false } });
const handle = screen.getByLabelText(/reorder track/i);
await fireEvent.keyDown(handle, { key: ' ' });
expect(moveQueueItem).not.toHaveBeenCalled();
const notPrevented = await fireEvent.keyDown(handle, { key });
expect(notPrevented).toBe(false);
if (move) expect(moveQueueItem).toHaveBeenCalledWith(...move);
else expect(moveQueueItem).not.toHaveBeenCalled();
});
// --- handle placement ---
+11 -24
View File
@@ -2,30 +2,17 @@ import { describe, it, expect } from 'vitest';
import { render, screen } from '@testing-library/svelte';
import StageBadge from './StageBadge.svelte';
// A stage at work or finished carries an icon; one waiting or skipped is a
// muted word alone.
describe('StageBadge', () => {
it('renders Processing + spinner when state is in_progress', () => {
render(StageBadge, { props: { state: 'in_progress' } });
expect(screen.getByText('Processing')).toBeInTheDocument();
// The spinner is a lucide icon — just confirm a child SVG exists.
expect(document.querySelector('svg')).toBeTruthy();
});
it('renders Done + check when state is done', () => {
render(StageBadge, { props: { state: 'done' } });
expect(screen.getByText('Done')).toBeInTheDocument();
expect(document.querySelector('svg')).toBeTruthy();
});
it('renders Pending muted when state is pending', () => {
render(StageBadge, { props: { state: 'pending' } });
expect(screen.getByText('Pending')).toBeInTheDocument();
// No icon for the muted states.
expect(document.querySelector('svg')).toBeFalsy();
});
it('renders Skipped muted when state is skipped', () => {
render(StageBadge, { props: { state: 'skipped' } });
expect(screen.getByText('Skipped')).toBeInTheDocument();
expect(document.querySelector('svg')).toBeFalsy();
it.each([
['in_progress', 'Processing', true],
['done', 'Done', true],
['pending', 'Pending', false],
['skipped', 'Skipped', false]
] as const)('%s reads %s', (state, label, icon) => {
render(StageBadge, { props: { state } });
expect(screen.getByText(label)).toBeInTheDocument();
expect(!!document.querySelector('svg')).toBe(icon);
});
});
+2 -8
View File
@@ -48,15 +48,9 @@ describe('TrackRow', () => {
expect(playQueue).toHaveBeenCalledWith(tracks, 1, { source: undefined });
});
test('Enter on the row activates play', async () => {
test.each([['Enter'], [' ']])('%s on the row activates play', async (key) => {
render(TrackRow, { props: { tracks, index: 0 } });
await fireEvent.keyDown(screen.getByRole('button', { name: 'So Then' }), { key: 'Enter' });
expect(playQueue).toHaveBeenCalledWith(tracks, 0, { source: undefined });
});
test('Space on the row activates play', async () => {
render(TrackRow, { props: { tracks, index: 0 } });
await fireEvent.keyDown(screen.getByRole('button', { name: 'So Then' }), { key: ' ' });
await fireEvent.keyDown(screen.getByRole('button', { name: 'So Then' }), { key });
expect(playQueue).toHaveBeenCalledWith(tracks, 0, { source: undefined });
});
+16 -34
View File
@@ -1,40 +1,22 @@
import { describe, it, expect } from 'vitest';
import { offsetToDelta } from './queue-row-math';
// A drag moves a row by the whole rows it crosses, counting half a row or
// more as one. A row of no height moves nothing.
describe('offsetToDelta', () => {
it('returns 0 for zero offset', () => {
expect(offsetToDelta(0, 64)).toBe(0);
});
it('returns 1 for a full row down', () => {
expect(offsetToDelta(64, 64)).toBe(1);
});
it('rounds half-rows down (just under midpoint)', () => {
expect(offsetToDelta(31, 64)).toBe(0);
});
it('rounds half-rows up (at or past midpoint)', () => {
expect(offsetToDelta(32, 64)).toBe(1);
});
it('handles negative offsets symmetrically (drag up)', () => {
expect(offsetToDelta(-64, 64)).toBe(-1);
expect(offsetToDelta(-32, 64)).toBe(0); // Math.round(-0.5) === 0 in JS
});
it('handles multi-row offsets', () => {
expect(offsetToDelta(192, 64)).toBe(3);
expect(offsetToDelta(-128, 64)).toBe(-2);
});
it('returns 0 when rowHeight is non-positive (defensive)', () => {
expect(offsetToDelta(100, 0)).toBe(0);
expect(offsetToDelta(100, -1)).toBe(0);
});
it('respects the measured row height (e.g., h-14 = 56px)', () => {
expect(offsetToDelta(56, 56)).toBe(1);
expect(offsetToDelta(28, 56)).toBe(1); // 0.5 → 1 (half-up)
it.each([
[0, 64, 0],
[64, 64, 1],
[31, 64, 0],
[32, 64, 1],
[28, 56, 1],
[192, 64, 3],
[-64, 64, -1],
[-32, 64, 0], // Math.round(-0.5) is 0
[-128, 64, -2],
[100, 0, 0],
[100, -1, 0]
])('%spx on %spx rows → %s', (offset, rowHeight, want) => {
expect(offsetToDelta(offset, rowHeight)).toBe(want);
});
});