refactor(web): extract emptyPlaylistsMock + apiClientMock test helpers
The DRY pass audit (#375) found two inline mock patterns repeated across the vitest suite: a default empty-playlists mock for $lib/api/playlists (4 exact copies in menu/card tests) and an api-client spy mock for $lib/api/client (9 callers split between get-only and full-RESTy shapes — unified into one helper that always returns all four verb spies). Mirrors the existing test-utils/mocks/likes.ts and test-utils/mocks/quarantine.ts convention. Tests with intentionally divergent shapes (AddToPlaylistMenu's richer createPlaylist payload, PlaylistCard's getPlaylist, route-specific mocks, events.svelte's specific resolved value) stay inline. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { afterEach, describe, expect, test, vi } from 'vitest';
|
||||
import { render, screen, fireEvent, waitFor } from '@testing-library/svelte';
|
||||
import { readable } from 'svelte/store';
|
||||
import { emptyLikesMock } from '../../test-utils/mocks/likes';
|
||||
import { emptyPlaylistsMock } from '../../test-utils/mocks/playlists';
|
||||
import { emptyQuarantineMock } from '../../test-utils/mocks/quarantine';
|
||||
import { makeTrack } from '$test-utils/fixtures/track';
|
||||
|
||||
@@ -29,12 +29,7 @@ vi.mock('$lib/api/admin/tracks', () => ({
|
||||
removeTrack: vi.fn().mockResolvedValue({ deleted_track_id: 't1' })
|
||||
}));
|
||||
|
||||
vi.mock('$lib/api/playlists', () => ({
|
||||
createPlaylistsQuery: () =>
|
||||
readable({ data: { owned: [], public: [] }, isPending: false, isError: false }),
|
||||
appendTracks: vi.fn().mockResolvedValue({ id: 'p1', tracks: [] }),
|
||||
createPlaylist: vi.fn().mockResolvedValue({ id: 'p1', name: 'New' })
|
||||
}));
|
||||
vi.mock('$lib/api/playlists', () => emptyPlaylistsMock());
|
||||
|
||||
vi.mock('$lib/player/store.svelte', () => ({
|
||||
playNext: vi.fn(),
|
||||
|
||||
Reference in New Issue
Block a user