dd67f28745
Centralizes the inline { page: { get url() { return state.pageUrl } } }
mock shape via test-utils/mocks/appState.ts. The vi.hoisted state
declaration remains per-file (vitest mock-hoisting requires module-
level declaration). Adds a $test-utils alias to svelte.config.js so
the helper can be imported without ../../../ chains.
SKIPPED (mock exposes more than url):
- Shell.test.ts, MobileNavDrawer.test.ts, admin.test.ts: static
page: { url: ... } shape, no hoisted state to centralize.
- album.test.ts, artist.test.ts: page exposes both params and url.
- playlist.test.ts, reset-password.test.ts: page exposes params only.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
68 lines
2.2 KiB
TypeScript
68 lines
2.2 KiB
TypeScript
import { describe, expect, test, vi } from 'vitest';
|
|
import { render, screen } from '@testing-library/svelte';
|
|
import { pageUrlModule } from '$test-utils/mocks/appState';
|
|
|
|
const state = vi.hoisted(() => ({
|
|
pageUrl: new URL('http://localhost/admin')
|
|
}));
|
|
|
|
vi.mock('$app/state', () => pageUrlModule(state));
|
|
|
|
import AdminTabs from './AdminTabs.svelte';
|
|
|
|
describe('AdminTabs', () => {
|
|
test('Overview tab is current when on /admin', () => {
|
|
state.pageUrl = new URL('http://localhost/admin');
|
|
render(AdminTabs);
|
|
const overview = screen.getByRole('link', { name: /overview/i });
|
|
expect(overview).toHaveAttribute('aria-current', 'page');
|
|
});
|
|
|
|
test('Integrations tab is current when on /admin/integrations', () => {
|
|
state.pageUrl = new URL('http://localhost/admin/integrations');
|
|
render(AdminTabs);
|
|
expect(screen.getByRole('link', { name: /integrations/i })).toHaveAttribute(
|
|
'aria-current',
|
|
'page'
|
|
);
|
|
expect(screen.getByRole('link', { name: /overview/i })).not.toHaveAttribute('aria-current');
|
|
});
|
|
|
|
test('Requests tab is current when on /admin/requests', () => {
|
|
state.pageUrl = new URL('http://localhost/admin/requests');
|
|
render(AdminTabs);
|
|
expect(screen.getByRole('link', { name: /requests/i })).toHaveAttribute('aria-current', 'page');
|
|
});
|
|
|
|
test('Quarantine tab is current when on /admin/quarantine', () => {
|
|
state.pageUrl = new URL('http://localhost/admin/quarantine');
|
|
render(AdminTabs);
|
|
expect(screen.getByRole('link', { name: /quarantine/i })).toHaveAttribute(
|
|
'aria-current',
|
|
'page'
|
|
);
|
|
});
|
|
|
|
test('Users tab is current when on /admin/users', () => {
|
|
state.pageUrl = new URL('http://localhost/admin/users');
|
|
render(AdminTabs);
|
|
expect(screen.getByRole('link', { name: /users/i })).toHaveAttribute(
|
|
'aria-current',
|
|
'page'
|
|
);
|
|
});
|
|
|
|
test('renders exactly five tabs', () => {
|
|
state.pageUrl = new URL('http://localhost/admin');
|
|
render(AdminTabs);
|
|
const links = screen.getAllByRole('link');
|
|
expect(links.map((l) => l.textContent?.trim())).toEqual([
|
|
'Overview',
|
|
'Integrations',
|
|
'Requests',
|
|
'Quarantine',
|
|
'Users'
|
|
]);
|
|
});
|
|
});
|