release / govulncheck (push) Successful in 23s
release / web (push) Successful in 1m22s
release / go (push) Successful in 1m41s
release / integration (push) Successful in 4m49s
release / android (push) Successful in 5m32s
release / Build signed APK (releases and dev) (push) Successful in 5m39s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 28s
release / Verify release artifacts (tag releases only) (push) Skipped
CI run 8789 warned on both: - kit 3 deprecates `config.alias`. The $test-utils alias becomes a `#test-utils/*` subpath import, matching #lib, and its 43 import sites move with it. - Vite's coming native config loader needs the extension on vitest.config.ts's import of vite.config. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
88 lines
3.7 KiB
TypeScript
88 lines
3.7 KiB
TypeScript
import { afterEach, describe, expect, test, vi } from 'vitest';
|
|
import { render, screen, fireEvent, waitFor } from '@testing-library/svelte';
|
|
import { emptyLikesMock } from '../../test-utils/mocks/likes';
|
|
import { emptyPlaylistsMock } from '../../test-utils/mocks/playlists';
|
|
import type { TrackRef } from '#lib/api/types.js';
|
|
import { makeTracks } from '#test-utils/fixtures/track.js';
|
|
|
|
vi.mock('$app/navigation', () => ({ goto: vi.fn() }));
|
|
|
|
vi.mock('#lib/api/likes.js', () => emptyLikesMock());
|
|
|
|
vi.mock('#lib/api/albums.js', async (orig) => {
|
|
const actual = (await orig()) as Record<string, unknown>;
|
|
return { ...actual, listAlbumTracks: vi.fn().mockResolvedValue([]) };
|
|
});
|
|
|
|
vi.mock('#lib/api/playlists.js', () => emptyPlaylistsMock());
|
|
|
|
vi.mock('#lib/player/store.svelte.js', () => ({
|
|
enqueueTracks: vi.fn()
|
|
}));
|
|
|
|
import AlbumMenu from './AlbumMenu.svelte';
|
|
import { enqueueTracks } from '#lib/player/store.svelte.js';
|
|
import { listAlbumTracks } from '#lib/api/albums.js';
|
|
import { likeEntity } from '#lib/api/likes.js';
|
|
import { goto } from '$app/navigation';
|
|
|
|
const TRACKS: TrackRef[] = makeTracks(2, {
|
|
album_id: 'al1', album_title: 'Disc', artist_id: 'a1', artist_name: 'Test'
|
|
});
|
|
|
|
const PROPS = { albumId: 'al1', albumTitle: 'Disc', artistId: 'a1', artistName: 'Test' };
|
|
|
|
afterEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
describe('AlbumMenu', () => {
|
|
test('kebab opens menu with action items', async () => {
|
|
render(AlbumMenu, { props: { ...PROPS, tracks: TRACKS } });
|
|
await fireEvent.click(screen.getByRole('button', { name: /album actions for disc/i }));
|
|
expect(await screen.findByText(/Like album/i)).toBeInTheDocument();
|
|
expect(screen.getByText(/Add to queue/i)).toBeInTheDocument();
|
|
expect(screen.getByText(/Add to playlist/i)).toBeInTheDocument();
|
|
expect(screen.getByText(/Go to artist/i)).toBeInTheDocument();
|
|
});
|
|
|
|
test('Add to queue uses cached tracks when provided', async () => {
|
|
render(AlbumMenu, { props: { ...PROPS, tracks: TRACKS } });
|
|
await fireEvent.click(screen.getByRole('button', { name: /album actions for disc/i }));
|
|
await fireEvent.click(screen.getByText(/Add to queue/i));
|
|
expect(enqueueTracks).toHaveBeenCalledWith(TRACKS);
|
|
expect(listAlbumTracks).not.toHaveBeenCalled();
|
|
});
|
|
|
|
test('Add to queue lazily fetches when no cached tracks', async () => {
|
|
(listAlbumTracks as unknown as ReturnType<typeof vi.fn>).mockResolvedValueOnce(TRACKS);
|
|
render(AlbumMenu, { props: PROPS });
|
|
await fireEvent.click(screen.getByRole('button', { name: /album actions for disc/i }));
|
|
await fireEvent.click(screen.getByText(/Add to queue/i));
|
|
await waitFor(() => expect(enqueueTracks).toHaveBeenCalledWith(TRACKS));
|
|
expect(listAlbumTracks).toHaveBeenCalledWith('al1');
|
|
});
|
|
|
|
test('Like item calls likeEntity', async () => {
|
|
render(AlbumMenu, { props: { ...PROPS, tracks: TRACKS } });
|
|
await fireEvent.click(screen.getByRole('button', { name: /album actions for disc/i }));
|
|
await fireEvent.click(screen.getByText(/Like album/i));
|
|
expect(likeEntity).toHaveBeenCalled();
|
|
});
|
|
|
|
test('Go to artist navigates', async () => {
|
|
render(AlbumMenu, { props: { ...PROPS, tracks: TRACKS } });
|
|
await fireEvent.click(screen.getByRole('button', { name: /album actions for disc/i }));
|
|
await fireEvent.click(screen.getByText(/Go to artist/i));
|
|
expect(goto).toHaveBeenCalledWith('/artists/a1');
|
|
});
|
|
|
|
test('Escape key closes the menu', async () => {
|
|
render(AlbumMenu, { props: { ...PROPS, tracks: TRACKS } });
|
|
await fireEvent.click(screen.getByRole('button', { name: /album actions for disc/i }));
|
|
expect(await screen.findByText(/Like album/i)).toBeInTheDocument();
|
|
await fireEvent.keyDown(window, { key: 'Escape' });
|
|
expect(screen.queryByText(/Like album/i)).not.toBeInTheDocument();
|
|
});
|
|
});
|