Redesigns the testimonials section
A landscape photo overlaps a card with the shoot type, quote and names. The controls are two arrows with an X / Y counter; the dots are gone and nothing moves by itself. A change slides the whole slide horizontally, also on a swipe. Reviews get an optional imagePosition for the crop, normalised by normalizeImagePosition; slideCounter writes the counter. Both helpers have property tests next to example tests. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -17,6 +17,8 @@ import Testimonials from './Testimonials';
|
||||
const carousel = vi.hoisted(() => ({
|
||||
props: undefined as UseCarouselProps | undefined,
|
||||
calls: [] as Array<[string, ...unknown[]]>,
|
||||
// Zag can not move in jsdom: a test sets the page the counter should show
|
||||
page: undefined as number | undefined,
|
||||
}));
|
||||
|
||||
vi.mock('@chakra-ui/react', async (importOriginal) => {
|
||||
@@ -34,6 +36,7 @@ vi.mock('@chakra-ui/react', async (importOriginal) => {
|
||||
};
|
||||
return {
|
||||
...api,
|
||||
page: carousel.page ?? api.page,
|
||||
scrollNext: record('scrollNext', api.scrollNext),
|
||||
scrollPrev: record('scrollPrev', api.scrollPrev),
|
||||
scrollTo: record('scrollTo', api.scrollTo),
|
||||
@@ -44,6 +47,7 @@ vi.mock('@chakra-ui/react', async (importOriginal) => {
|
||||
|
||||
beforeEach(() => {
|
||||
carousel.calls = [];
|
||||
carousel.page = undefined;
|
||||
vi.stubGlobal('IntersectionObserver', FakeIntersectionObserver);
|
||||
Element.prototype.scrollTo = () => {};
|
||||
});
|
||||
@@ -79,6 +83,7 @@ async function renderTestimonials(items = testimonials) {
|
||||
}
|
||||
|
||||
const status = () => screen.getByTestId('testimonials-status');
|
||||
const counter = () => screen.getByTestId('testimonials-counter');
|
||||
const button = (name: string) => screen.getByRole('button', { name });
|
||||
|
||||
const preferReducedMotion = () =>
|
||||
@@ -130,8 +135,6 @@ describe('Testimonials', () => {
|
||||
});
|
||||
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"]',
|
||||
);
|
||||
@@ -157,42 +160,73 @@ describe('Testimonials', () => {
|
||||
expect(status()).toHaveTextContent('Review 2 van 2');
|
||||
});
|
||||
|
||||
it('moves with the arrows, the dots and the arrow keys', async () => {
|
||||
it('moves with the arrows 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' });
|
||||
fireEvent.keyDown(button('Vorige review'), { key: 'ArrowRight' });
|
||||
fireEvent.keyDown(button('Volgende review'), { key: 'ArrowLeft' });
|
||||
fireEvent.keyDown(button('Volgende review'), { key: 'Enter' });
|
||||
expect(carousel.calls).toEqual([
|
||||
['scrollNext', false],
|
||||
['scrollPrev', false],
|
||||
['scrollTo', 1, false],
|
||||
['scrollNext', false],
|
||||
['scrollPrev', false],
|
||||
]);
|
||||
});
|
||||
|
||||
it('has no dots: only the two arrows and the counter', async () => {
|
||||
await renderTestimonials();
|
||||
expect(screen.getAllByRole('button').map((b) => b.ariaLabel)).toEqual([
|
||||
'Vorige review',
|
||||
'Volgende review',
|
||||
]);
|
||||
expect(screen.queryByTestId('testimonials-dot-1')).toBeNull();
|
||||
});
|
||||
|
||||
it('shows the counter as "X / Y" and keeps it away from assistive technology', async () => {
|
||||
await renderTestimonials();
|
||||
expect(counter()).toHaveTextContent('1 / 2');
|
||||
expect(counter()).toHaveAttribute('aria-hidden', 'true');
|
||||
|
||||
carousel.page = 1;
|
||||
act(() => {
|
||||
carousel.props?.onPageChange?.({ page: 1, pageSnapPoint: 0 });
|
||||
});
|
||||
expect(counter()).toHaveTextContent('2 / 2');
|
||||
// The announcement says the same thing aloud
|
||||
expect(status()).toHaveTextContent('Review 2 van 2');
|
||||
});
|
||||
|
||||
it('does not move by itself', async () => {
|
||||
await renderTestimonials();
|
||||
expect(carousel.props).not.toHaveProperty('autoplay');
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
expect(carousel.calls).toEqual([]);
|
||||
expect(status()).toHaveTextContent('');
|
||||
expect(
|
||||
screen.queryByRole('button', { name: /paus|afspel/i }),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
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' });
|
||||
fireEvent.keyDown(button('Vorige review'), { key: 'ArrowLeft' });
|
||||
expect(carousel.calls).toEqual([
|
||||
['scrollNext', true],
|
||||
['scrollTo', 0, true],
|
||||
['scrollPrev', true],
|
||||
]);
|
||||
});
|
||||
|
||||
it('shows a single review without carousel controls', async () => {
|
||||
it('shows a single review without carousel controls or counter', async () => {
|
||||
await renderTestimonials([testimonials[0]]);
|
||||
expect(
|
||||
screen.getByTestId(`testimonial-${testimonials[0].id}`),
|
||||
).toBeInTheDocument();
|
||||
expect(screen.queryByRole('button')).toBeNull();
|
||||
expect(screen.queryByTestId('testimonials-counter')).toBeNull();
|
||||
});
|
||||
|
||||
it('leaves the section out when no review is valid', async () => {
|
||||
|
||||
Reference in New Issue
Block a user