feat(web/m7-377): ArtistCard top-right cluster + bottom-right kebab
This commit is contained in:
@@ -6,8 +6,25 @@ vi.mock('$lib/api/client', () => ({
|
||||
api: { get: vi.fn() }
|
||||
}));
|
||||
vi.mock('$lib/player/store.svelte', () => ({
|
||||
playQueue: vi.fn()
|
||||
playQueue: vi.fn(),
|
||||
enqueueTracks: vi.fn()
|
||||
}));
|
||||
vi.mock('$lib/api/artists', () => ({
|
||||
listArtistTracks: vi.fn().mockResolvedValue([])
|
||||
}));
|
||||
vi.mock('$lib/api/likes', async () => {
|
||||
const { readable } = await import('svelte/store');
|
||||
return {
|
||||
createLikedIdsQuery: () =>
|
||||
readable({ data: { track_ids: [], album_ids: [], artist_ids: [] }, isPending: false, isError: false }),
|
||||
likeEntity: vi.fn().mockResolvedValue(undefined),
|
||||
unlikeEntity: vi.fn().mockResolvedValue(undefined)
|
||||
};
|
||||
});
|
||||
vi.mock('@tanstack/svelte-query', async (orig) => {
|
||||
const actual = (await orig()) as Record<string, unknown>;
|
||||
return { ...actual, useQueryClient: () => ({ invalidateQueries: vi.fn() }) };
|
||||
});
|
||||
|
||||
import ArtistCard from './ArtistCard.svelte';
|
||||
import { api } from '$lib/api/client';
|
||||
@@ -62,4 +79,33 @@ describe('ArtistCard', () => {
|
||||
expect(idx).toBe(0);
|
||||
expect(calledTracks.map((t: TrackRef) => t.id).sort()).toEqual(['t1', 't2']);
|
||||
});
|
||||
|
||||
test('renders the top-right action cluster (Like + Add-to-queue)', () => {
|
||||
render(ArtistCard, { props: { artist } });
|
||||
// Like button (LikeButton's aria-label is dynamic Like|Unlike).
|
||||
expect(screen.getByRole('button', { name: /^(Like|Unlike)$/ })).toBeInTheDocument();
|
||||
// Add-to-queue button.
|
||||
expect(screen.getByRole('button', { name: /Add Boards of Canada to queue/i })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('renders the bottom-right kebab', () => {
|
||||
render(ArtistCard, { props: { artist } });
|
||||
expect(screen.getByRole('button', { name: /Artist actions for Boards of Canada/i })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('+queue button calls listArtistTracks then enqueueTracks', async () => {
|
||||
const fakeTracks = [
|
||||
{ id: 't1', title: 'A', album_id: 'al1', album_title: 'X', artist_id: 'art-1', artist_name: 'BoC', duration_sec: 60, stream_url: '/s/t1' }
|
||||
];
|
||||
const { listArtistTracks } = await import('$lib/api/artists');
|
||||
(listArtistTracks as unknown as ReturnType<typeof vi.fn>).mockResolvedValueOnce(fakeTracks);
|
||||
render(ArtistCard, { props: { artist } });
|
||||
const btn = screen.getByRole('button', { name: /Add Boards of Canada to queue/i });
|
||||
await fireEvent.click(btn);
|
||||
// Allow promise microtask to flush.
|
||||
await new Promise((r) => setTimeout(r, 0));
|
||||
expect(listArtistTracks).toHaveBeenCalledWith('art-1');
|
||||
const { enqueueTracks } = await import('$lib/player/store.svelte');
|
||||
expect(enqueueTracks).toHaveBeenCalledWith(fakeTracks);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user