Loading panel (role=status, motion-safe spinner + pulsing subtitle) and combined error panels: 503 (red icon + switch-to-keyword button) and 429 (amber clock icon, no action button). 5 vitest-browser-svelte specs. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
61 lines
2.2 KiB
TypeScript
61 lines
2.2 KiB
TypeScript
import { describe, expect, it, vi, afterEach } from 'vitest';
|
|
import { cleanup, render } from 'vitest-browser-svelte';
|
|
import { page } from 'vitest/browser';
|
|
import SmartSearchStatus from './SmartSearchStatus.svelte';
|
|
|
|
afterEach(() => {
|
|
cleanup();
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
describe('SmartSearchStatus', () => {
|
|
it('renders a role="status" loading panel with the loading title', async () => {
|
|
render(SmartSearchStatus, { status: 'loading' });
|
|
const status = page.getByRole('status');
|
|
await expect.element(status).toBeInTheDocument();
|
|
await expect.element(status).toHaveTextContent('Archiv wird befragt');
|
|
});
|
|
|
|
it('hides the loading panel once the status changes away from loading', async () => {
|
|
const { rerender } = render(SmartSearchStatus, { status: 'loading' });
|
|
await expect.element(page.getByRole('status')).toBeInTheDocument();
|
|
await rerender({ status: 'error', errorCode: 'SMART_SEARCH_UNAVAILABLE' });
|
|
await expect.element(page.getByRole('status')).not.toBeInTheDocument();
|
|
});
|
|
|
|
it('renders the 503 panel with title, body and a switch-to-keyword button', async () => {
|
|
render(SmartSearchStatus, {
|
|
status: 'error',
|
|
errorCode: 'SMART_SEARCH_UNAVAILABLE',
|
|
onSwitchToKeyword: vi.fn()
|
|
});
|
|
await expect.element(page.getByText('Intelligente Suche nicht verfügbar')).toBeInTheDocument();
|
|
await expect
|
|
.element(page.getByRole('button', { name: /Volltextsuche wechseln/ }))
|
|
.toBeInTheDocument();
|
|
});
|
|
|
|
it('invokes onSwitchToKeyword when the 503 fallback button is clicked', async () => {
|
|
const onSwitchToKeyword = vi.fn();
|
|
render(SmartSearchStatus, {
|
|
status: 'error',
|
|
errorCode: 'SMART_SEARCH_UNAVAILABLE',
|
|
onSwitchToKeyword
|
|
});
|
|
await page.getByRole('button', { name: /Volltextsuche wechseln/ }).click();
|
|
expect(onSwitchToKeyword).toHaveBeenCalledOnce();
|
|
});
|
|
|
|
it('renders the 429 panel with title and body but no switch-to-keyword button', async () => {
|
|
render(SmartSearchStatus, {
|
|
status: 'error',
|
|
errorCode: 'SMART_SEARCH_RATE_LIMITED',
|
|
onSwitchToKeyword: vi.fn()
|
|
});
|
|
await expect.element(page.getByText('Zu viele Anfragen')).toBeInTheDocument();
|
|
await expect
|
|
.element(page.getByRole('button', { name: /Volltextsuche wechseln/ }))
|
|
.not.toBeInTheDocument();
|
|
});
|
|
});
|