import { fireEvent, render, screen } from '@testing-library/angular'; import { of } from 'rxjs'; import { BffApiV1Service, type OpenbaarEntry } from 'api-client'; import { axe } from 'vitest-axe'; import { RegisterPage } from './register-page'; const sample: OpenbaarEntry[] = [ { id: 'zaak-abc', status: 'INGEDIEND', reference: 'REG-abc' }, { id: 'zaak-def', status: 'INGESCHREVEN', reference: 'REG-def' }, ]; function providers(get = vi.fn().mockReturnValue(of(sample))) { return { get, providers: [{ provide: BffApiV1Service, useValue: { getOpenbaarRegister: get } }], }; } describe('RegisterPage', () => { it('lists the public register entries from the BFF on open', async () => { const { get } = providers(); await render(RegisterPage, { providers: providers(get).providers }); expect(get).toHaveBeenCalled(); // The Referentie column shows the citizen's reference (matches the submit confirmation, #78), // not the internal zaak id. expect(await screen.findByText(/REG-abc/)).toBeTruthy(); expect(screen.getByText(/INGEDIEND/)).toBeTruthy(); expect(screen.getByText(/REG-def/)).toBeTruthy(); }); it('searches by the entered term', async () => { const get = vi.fn().mockReturnValue(of(sample)); await render(RegisterPage, { providers: providers(get).providers }); fireEvent.input(screen.getByRole('searchbox'), { target: { value: 'zaak-abc' } }); fireEvent.click(screen.getByRole('button', { name: /zoek/i })); expect(get).toHaveBeenLastCalledWith({ q: 'zaak-abc' }); }); it('shows an empty-state message when the register has no matches', async () => { const get = vi.fn().mockReturnValue(of([] as OpenbaarEntry[])); await render(RegisterPage, { providers: providers(get).providers }); expect(await screen.findByText(/geen inschrijvingen gevonden/i)).toBeTruthy(); }); it('has no WCAG 2.1 AA violations', async () => { document.documentElement.lang = 'nl'; const { container } = await render(RegisterPage, { providers: providers().providers }); const results = await axe(container, { runOnly: { type: 'tag', values: ['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa'] }, }); expect(results.violations).toEqual([]); }); });