Adds the Lieve woorden section to the homepage

Shows client reviews one at a time with the framed photo, a large
quotation mark, the shoot type and the names. Uses Chakra's carousel for
paging, looping and swiping with our own controls, so visitors who
prefer reduced motion get instant changes, and loads the carousel only
when the section comes near the screen so the hero does not wait for it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-20 01:52:41 +02:00
co-authored by Claude Opus 5.5
parent 30dab1af42
commit cb6a9b07f9
30 changed files with 1307 additions and 6 deletions
@@ -0,0 +1,198 @@
import { act, fireEvent, screen, within } from '@testing-library/react';
import type { UseCarouselProps } from '@chakra-ui/react';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import homeContent from '@/content/homeContent';
import testimonials from '@/content/testimonials';
import { axeResults } from '@/test/axe';
import { FakeIntersectionObserver } from '@/test/fakeIntersectionObserver';
import { renderWithProviders } from '@/test/renderWithProviders';
import { visibleTestimonials } from '@/lib/visibleTestimonials';
import Testimonials from './Testimonials';
// jsdom has no layout, so the carousel (Zag) cannot compute pages and
// cannot really move; paging, looping and swiping are Zag's own and are
// checked in a real browser (see the unit's code summary). These tests check
// our wiring: which API calls our controls make, and what is announced.
const carousel = vi.hoisted(() => ({
props: undefined as UseCarouselProps | undefined,
calls: [] as Array<[string, ...unknown[]]>,
}));
vi.mock('@chakra-ui/react', async (importOriginal) => {
const chakra = await importOriginal<typeof import('@chakra-ui/react')>();
return {
...chakra,
useCarousel: (props: UseCarouselProps) => {
const api = chakra.useCarousel(props);
carousel.props = props;
const record =
(name: string, real: (...args: never[]) => void) =>
(...args: unknown[]) => {
carousel.calls.push([name, ...args]);
(real as (...args: unknown[]) => void)(...args);
};
return {
...api,
scrollNext: record('scrollNext', api.scrollNext),
scrollPrev: record('scrollPrev', api.scrollPrev),
scrollTo: record('scrollTo', api.scrollTo),
};
},
};
});
beforeEach(() => {
carousel.calls = [];
vi.stubGlobal('IntersectionObserver', FakeIntersectionObserver);
Element.prototype.scrollTo = () => {};
});
afterEach(() => {
vi.unstubAllGlobals();
FakeIntersectionObserver.reset();
// @ts-expect-error -- jsdom has no Element.scrollTo of its own
delete Element.prototype.scrollTo;
});
const content = homeContent.testimonials;
// Renders the section and brings it into view, so the lazily loaded
// carousel appears
async function renderTestimonials(items = testimonials) {
const result = await renderWithProviders(
<Testimonials content={content} testimonials={items} />,
);
act(() => {
FakeIntersectionObserver.instances.forEach((observer) =>
observer.trigger(true),
);
});
if (visibleTestimonials(items).length > 1) {
await screen.findByRole('region', { name: 'Reviews' });
}
return result;
}
const status = () => screen.getByTestId('testimonials-status');
const button = (name: string) => screen.getByRole('button', { name });
const preferReducedMotion = () =>
vi.spyOn(window, 'matchMedia').mockImplementation(
(query: string) =>
({
matches: query.includes('reduce'),
media: query,
onchange: null,
addEventListener: () => {},
removeEventListener: () => {},
addListener: () => {},
removeListener: () => {},
dispatchEvent: () => false,
}) as MediaQueryList,
);
describe('Testimonials', () => {
it('shows the heading at once but loads the carousel only near the screen', async () => {
await renderWithProviders(
<Testimonials content={content} testimonials={testimonials} />,
);
expect(
screen.getByRole('region', { name: 'Lieve woorden' }),
).toBeInTheDocument();
expect(screen.queryByRole('region', { name: 'Reviews' })).toBeNull();
act(() => {
FakeIntersectionObserver.instances.forEach((observer) =>
observer.trigger(true),
);
});
expect(
await screen.findByRole('region', { name: 'Reviews' }),
).toBeInTheDocument();
});
it('shows a looping carousel of the reviews with Dutch labels', async () => {
const { container } = await renderTestimonials();
const section = screen.getByRole('region', { name: 'Lieve woorden' });
const region = within(section).getByRole('region', {
name: 'Reviews',
});
expect(region).toHaveAttribute('aria-roledescription', 'carrousel');
expect(carousel.props).toMatchObject({
slideCount: 2,
loop: true,
allowMouseDrag: true,
});
expect(button('Vorige review')).toBeInTheDocument();
expect(button('Volgende review')).toBeInTheDocument();
expect(button('Review 1')).toHaveAttribute('aria-current', 'true');
expect(button('Review 2')).not.toHaveAttribute('aria-current');
const slides = container.querySelectorAll(
'[aria-roledescription="slide"]',
);
expect(slides[0]).toHaveAttribute('aria-label', 'Review 1 van 2');
expect(slides[1]).toHaveAttribute('aria-label', 'Review 2 van 2');
expect(await axeResults(container)).toHaveNoViolations();
});
it('announces nothing on load and only through its own live region', async () => {
const { container } = await renderTestimonials();
expect(status()).toHaveTextContent('');
const live = [...container.querySelectorAll('[aria-live]')].filter(
(element) => element.getAttribute('aria-live') !== 'off',
);
expect(live).toEqual([status()]);
});
it('announces a page change as "Review n van m"', async () => {
await renderTestimonials();
act(() => {
carousel.props?.onPageChange?.({ page: 1, pageSnapPoint: 0 });
});
expect(status()).toHaveTextContent('Review 2 van 2');
});
it('moves with the arrows, the dots and the arrow keys', async () => {
await renderTestimonials();
fireEvent.click(button('Volgende review'));
fireEvent.click(button('Vorige review'));
fireEvent.click(button('Review 2'));
fireEvent.keyDown(button('Review 2'), { key: 'ArrowRight' });
fireEvent.keyDown(button('Review 2'), { key: 'ArrowLeft' });
fireEvent.keyDown(button('Review 2'), { key: 'Enter' });
expect(carousel.calls).toEqual([
['scrollNext', false],
['scrollPrev', false],
['scrollTo', 1, false],
['scrollNext', false],
['scrollPrev', false],
]);
});
it('scrolls instantly for visitors who prefer reduced motion', async () => {
preferReducedMotion();
await renderTestimonials();
fireEvent.click(button('Volgende review'));
fireEvent.click(button('Review 1'));
fireEvent.keyDown(button('Review 1'), { key: 'ArrowLeft' });
expect(carousel.calls).toEqual([
['scrollNext', true],
['scrollTo', 0, true],
['scrollPrev', true],
]);
});
it('shows a single review without carousel controls', async () => {
await renderTestimonials([testimonials[0]]);
expect(
screen.getByTestId(`testimonial-${testimonials[0].id}`),
).toBeInTheDocument();
expect(screen.queryByRole('button')).toBeNull();
});
it('leaves the section out when no review is valid', async () => {
await renderTestimonials([{ ...testimonials[0], quote: '' }]);
expect(
screen.queryByRole('region', { name: 'Lieve woorden' }),
).toBeNull();
});
});