Files
minstrel/web/src/lib/components/Shell.test.ts
T
bvandeusenandClaude Opus 5.5 55c7497ca7
release / go (push) Successful in 1m54s
release / web (push) Failing after 5s
release / integration (push) Failing after 3m44s
release / govulncheck (push) Successful in 20s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / Build signed APK (push) Canceled after 19s
release / android (push) Canceled after 2m37s
feat: Minstrel stops acquiring music and drops Discover
Minstrel is now a viewer of the library it is pointed at. Finding,
downloading and filing music moves out of it.

Removed from the server:
- the request flow (requests, approval, auto-approve) and the wanted list,
  follows, release profiles and release blocks;
- searching indexers, the download clients, the importer, the album
  lifecycle and missing-file re-acquisition;
- the catalogue's discography, search and art (the MusicBrainz release and
  track-list cache stays, for the duplicate resolver);
- Discover: its suggestions of artists not in the library, snoozes, the
  candidate-artist tag enrichment and its tuning scope;
- writes to acquisition tables from moving the library folder and from
  merging duplicates, the want-list join on Suspect sources, the sealing of
  acquisition credentials, and the release-group lookup only
  re-acquisition used.

Settling a wrong-slot duplicate no longer sets the release aside: the
copies go and their slots show as missing until a good copy is in the
library.

Removed from the web: Admin > Acquisition and Requests, /requests,
/discover, Follow on the artist page, the auto-approve toggle, and the
Collection's wanted-list tabs. The Collection is now the library's health:
an overview, Reports, Duplicates, Suspect sources and Missing files. The
README and docs no longer describe getting music.

The tables stay for now; a later migration drops them. The request
notification kinds and the Android screens are still to go.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 20:51:14 -05:00

131 lines
5.2 KiB
TypeScript

import { afterEach, describe, expect, test, vi } from 'vitest';
import { render, screen, fireEvent } from '@testing-library/svelte';
vi.mock('$app/state', () => ({
page: { url: new URL('http://localhost/') }
}));
vi.mock('$app/navigation', () => ({
goto: vi.fn()
}));
// Mutable handle so individual tests can flip the user between admin /
// non-admin without re-importing the module.
const userState = vi.hoisted(() => ({
current: { id: '1', username: 'alice', is_admin: false } as {
id: string;
username: string;
is_admin: boolean;
} | null
}));
vi.mock('#lib/auth/store.svelte.js', () => ({
user: { get value() { return userState.current; } },
logout: vi.fn().mockResolvedValue(undefined)
}));
// The bell's queries need a QueryClient the Shell tests do not provide; its own
// behaviour is covered in NotificationBell.test.ts.
vi.mock('#lib/api/notifications.js', async () => {
const { mockQuery } = await import('../../test-utils/query');
return {
createUnreadCountQuery: () => mockQuery({ data: 0 }),
createNotificationsQuery: () => mockQuery({ data: { items: [], unread_count: 0 } }),
markNotificationRead: vi.fn(),
markAllNotificationsRead: vi.fn(),
readAllCutoff: () => undefined,
badgeLabel: () => ''
};
});
import Shell from './Shell.svelte';
import { logout } from '#lib/auth/store.svelte.js';
import { goto } from '$app/navigation';
afterEach(() => {
vi.clearAllMocks();
userState.current = { id: '1', username: 'alice', is_admin: false };
});
describe('Shell', () => {
test('renders the username in the header', () => {
render(Shell);
expect(screen.getByText('alice')).toBeInTheDocument();
});
test('main nav renders the primary surfaces in order', () => {
render(Shell);
// Library is a parent for Artists / Albums / Liked / History /
// Playlists (tabs under /library); only the parent appears here.
const labels = ['Home', 'Library'];
for (const label of labels) {
expect(screen.getByRole('link', { name: label })).toBeInTheDocument();
}
expect(screen.getByRole('link', { name: 'Home' })).toHaveAttribute('href', '/');
// Library jumps to the Artists tab directly so SPA navigation
// bypasses the /library 308-redirect.
expect(screen.getByRole('link', { name: 'Library' })).toHaveAttribute('href', '/library/artists');
});
test('admins get Collection after Library; others do not', () => {
const primary = () =>
screen
.getAllByRole('link')
.filter((el) => el.closest('nav[aria-label="Primary"]') !== null)
.map((el) => el.textContent?.trim());
const { unmount } = render(Shell);
expect(primary()).not.toContain('Collection');
unmount();
userState.current = { id: '1', username: 'alice', is_admin: true };
render(Shell);
expect(primary()).toEqual(['Home', 'Library', 'Collection']);
expect(screen.getByRole('link', { name: 'Collection' })).toHaveAttribute('href', '/collection');
});
test('main nav omits Artists/Albums/Liked/History/Playlists/Search/Settings/Admin', () => {
userState.current = { id: '1', username: 'alice', is_admin: true };
render(Shell);
// Library sub-pages reach their content via the /library tab bar
// (in routes/library/+layout.svelte), not via the global Shell nav.
// Search reaches /search via the global SearchInput on the right.
// Settings + Admin live in the username dropdown — they're per-
// operator chrome, not primary surfaces.
const navLinks = screen
.getAllByRole('link')
.filter((el) => el.closest('nav[aria-label="Primary"]') !== null)
.map((el) => el.textContent?.trim());
for (const label of [
'Artists', 'Albums', 'Liked', 'History', 'Playlists',
'Search', 'Hidden', 'Settings', 'Admin'
]) {
expect(navLinks).not.toContain(label);
}
});
test('user-menu shows Settings + Log out for non-admin users', async () => {
userState.current = { id: '1', username: 'alice', is_admin: false };
render(Shell);
await fireEvent.click(screen.getByRole('button', { name: /alice/i }));
expect(screen.getByRole('menuitem', { name: 'Settings' })).toHaveAttribute('href', '/settings');
expect(screen.getByRole('menuitem', { name: /log out/i })).toBeInTheDocument();
expect(screen.queryByRole('menuitem', { name: 'Admin' })).not.toBeInTheDocument();
});
test('user-menu adds Admin between Settings and Log out for admin users', async () => {
userState.current = { id: '1', username: 'alice', is_admin: true };
render(Shell);
await fireEvent.click(screen.getByRole('button', { name: /alice/i }));
const items = screen.getAllByRole('menuitem').map((el) => el.textContent?.trim());
expect(items).toEqual(['Settings', 'Admin', 'Log out']);
expect(screen.getByRole('menuitem', { name: 'Admin' })).toHaveAttribute('href', '/admin');
});
test('user-menu "Log out" calls logout() and navigates to /login', async () => {
render(Shell);
await fireEvent.click(screen.getByRole('button', { name: /alice/i }));
await fireEvent.click(screen.getByRole('menuitem', { name: /log out/i }));
expect(logout).toHaveBeenCalledTimes(1);
expect(goto).toHaveBeenCalledWith('/login', { replace: true });
});
});