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>
35 lines
1.3 KiB
TypeScript
35 lines
1.3 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/discover')
|
|
}));
|
|
|
|
vi.mock('$app/state', () => pageUrlModule(state));
|
|
|
|
import DiscoverTabs from './DiscoverTabs.svelte';
|
|
|
|
describe('DiscoverTabs', () => {
|
|
test('Discover tab is current on /discover', () => {
|
|
state.pageUrl = new URL('http://localhost/discover');
|
|
render(DiscoverTabs);
|
|
expect(screen.getByRole('link', { name: /discover/i })).toHaveAttribute('aria-current', 'page');
|
|
expect(screen.getByRole('link', { name: /requests/i })).not.toHaveAttribute('aria-current');
|
|
});
|
|
|
|
test('Requests tab is current on /requests', () => {
|
|
state.pageUrl = new URL('http://localhost/requests');
|
|
render(DiscoverTabs);
|
|
expect(screen.getByRole('link', { name: /requests/i })).toHaveAttribute('aria-current', 'page');
|
|
expect(screen.getByRole('link', { name: /discover/i })).not.toHaveAttribute('aria-current');
|
|
});
|
|
|
|
test('renders both tabs in order', () => {
|
|
state.pageUrl = new URL('http://localhost/discover');
|
|
render(DiscoverTabs);
|
|
const labels = screen.getAllByRole('link').map((l) => l.textContent?.trim());
|
|
expect(labels).toEqual(['Discover', 'Requests']);
|
|
});
|
|
});
|