import { signal } from '@angular/core'; import { render, screen } from '@testing-library/angular'; import { of, throwError } from 'rxjs'; import { BeheerZaaktype, BffApiV1Service } from 'api-client'; import { AuthService } from 'auth'; import { axe } from 'vitest-axe'; import { CatalogusPage } from './catalogus-page'; const sample: BeheerZaaktype[] = [ { identificatie: 'BIG-REGISTRATIE', omschrijving: 'BIG-registratie' }, { identificatie: 'BIG-HERREGISTRATIE', omschrijving: 'BIG-herregistratie' }, ]; class FakeAuth extends AuthService { readonly isAuthenticated = signal(true); readonly bsn = signal(undefined); override readonly roles = signal(['beheerder']); login(): void { /* not exercised here */ } logout(): void { /* not exercised here */ } } function setup(overrides: { getBeheerCatalogiZaaktypen?: ReturnType } = {}) { const getBeheerCatalogiZaaktypen = overrides.getBeheerCatalogiZaaktypen ?? vi.fn().mockReturnValue(of(sample)); return { getBeheerCatalogiZaaktypen, providers: [ { provide: BffApiV1Service, useValue: { getBeheerCatalogiZaaktypen } }, { provide: AuthService, useClass: FakeAuth }, ], }; } describe('CatalogusPage', () => { it('lists the published zaaktypen on open', async () => { const { getBeheerCatalogiZaaktypen, providers } = setup(); await render(CatalogusPage, { providers }); expect(getBeheerCatalogiZaaktypen).toHaveBeenCalled(); expect(await screen.findByText('BIG-REGISTRATIE')).toBeTruthy(); expect(screen.getByText('BIG-registratie')).toBeTruthy(); expect(screen.getByText('BIG-HERREGISTRATIE')).toBeTruthy(); }); it('shows an empty state when the catalogus has no published zaaktypen', async () => { const { providers } = setup({ getBeheerCatalogiZaaktypen: vi.fn().mockReturnValue(of([])) }); await render(CatalogusPage, { providers }); expect(await screen.findByText(/geen gepubliceerde zaaktypen/i)).toBeTruthy(); }); it('surfaces a load failure instead of swallowing it', async () => { const { providers } = setup({ getBeheerCatalogiZaaktypen: vi.fn().mockReturnValue(throwError(() => new Error('403'))), }); await render(CatalogusPage, { providers }); expect(await screen.findByText(/kon de catalogus niet laden/i)).toBeTruthy(); }); it('has no WCAG 2.1 AA violations', async () => { document.documentElement.lang = 'nl'; const { container } = await render(CatalogusPage, { providers: setup().providers }); const results = await axe(container, { runOnly: { type: 'tag', values: ['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa'] }, }); expect(results.violations).toEqual([]); }); });