import { afterEach, describe, expect, test, vi } from 'vitest'; import { cleanup, render, screen } from '@testing-library/svelte'; import { readable } from 'svelte/store'; import { apiClientMock } from '../../../test-utils/mocks/client'; vi.mock('#lib/api/albums.js', () => ({ createAlbumsAlphaInfiniteQuery: () => readable({ data: { pages: [{ items: [], total: 0, limit: 50, offset: 0 }] }, isPending: false, isError: false, hasNextPage: false, isFetchingNextPage: false, refetch: () => {}, fetchNextPage: () => {} }), ALBUM_PAGE_SIZE: 50 })); vi.mock('#lib/api/client.js', () => apiClientMock()); import Page from './+page.svelte'; import { setUser } from '#lib/auth/user.svelte.js'; import type { User } from '#lib/api/client.js'; afterEach(() => { cleanup(); setUser(null); }); // An empty library sends an admin to Admin to run a scan, and nobody to // Settings. describe('/library/albums with an empty library', () => { test('an admin is sent to Admin to run a scan', () => { setUser({ id: 'u1', username: 'root', is_admin: true } as User); render(Page); expect(screen.getByRole('link', { name: /run a scan/i }).getAttribute('href')).toBe('/admin'); expect(screen.queryByRole('link', { name: /open settings/i })).toBeNull(); }); test('anyone else is told the admin scans the library, with no link', () => { setUser({ id: 'u2', username: 'alice', is_admin: false } as User); render(Page); expect(screen.getByText(/your server's admin has scanned the library/i)).toBeInTheDocument(); expect(screen.queryByRole('link')).toBeNull(); }); });