Continuous Integration / check (pull_request) Successful in 1m57s
Continuous Integration / build-test (pull_request) Skipped
Continuous Integration / deploy-test (pull_request) Skipped
Continuous Integration / lighthouse (pull_request) Successful in 9m0s
Continuous Integration / deploy-production (pull_request) Skipped
The plain HTML is painted at scale 1.06 and the slider zooms it out to 1 after hydration, like the other photos: same first frame (no CLS), and the LCP does not wait for hydration. Assumptions 15 and 16 recorded. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
168 lines
6.7 KiB
TypeScript
168 lines
6.7 KiB
TypeScript
import { fireEvent, screen, waitFor } from '@testing-library/react';
|
|
import userEvent from '@testing-library/user-event';
|
|
import { describe, expect, it } from 'vitest';
|
|
import heroContent from '@/content/heroContent';
|
|
import siteContent from '@/content/siteContent';
|
|
import { axeResults } from '@/test/axe';
|
|
import { renderWithProviders } from '@/test/renderWithProviders';
|
|
import Hero from './Hero';
|
|
|
|
describe('Hero', () => {
|
|
it('toont alleen geldige socials, met melding over het nieuwe tabblad', async () => {
|
|
const { container } = await renderWithProviders(
|
|
<Hero
|
|
content={heroContent}
|
|
socials={[
|
|
...siteContent.socials,
|
|
{ platform: 'facebook', href: 'javascript:alert(1)' },
|
|
]}
|
|
/>,
|
|
);
|
|
const links = screen.getAllByRole('link', {
|
|
name: /opent in nieuw tabblad/,
|
|
});
|
|
// In content order: Instagram, then Facebook
|
|
expect(links).toHaveLength(2);
|
|
expect(links[0]).toHaveAccessibleName(
|
|
'Instagram (opent in nieuw tabblad)',
|
|
);
|
|
expect(links[1]).toHaveAccessibleName(
|
|
'Facebook (opent in nieuw tabblad)',
|
|
);
|
|
expect(links[0]).toHaveAttribute('rel', 'noopener noreferrer');
|
|
expect(await axeResults(container)).toHaveNoViolations();
|
|
});
|
|
|
|
it('laadt eerst de eerste foto, daarna alleen de volgende en vorige', async () => {
|
|
const { container } = await renderWithProviders(
|
|
<Hero content={heroContent} socials={siteContent.socials} />,
|
|
);
|
|
const sources = () =>
|
|
[...container.querySelectorAll('img')].map((img) =>
|
|
img.getAttribute('src'),
|
|
);
|
|
const slide = (i: number) => heroContent.slides[i].image.src;
|
|
const last = heroContent.slides.length - 1;
|
|
|
|
expect(sources()).toEqual([slide(0)]);
|
|
fireEvent.load(container.querySelector('img')!);
|
|
// Vanaf de eerste foto is de vorige de laatste
|
|
await waitFor(() =>
|
|
expect(sources()).toEqual([slide(0), slide(1), slide(last)]),
|
|
);
|
|
|
|
await userEvent.click(
|
|
screen.getByRole('button', { name: 'Volgende foto' }),
|
|
);
|
|
expect(sources()).toEqual([slide(0), slide(1), slide(2)]);
|
|
});
|
|
|
|
describe('meldingen voor schermlezers', () => {
|
|
const announcement = () =>
|
|
screen.getByTestId('hero-announcement').textContent;
|
|
|
|
it('meldt een wissel door de bezoeker met nummer en beschrijving', async () => {
|
|
await renderWithProviders(
|
|
<Hero content={heroContent} socials={siteContent.socials} />,
|
|
);
|
|
const region = screen.getByTestId('hero-announcement');
|
|
expect(region).toHaveAttribute('aria-live', 'polite');
|
|
expect(announcement()).toBe('');
|
|
|
|
await userEvent.click(
|
|
screen.getByRole('button', { name: 'Volgende foto' }),
|
|
);
|
|
expect(announcement()).toBe(
|
|
`Foto 2 van ${heroContent.slides.length}: ${heroContent.slides[1].alt}`,
|
|
);
|
|
|
|
await userEvent.click(
|
|
screen.getByRole('button', { name: 'Vorige foto' }),
|
|
);
|
|
expect(announcement()).toBe(
|
|
`Foto 1 van ${heroContent.slides.length}: ${heroContent.slides[0].alt}`,
|
|
);
|
|
});
|
|
|
|
// Stil blijven bij een automatische wissel: zie useHeroSlider.test.tsx
|
|
// (jsdom kent geen animationend voor React)
|
|
});
|
|
|
|
describe('pauzeknop', () => {
|
|
it('pauzeert en hervat de diavoorstelling', async () => {
|
|
const { container } = await renderWithProviders(
|
|
<Hero content={heroContent} socials={siteContent.socials} />,
|
|
);
|
|
const pause = screen.getByRole('button', {
|
|
name: 'Diavoorstelling pauzeren',
|
|
});
|
|
const progress = () => screen.getByTestId('hero-progress');
|
|
expect(progress()).toHaveAttribute('data-state', 'running');
|
|
|
|
await userEvent.click(pause);
|
|
expect(pause).toHaveAccessibleName('Diavoorstelling afspelen');
|
|
expect(screen.getByTestId('hero-announcement')).toHaveTextContent(
|
|
'Diavoorstelling gepauzeerd',
|
|
);
|
|
expect(progress()).toHaveAttribute('data-state', 'paused');
|
|
|
|
// Blijft gepauzeerd als de muis de hero verlaat
|
|
fireEvent.pointerLeave(container.querySelector('section')!);
|
|
expect(progress()).toHaveAttribute('data-state', 'paused');
|
|
|
|
await userEvent.click(pause);
|
|
expect(pause).toHaveAccessibleName('Diavoorstelling pauzeren');
|
|
expect(screen.getByTestId('hero-announcement')).toHaveTextContent(
|
|
'Diavoorstelling speelt weer af',
|
|
);
|
|
expect(progress()).toHaveAttribute('data-state', 'running');
|
|
expect(await axeResults(container)).toHaveNoViolations();
|
|
});
|
|
|
|
it('ontbreekt als er niets automatisch wisselt', async () => {
|
|
await renderWithProviders(
|
|
<Hero
|
|
content={{
|
|
...heroContent,
|
|
slides: heroContent.slides.slice(0, 1),
|
|
}}
|
|
socials={siteContent.socials}
|
|
/>,
|
|
);
|
|
expect(
|
|
screen.queryByRole('button', { name: /Diavoorstelling/ }),
|
|
).not.toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
it('laat de eerste foto inzoomen zolang hij de actieve is', async () => {
|
|
const { container } = await renderWithProviders(
|
|
<Hero content={heroContent} socials={siteContent.socials} />,
|
|
);
|
|
const picture = container.querySelector('.cms-hero-picture')!;
|
|
expect(picture).toHaveAttribute('data-zoom');
|
|
expect(picture).not.toHaveAttribute('aria-hidden');
|
|
await userEvent.click(
|
|
screen.getByRole('button', { name: 'Volgende foto' }),
|
|
);
|
|
expect(picture).not.toHaveAttribute('data-zoom');
|
|
expect(picture).toHaveAttribute('aria-hidden', 'true');
|
|
await userEvent.click(
|
|
screen.getByRole('button', { name: 'Vorige foto' }),
|
|
);
|
|
expect(picture).toHaveAttribute('data-zoom');
|
|
});
|
|
|
|
it('heeft pijlen met een toegankelijke naam', async () => {
|
|
await renderWithProviders(
|
|
<Hero content={heroContent} socials={siteContent.socials} />,
|
|
);
|
|
expect(
|
|
screen.getByRole('button', { name: 'Vorige foto' }),
|
|
).toBeInTheDocument();
|
|
expect(
|
|
screen.getByRole('button', { name: 'Volgende foto' }),
|
|
).toBeInTheDocument();
|
|
});
|
|
});
|