The prerendered hero is plain HTML between the markers (first photo, h1, buttons), the slider takes over after hydration with the hero of the host block, the API or the build. The head preload is added to the finished HTML. Hero texts move into nl.json. The stand-in host and the e2e tests cover the hero. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
150 lines
5.9 KiB
TypeScript
150 lines
5.9 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('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();
|
|
});
|
|
});
|