Files
minstrel/web/src/lib/components/QueueTrackRow.test.ts
T
bvandeusen 9b4f907db6 refactor(web): sweep 24 test files to use makeTrack/makeTracks fixtures (#375)
Replaces inline TrackRef literal redefinitions with calls to the
test-utils helper. Tests that asserted on default field values
(e.g. track titles, artist names rendered in the DOM) keep explicit
overrides; tests that only need a stub for shape now use makeTrack()
with no overrides.

PlaylistCard.test.ts, PlaylistTrackRow.test.ts, and playlist.test.ts
SKIPPED — they use PlaylistTrack (with track_id/added_at), not TrackRef.
ArtistCard.svelte and +page.svelte route files (matched by initial grep)
SKIPPED — live code, not test files.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-10 15:58:14 -04:00

89 lines
3.7 KiB
TypeScript

import { describe, it, expect, vi, beforeEach } from 'vitest';
import { render, screen, fireEvent } from '@testing-library/svelte';
import QueueTrackRow from './QueueTrackRow.svelte';
import { makeTrack } from '$test-utils/fixtures/track';
const playFromQueueIndex = vi.fn();
const removeFromQueue = vi.fn();
const moveQueueItem = vi.fn();
vi.mock('$lib/player/store.svelte', () => ({
playFromQueueIndex: (...args: unknown[]) => playFromQueueIndex(...args),
removeFromQueue: (...args: unknown[]) => removeFromQueue(...args),
moveQueueItem: (...args: unknown[]) => moveQueueItem(...args)
}));
const sampleTrack = makeTrack({
title: 'Song Title',
artist_name: 'Artist Name'
});
describe('QueueTrackRow', () => {
beforeEach(() => {
playFromQueueIndex.mockClear();
removeFromQueue.mockClear();
moveQueueItem.mockClear();
});
it('renders track title and artist', () => {
render(QueueTrackRow, { props: { track: sampleTrack, index: 3, isCurrent: false } });
expect(screen.getByText('Song Title')).toBeInTheDocument();
expect(screen.getByText(/Artist Name/)).toBeInTheDocument();
});
it('clicking the body calls playFromQueueIndex with the row index', async () => {
render(QueueTrackRow, { props: { track: sampleTrack, index: 3, isCurrent: false } });
const body = screen.getByRole('button', { name: /play song title/i });
await fireEvent.click(body);
expect(playFromQueueIndex).toHaveBeenCalledWith(3);
});
it('clicking the remove button calls removeFromQueue with the row index', async () => {
render(QueueTrackRow, { props: { track: sampleTrack, index: 3, isCurrent: false } });
const remove = screen.getByLabelText(/remove from queue/i);
await fireEvent.click(remove);
expect(removeFromQueue).toHaveBeenCalledWith(3);
});
it('current row shows the "Now playing" chip', () => {
render(QueueTrackRow, { props: { track: sampleTrack, index: 3, isCurrent: true } });
expect(screen.getByText(/now playing/i)).toBeInTheDocument();
});
it('current row body click does NOT call playFromQueueIndex', async () => {
render(QueueTrackRow, { props: { track: sampleTrack, index: 3, isCurrent: true } });
// The body button has a different aria-label when isCurrent
const body = screen.getByLabelText(/now playing/i);
await fireEvent.click(body);
expect(playFromQueueIndex).not.toHaveBeenCalled();
});
it('ArrowDown 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: '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();
});
});