feat(web): wire LikeButton into TrackRow, AlbumCard, ArtistRow, PlayerBar
Heart appears on every entity rendering surface. ArtistRow restructured to a <div> with the link as a positioned overlay so the heart button can nest without invalid <button>-in-<a> markup. Shell nav grows a 'Liked' entry pointing at /library/liked.
This commit is contained in:
@@ -1,8 +1,24 @@
|
||||
import { describe, expect, test } from 'vitest';
|
||||
import { describe, expect, test, vi } from 'vitest';
|
||||
import { render, screen } from '@testing-library/svelte';
|
||||
import { readable } from 'svelte/store';
|
||||
import ArtistRow from './ArtistRow.svelte';
|
||||
import type { ArtistRef } from '$lib/api/types';
|
||||
|
||||
vi.mock('$lib/api/likes', () => ({
|
||||
createLikedIdsQuery: () => readable({
|
||||
data: { track_ids: [], album_ids: [], artist_ids: [] },
|
||||
isPending: false,
|
||||
isError: false
|
||||
}),
|
||||
likeEntity: vi.fn(),
|
||||
unlikeEntity: vi.fn()
|
||||
}));
|
||||
|
||||
vi.mock('@tanstack/svelte-query', async (orig) => {
|
||||
const actual = (await orig()) as Record<string, unknown>;
|
||||
return { ...actual, useQueryClient: () => ({}) };
|
||||
});
|
||||
|
||||
const artist: ArtistRef = { id: 'abc', name: 'alice', album_count: 12 };
|
||||
|
||||
describe('ArtistRow', () => {
|
||||
@@ -11,14 +27,14 @@ describe('ArtistRow', () => {
|
||||
|
||||
const link = screen.getByRole('link');
|
||||
expect(link).toHaveAttribute('href', '/artists/abc');
|
||||
expect(link).toHaveTextContent('alice');
|
||||
expect(link).toHaveTextContent('12 albums');
|
||||
expect(link).toHaveTextContent('A'); // initial letter
|
||||
expect(screen.getByText('alice')).toBeInTheDocument();
|
||||
expect(screen.getByText('12 albums')).toBeInTheDocument();
|
||||
expect(screen.getByText('A')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('singular "1 album" when album_count is 1', () => {
|
||||
render(ArtistRow, { props: { artist: { ...artist, album_count: 1 } } });
|
||||
expect(screen.getByRole('link')).toHaveTextContent('1 album');
|
||||
expect(screen.getByText('1 album')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('empty name still renders a safe initial', () => {
|
||||
|
||||
Reference in New Issue
Block a user