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>
This commit is contained in:
@@ -4,6 +4,7 @@ import { flushSync } from 'svelte';
|
||||
import { mockQuery } from '../../../test-utils/query';
|
||||
import { emptyLikesMock } from '../../../test-utils/mocks/likes';
|
||||
import type { AlbumDetail, TrackRef } from '$lib/api/types';
|
||||
import { makeTrack } from '$test-utils/fixtures/track';
|
||||
|
||||
const state = vi.hoisted(() => ({ pageParams: { id: 'xyz' } as Record<string, string> }));
|
||||
|
||||
@@ -25,14 +26,14 @@ import AlbumPage from './+page.svelte';
|
||||
import { createAlbumQuery } from '$lib/api/queries';
|
||||
|
||||
function track(id: string, title: string, number: number, dur: number): TrackRef {
|
||||
return {
|
||||
return makeTrack({
|
||||
id, title,
|
||||
album_id: 'xyz', album_title: 'Kind of Blue',
|
||||
artist_id: 'md', artist_name: 'Miles Davis',
|
||||
track_number: number, disc_number: 1,
|
||||
track_number: number,
|
||||
duration_sec: dur,
|
||||
stream_url: `/api/tracks/${id}/stream`
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
@@ -2,18 +2,9 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { render, screen } from '@testing-library/svelte';
|
||||
import HistoryPage from './+page.svelte';
|
||||
import type { HistoryEvent, HistoryResponse } from '$lib/api/history';
|
||||
import type { TrackRef } from '$lib/api/types';
|
||||
import { makeTrack } from '$test-utils/fixtures/track';
|
||||
|
||||
const mkTrack = (id: string): TrackRef => ({
|
||||
id: `track-${id}`,
|
||||
title: `Song ${id}`,
|
||||
album_id: `album-${id}`,
|
||||
album_title: `Album ${id}`,
|
||||
artist_id: `artist-${id}`,
|
||||
artist_name: `Artist ${id}`,
|
||||
duration_sec: 200,
|
||||
stream_url: `/stream/${id}`
|
||||
});
|
||||
const mkTrack = (id: string) => makeTrack({ id: `track-${id}`, title: `Song ${id}` });
|
||||
|
||||
const mkEvent = (id: string, playedAt: Date): HistoryEvent => ({
|
||||
id: `event-${id}`,
|
||||
|
||||
@@ -3,6 +3,7 @@ import { render, screen, fireEvent } from '@testing-library/svelte';
|
||||
import { mockInfiniteQuery } from '../../../test-utils/query';
|
||||
import type { ArtistRef, AlbumRef, TrackRef, Page } from '$lib/api/types';
|
||||
import { readable } from 'svelte/store';
|
||||
import { makeTrack } from '$test-utils/fixtures/track';
|
||||
|
||||
vi.mock('$lib/api/likes', () => ({
|
||||
createLikedIdsQuery: () => readable({
|
||||
@@ -42,12 +43,10 @@ describe('liked library page', () => {
|
||||
id: 'al1', title: 'Y', sort_title: 'Y', artist_id: 'a1', artist_name: 'X',
|
||||
year: 2020, track_count: 1, duration_sec: 100, cover_url: '/x', cover_art_source: null
|
||||
};
|
||||
const tr: TrackRef = {
|
||||
id: 't1', title: 'Z', album_id: 'al1', album_title: 'Y',
|
||||
artist_id: 'a1', artist_name: 'X',
|
||||
track_number: 1, disc_number: 1, duration_sec: 100,
|
||||
stream_url: '/api/tracks/t1/stream'
|
||||
};
|
||||
const tr: TrackRef = makeTrack({
|
||||
title: 'Z', album_id: 'al1', album_title: 'Y',
|
||||
artist_id: 'a1', artist_name: 'X', duration_sec: 100
|
||||
});
|
||||
(createLikedArtistsInfiniteQuery as ReturnType<typeof vi.fn>).mockReturnValue(
|
||||
mockInfiniteQuery({ pages: [page([ar], 1)] })
|
||||
);
|
||||
|
||||
@@ -3,7 +3,8 @@ import { render, screen } from '@testing-library/svelte';
|
||||
import { mockQuery } from '../../test-utils/query';
|
||||
import { emptyLikesMock } from '../../test-utils/mocks/likes';
|
||||
import { pageUrlModule } from '$test-utils/mocks/appState';
|
||||
import type { ArtistRef, AlbumRef, TrackRef, SearchResponse } from '$lib/api/types';
|
||||
import type { ArtistRef, AlbumRef, SearchResponse } from '$lib/api/types';
|
||||
import { makeTrack } from '$test-utils/fixtures/track';
|
||||
|
||||
const state = vi.hoisted(() => ({
|
||||
pageUrl: new URL('http://localhost/search')
|
||||
@@ -44,13 +45,12 @@ const album: AlbumRef = {
|
||||
id: 'al1', title: 'Kind of Blue', sort_title: 'Kind of Blue', artist_id: 'a1', artist_name: 'Miles Davis',
|
||||
year: 1959, track_count: 5, duration_sec: 2630, cover_url: '/api/albums/al1/cover', cover_art_source: null
|
||||
};
|
||||
const track: TrackRef = {
|
||||
id: 't1', title: 'So What',
|
||||
const track = makeTrack({
|
||||
title: 'So What',
|
||||
album_id: 'al1', album_title: 'Kind of Blue',
|
||||
artist_id: 'a1', artist_name: 'Miles Davis',
|
||||
track_number: 1, disc_number: 1, duration_sec: 545,
|
||||
stream_url: '/api/tracks/t1/stream'
|
||||
};
|
||||
duration_sec: 545
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
@@ -5,6 +5,7 @@ import { emptyLikesMock } from '../../../test-utils/mocks/likes';
|
||||
import { emptyQuarantineMock } from '../../../test-utils/mocks/quarantine';
|
||||
import { pageUrlModule } from '$test-utils/mocks/appState';
|
||||
import type { TrackRef, Page } from '$lib/api/types';
|
||||
import { makeTrack } from '$test-utils/fixtures/track';
|
||||
|
||||
const state = vi.hoisted(() => ({ pageUrl: new URL('http://localhost/search/tracks?q=miles') }));
|
||||
|
||||
@@ -32,13 +33,7 @@ function page<T>(items: T[], total: number, offset = 0, limit = 50): Page<T> {
|
||||
return { items, total, offset, limit };
|
||||
}
|
||||
|
||||
const track: TrackRef = {
|
||||
id: 't1', title: 'So What',
|
||||
album_id: 'al1', album_title: 'Kind of Blue',
|
||||
artist_id: 'a1', artist_name: 'Miles Davis',
|
||||
track_number: 1, disc_number: 1, duration_sec: 545,
|
||||
stream_url: '/api/tracks/t1/stream'
|
||||
};
|
||||
const track = makeTrack({ title: 'So What' });
|
||||
|
||||
afterEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
Reference in New Issue
Block a user