Merges Renovate's kit 3 (PR #149) and adapter-static 4 (PR #148) bumps, plus the migration they need. The mechanical part is `sv migrate sveltekit-3`, run one task at a time and reviewed: - svelte.config.js is gone. Its options move into sveltekit() in vite.config.ts, exported as kitOptions so vitest.config.ts runs the same kit setup, including the $test-utils alias the tests import. - $lib becomes #lib through package.json "imports". There is no src/lib/index, so only the "#lib/*" entry is kept. - tsconfig extends $app/tsconfig. - Peer floors raised to kit 3's requirements: svelte ^5.57.1, vite ^8.0.12, svelte-check ^4.7.5. By hand, from the codemod's list of non-automated tasks: - goto's replaceState option is now replace; keepFocus becomes reset: false. For the search typeahead, reset: false also stops the scroll-to-top, which is wanted while typing. - The test setup mocks drop pushState/replaceState and $app/paths base/assets, which kit 3 removed, and mock refreshAll in place of invalidateAll. - The other flagged files only read page.url or goto internal routes, so they needed no change. TypeScript goes to ^6, not the ^7 Renovate offers: kit 3 declares typescript ^6 as a peer and svelte-check 4.7 accepts ^5 || ^6. Move to 7 once both accept it. With Tailwind 4 and kit 3 in, `npm audit` on the whole tree reports 0, so the web lane now audits every dependency rather than only what ships to browsers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
136 lines
5.3 KiB
TypeScript
136 lines
5.3 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
|
|
import { render, screen } from '@testing-library/svelte';
|
|
import { flushSync } from 'svelte';
|
|
import { mockQuery } from '../../../test-utils/query';
|
|
import { emptyLikesMock } from '../../../test-utils/mocks/likes';
|
|
import type { ArtistDetail, AlbumRef } from '#lib/api/types.js';
|
|
|
|
const state = vi.hoisted(() => ({ pageParams: { id: 'abc' } as Record<string, string> }));
|
|
|
|
vi.mock('$app/state', () => ({
|
|
page: {
|
|
get params() { return state.pageParams; },
|
|
get url() { return new URL('http://localhost/artists/' + state.pageParams.id); }
|
|
}
|
|
}));
|
|
|
|
vi.mock('#lib/api/queries.js', () => ({
|
|
qk: { artist: (id: string) => ['artist', id] },
|
|
createArtistQuery: vi.fn(),
|
|
createSimilarArtistsQuery: vi.fn(),
|
|
createArtistTopTracksQuery: vi.fn()
|
|
}));
|
|
|
|
vi.mock('#lib/api/likes.js', () => emptyLikesMock());
|
|
|
|
import ArtistPage from './+page.svelte';
|
|
import {
|
|
createArtistQuery,
|
|
createSimilarArtistsQuery,
|
|
createArtistTopTracksQuery
|
|
} from '#lib/api/queries.js';
|
|
|
|
function album(id: string, title: string, year?: number): AlbumRef {
|
|
return {
|
|
id, title,
|
|
sort_title: title,
|
|
artist_id: 'abc', artist_name: 'Alice',
|
|
year, track_count: 10, duration_sec: 2400,
|
|
cover_url: `/api/albums/${id}/cover`,
|
|
cover_art_source: null
|
|
};
|
|
}
|
|
|
|
afterEach(() => {
|
|
vi.clearAllMocks();
|
|
state.pageParams = { id: 'abc' };
|
|
});
|
|
|
|
beforeEach(() => {
|
|
// Secondary sections default to empty so the existing album-grid assertions
|
|
// are unaffected; individual tests can override to exercise the new strips.
|
|
(createSimilarArtistsQuery as ReturnType<typeof vi.fn>).mockReturnValue(mockQuery({ data: [] }));
|
|
(createArtistTopTracksQuery as ReturnType<typeof vi.fn>).mockReturnValue(mockQuery({ data: [] }));
|
|
});
|
|
|
|
describe('artist detail page', () => {
|
|
test('renders artist name, subtitle, and one AlbumCard per album', () => {
|
|
const detail: ArtistDetail = {
|
|
id: 'abc', name: 'Alice', sort_name: 'Alice', album_count: 2, cover_url: '',
|
|
albums: [album('a1', 'First', 2020), album('a2', 'Second')],
|
|
genres: []
|
|
};
|
|
(createArtistQuery as ReturnType<typeof vi.fn>).mockReturnValue(mockQuery({ data: detail }));
|
|
render(ArtistPage);
|
|
expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent('Alice');
|
|
expect(screen.getByText(/2 albums/i)).toBeInTheDocument();
|
|
expect(screen.getByRole('link', { name: /First/ })).toHaveAttribute('href', '/albums/a1');
|
|
expect(screen.getByRole('link', { name: /Second/ })).toHaveAttribute('href', '/albums/a2');
|
|
});
|
|
|
|
test('renders top-tracks panel and similar-artists strip when present', () => {
|
|
const detail: ArtistDetail = {
|
|
id: 'abc', name: 'Alice', sort_name: 'Alice', album_count: 1, cover_url: '',
|
|
albums: [album('a1', 'First', 2020)],
|
|
genres: []
|
|
};
|
|
(createArtistQuery as ReturnType<typeof vi.fn>).mockReturnValue(mockQuery({ data: detail }));
|
|
(createArtistTopTracksQuery as ReturnType<typeof vi.fn>).mockReturnValue(mockQuery({
|
|
data: [{
|
|
id: 't1', title: 'Hit Song', album_id: 'a1', album_title: 'First',
|
|
artist_id: 'abc', artist_name: 'Alice', duration_sec: 200, stream_url: '/s/t1'
|
|
}]
|
|
}));
|
|
(createSimilarArtistsQuery as ReturnType<typeof vi.fn>).mockReturnValue(mockQuery({
|
|
data: [{ id: 'sim1', name: 'Bob', sort_name: 'Bob', album_count: 2, cover_url: '' }]
|
|
}));
|
|
render(ArtistPage);
|
|
expect(screen.getByText(/top tracks/i)).toBeInTheDocument();
|
|
expect(screen.getByText('Hit Song')).toBeInTheDocument();
|
|
expect(screen.getByText(/similar artists/i)).toBeInTheDocument();
|
|
expect(screen.getByRole('link', { name: /Bob/ })).toHaveAttribute('href', '/artists/sim1');
|
|
});
|
|
|
|
test('back link points to Library', () => {
|
|
(createArtistQuery as ReturnType<typeof vi.fn>).mockReturnValue(mockQuery({
|
|
data: { id: 'abc', name: 'Alice', sort_name: 'Alice', album_count: 0, cover_url: '', albums: [] }
|
|
}));
|
|
render(ArtistPage);
|
|
const back = screen.getByRole('link', { name: /library/i });
|
|
expect(back).toHaveAttribute('href', '/');
|
|
});
|
|
|
|
test('404 renders non-retryable "Artist not found" with back link', () => {
|
|
(createArtistQuery as ReturnType<typeof vi.fn>).mockReturnValue(mockQuery({
|
|
isError: true,
|
|
error: { code: 'not_found', message: 'nope', status: 404 }
|
|
}));
|
|
render(ArtistPage);
|
|
expect(screen.getByText(/artist not found/i)).toBeInTheDocument();
|
|
expect(screen.queryByRole('button', { name: /try again/i })).not.toBeInTheDocument();
|
|
});
|
|
|
|
test('non-404 error renders the retry banner', () => {
|
|
(createArtistQuery as ReturnType<typeof vi.fn>).mockReturnValue(mockQuery({
|
|
isError: true,
|
|
error: { code: 'server_error', message: 'boom', status: 500 }
|
|
}));
|
|
render(ArtistPage);
|
|
expect(screen.getByRole('alert')).toHaveTextContent('boom');
|
|
expect(screen.getByRole('button', { name: /try again/i })).toBeInTheDocument();
|
|
});
|
|
|
|
test('pending (after delay) renders the grid skeleton', () => {
|
|
(createArtistQuery as ReturnType<typeof vi.fn>).mockReturnValue(mockQuery({ isPending: true }));
|
|
vi.useFakeTimers();
|
|
try {
|
|
render(ArtistPage);
|
|
vi.advanceTimersByTime(200);
|
|
flushSync();
|
|
expect(screen.getByTestId('skeleton-grid')).toBeInTheDocument();
|
|
} finally {
|
|
vi.useRealTimers();
|
|
}
|
|
});
|
|
});
|