release / web (push) Failing after 1m16s
release / go (push) Successful in 1m48s
release / govulncheck (push) Successful in 20s
release / integration (push) Successful in 4m0s
release / android (push) Successful in 4m34s
release / Build signed APK (push) Successful in 5m9s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Skipped
release / Verify release artifacts (tag releases only) (push) Skipped
Test data and example comments named real artists, records and songs, and carried real MusicBrainz ids. One mapping swaps them for invented ones throughout (Fields of Ontario, Plastic Apes, Marlo Davies, ...), keeping what each case tests: sort order, index letter, escaping, title keys, artist-prefix stripping. A test username is no longer the operator's name. The cover-art and Last.fm connection checks still query real releases; they reach live services and need something that exists there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
248 lines
8.6 KiB
TypeScript
248 lines
8.6 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
|
|
import { render, screen, fireEvent, within } from '@testing-library/svelte';
|
|
import type { TrackRef } from '#lib/api/types.js';
|
|
import { emptyLikesMock } from '../../test-utils/mocks/likes';
|
|
import { emptyQuarantineMock } from '../../test-utils/mocks/quarantine';
|
|
import { makeTrack } from '#test-utils/fixtures/track.js';
|
|
|
|
// Mutable state the mocked store reads from.
|
|
const state = vi.hoisted(() => ({
|
|
current: undefined as TrackRef | undefined,
|
|
queue: [] as TrackRef[],
|
|
index: 0,
|
|
state: 'idle' as 'idle' | 'loading' | 'playing' | 'paused' | 'error',
|
|
position: 0,
|
|
duration: 0,
|
|
volume: 1,
|
|
shuffle: false,
|
|
repeat: 'off' as 'off' | 'all' | 'one',
|
|
error: null as string | null,
|
|
queueDrawerOpen: false
|
|
}));
|
|
|
|
vi.mock('#lib/player/store.svelte.js', () => ({
|
|
player: {
|
|
get queue() { return state.queue; },
|
|
get index() { return state.index; },
|
|
get current() { return state.current; },
|
|
get state() { return state.state; },
|
|
get isPlaying() { return state.state === 'playing'; },
|
|
get position() { return state.position; },
|
|
get duration() { return state.duration; },
|
|
get volume() { return state.volume; },
|
|
get shuffle() { return state.shuffle; },
|
|
get repeat() { return state.repeat; },
|
|
get error() { return state.error; },
|
|
get queueDrawerOpen() { return state.queueDrawerOpen; }
|
|
},
|
|
togglePlay: vi.fn(),
|
|
skipNext: vi.fn(),
|
|
skipPrev: vi.fn(),
|
|
seekTo: vi.fn(),
|
|
setVolume: vi.fn(),
|
|
toggleShuffle: vi.fn(),
|
|
cycleRepeat: vi.fn(),
|
|
playQueue: vi.fn(),
|
|
toggleQueueDrawer: vi.fn()
|
|
}));
|
|
|
|
vi.mock('#lib/api/likes.js', () => emptyLikesMock());
|
|
|
|
vi.mock('#lib/api/quarantine.js', () => emptyQuarantineMock());
|
|
|
|
import PlayerBar from './PlayerBar.svelte';
|
|
import {
|
|
togglePlay, skipNext, skipPrev, seekTo, setVolume,
|
|
toggleShuffle, cycleRepeat, playQueue,
|
|
toggleQueueDrawer
|
|
} from '#lib/player/store.svelte.js';
|
|
|
|
function track(): TrackRef {
|
|
return makeTrack({
|
|
title: 'So Then',
|
|
album_id: 'xyz', album_title: 'Kind of Grey',
|
|
artist_id: 'md', artist_name: 'Marlo Davies',
|
|
duration_sec: 545
|
|
});
|
|
}
|
|
|
|
// PlayerBar renders both a compact (mobile, md:hidden) and desktop
|
|
// (hidden md:flex) block. jsdom doesn't apply CSS media queries, so
|
|
// both DOM trees are present in tests. Scope every query to the
|
|
// compact block — that's where the phone layout lives; desktop
|
|
// behavior is covered structurally by the same store + handlers.
|
|
function compact() {
|
|
return within(screen.getByTestId('player-bar-compact'));
|
|
}
|
|
|
|
beforeEach(() => {
|
|
state.queue = [track()];
|
|
state.current = state.queue[0];
|
|
state.index = 0;
|
|
state.state = 'paused';
|
|
state.position = 42;
|
|
state.duration = 545;
|
|
state.volume = 0.8;
|
|
state.shuffle = false;
|
|
state.repeat = 'off';
|
|
state.error = null;
|
|
state.queueDrawerOpen = false;
|
|
});
|
|
|
|
afterEach(() => vi.clearAllMocks());
|
|
|
|
describe('PlayerBar', () => {
|
|
test('renders title, artist, and cover linked to /now-playing', () => {
|
|
render(PlayerBar);
|
|
expect(compact().getByText('So Then')).toBeInTheDocument();
|
|
// The artist label sits under the title in compact (no link wrapper);
|
|
// look for it as plain text.
|
|
expect(compact().getByText('Marlo Davies')).toBeInTheDocument();
|
|
// Cover + title area links to /now-playing (Spotify/YouTube Music
|
|
// pattern). Album reachable via the album-name link inside NowPlaying.
|
|
const cover = compact().getByRole('link', { name: /open now playing/i });
|
|
expect(cover).toHaveAttribute('href', '/now-playing');
|
|
});
|
|
|
|
test('play button click calls togglePlay', async () => {
|
|
render(PlayerBar);
|
|
// Anchored regex — "Player options" (the new overflow ⋮) also matches
|
|
// /play|pause/i otherwise.
|
|
await fireEvent.click(compact().getByRole('button', { name: /^(play|pause)$/i }));
|
|
expect(togglePlay).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
test('skip-next click calls skipNext; skip-prev click calls skipPrev', async () => {
|
|
render(PlayerBar);
|
|
await fireEvent.click(compact().getByRole('button', { name: /next/i }));
|
|
await fireEvent.click(compact().getByRole('button', { name: /previous/i }));
|
|
expect(skipNext).toHaveBeenCalledTimes(1);
|
|
expect(skipPrev).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
test('skip-prev disabled when index=0 AND position<3', () => {
|
|
state.index = 0;
|
|
state.position = 1;
|
|
render(PlayerBar);
|
|
expect(compact().getByRole('button', { name: /previous/i })).toBeDisabled();
|
|
});
|
|
|
|
test('skip-next disabled at end with repeat=off', () => {
|
|
state.queue = [track()];
|
|
state.index = 0;
|
|
state.repeat = 'off';
|
|
render(PlayerBar);
|
|
expect(compact().getByRole('button', { name: /next/i })).toBeDisabled();
|
|
});
|
|
|
|
test('seek slider input calls seekTo(value)', async () => {
|
|
render(PlayerBar);
|
|
const slider = compact().getByLabelText(/seek/i) as HTMLInputElement;
|
|
await fireEvent.input(slider, { target: { value: '120' } });
|
|
expect(seekTo).toHaveBeenCalledWith(120);
|
|
});
|
|
|
|
test('volume slider input calls setVolume(value)', async () => {
|
|
render(PlayerBar);
|
|
const slider = compact().getByLabelText(/volume/i) as HTMLInputElement;
|
|
await fireEvent.input(slider, { target: { value: '0.3' } });
|
|
expect(setVolume).toHaveBeenCalledWith(0.3);
|
|
});
|
|
|
|
test('shuffle button click calls toggleShuffle; active class reflects shuffle', () => {
|
|
state.shuffle = true;
|
|
render(PlayerBar);
|
|
const btn = compact().getByRole('button', { name: /shuffle/i });
|
|
expect(btn.getAttribute('aria-pressed')).toBe('true');
|
|
});
|
|
|
|
test('repeat button aria-label reflects current mode', () => {
|
|
state.repeat = 'one';
|
|
render(PlayerBar);
|
|
expect(compact().getByRole('button', { name: /repeat one/i })).toBeInTheDocument();
|
|
});
|
|
|
|
test('loading state shows spinner in place of play icon', () => {
|
|
state.state = 'loading';
|
|
render(PlayerBar);
|
|
expect(compact().getByTestId('play-spinner')).toBeInTheDocument();
|
|
});
|
|
|
|
test('error state renders retry card; retry click calls playQueue(queue, index)', async () => {
|
|
state.state = 'error';
|
|
state.error = 'Playback failed.';
|
|
render(PlayerBar);
|
|
expect(compact().getByText(/playback failed/i)).toBeInTheDocument();
|
|
await fireEvent.click(compact().getByRole('button', { name: /try again/i }));
|
|
expect(playQueue).toHaveBeenCalledWith(state.queue, state.index);
|
|
});
|
|
|
|
test('elapsed and total render formatted duration', () => {
|
|
state.position = 65;
|
|
state.duration = 245;
|
|
render(PlayerBar);
|
|
expect(compact().getByText('1:05')).toBeInTheDocument();
|
|
expect(compact().getByText('4:05')).toBeInTheDocument();
|
|
});
|
|
|
|
test('renders the TrackMenu kebab button when a track is current', () => {
|
|
render(PlayerBar);
|
|
expect(
|
|
compact().getByRole('button', { name: /track actions for/i })
|
|
).toBeInTheDocument();
|
|
});
|
|
|
|
describe('queue toggle button', () => {
|
|
test('clicking the queue toggle calls toggleQueueDrawer', async () => {
|
|
render(PlayerBar);
|
|
const btn = compact().getByLabelText(/(open|close) queue/i);
|
|
await fireEvent.click(btn);
|
|
expect(toggleQueueDrawer).toHaveBeenCalled();
|
|
});
|
|
|
|
test('aria-pressed reflects queueDrawerOpen state', () => {
|
|
state.queueDrawerOpen = true;
|
|
render(PlayerBar);
|
|
const btn = compact().getByLabelText(/close queue/i);
|
|
expect(btn).toHaveAttribute('aria-pressed', 'true');
|
|
});
|
|
});
|
|
|
|
describe('"Up next" line (desktop only)', () => {
|
|
// The compact block has no "Next · …" copy; only the desktop block
|
|
// surfaces it. Scope queries to desktop.
|
|
function desktop() {
|
|
return within(screen.getByTestId('player-bar-desktop'));
|
|
}
|
|
|
|
test('renders the next track title when index + 1 < queue.length', () => {
|
|
state.queue = [
|
|
{ id: 'a', title: 'Track A', artist_name: 'Art A' } as TrackRef,
|
|
{ id: 'b', title: 'Track B', artist_name: 'Art B' } as TrackRef
|
|
];
|
|
state.index = 0;
|
|
state.current = state.queue[0];
|
|
render(PlayerBar);
|
|
expect(desktop().getByText(/track b/i)).toBeInTheDocument();
|
|
});
|
|
|
|
test('omits the line on the last track in queue', () => {
|
|
state.queue = [
|
|
{ id: 'a', title: 'Track A', artist_name: 'Art A' } as TrackRef
|
|
];
|
|
state.index = 0;
|
|
state.current = state.queue[0];
|
|
render(PlayerBar);
|
|
expect(desktop().queryByText(/^Next ·/i)).not.toBeInTheDocument();
|
|
});
|
|
|
|
test('omits the line when queue is empty', () => {
|
|
state.queue = [];
|
|
state.current = undefined;
|
|
state.index = 0;
|
|
render(PlayerBar);
|
|
expect(screen.queryByText(/^Next ·/i)).not.toBeInTheDocument();
|
|
});
|
|
});
|
|
});
|