Extends the shared blocks for the shoot types page
FramedImage and MediaText take a colour for the block behind the photo (sand by default) and MediaText can put the photo in the right-hand column from lg, without changing the reading order. RichParagraph moves to the shared components, a new CallToAction closes a page with a heading, lead and action, and the homepage pricing section gets the anchor #prijzen. A test helper reads the generated CSS rules, since jsdom applies neither media queries nor pseudo-elements. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
import { screen } from '@testing-library/react';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import LinkButton from '@/components/LinkButton';
|
||||
import RichParagraph from '@/components/RichParagraph/RichParagraph';
|
||||
import { axeResults } from '@/test/axe';
|
||||
import { renderWithProviders } from '@/test/renderWithProviders';
|
||||
import CallToAction from './CallToAction';
|
||||
|
||||
describe('CallToAction', () => {
|
||||
it('is a section named by its heading, with the lead and the action', async () => {
|
||||
const { container } = await renderWithProviders(
|
||||
<CallToAction
|
||||
title="Benieuwd naar de prijzen?"
|
||||
titleId="cta-title"
|
||||
lead={
|
||||
<RichParagraph
|
||||
paragraph={[
|
||||
'Bekijk ',
|
||||
{ text: 'de pakketten', to: '/', hash: 'prijzen' },
|
||||
' op de homepage.',
|
||||
]}
|
||||
/>
|
||||
}
|
||||
data-testid="cta"
|
||||
>
|
||||
<LinkButton variant="accent" to="/" hash="contact">
|
||||
Boek je shoot
|
||||
</LinkButton>
|
||||
</CallToAction>,
|
||||
);
|
||||
|
||||
const section = screen.getByRole('region', {
|
||||
name: 'Benieuwd naar de prijzen?',
|
||||
});
|
||||
expect(section).toBe(screen.getByTestId('cta'));
|
||||
expect(screen.getByRole('heading', { level: 2 })).toHaveAccessibleName(
|
||||
'Benieuwd naar de prijzen?',
|
||||
);
|
||||
expect(
|
||||
screen.getByRole('link', { name: 'de pakketten' }),
|
||||
).toHaveAttribute('href', '/#prijzen');
|
||||
expect(
|
||||
screen.getByRole('link', { name: 'Boek je shoot' }),
|
||||
).toHaveAttribute('href', '/#contact');
|
||||
expect(await axeResults(container)).toHaveNoViolations();
|
||||
});
|
||||
|
||||
it('wraps a plain-text lead in a paragraph', async () => {
|
||||
await renderWithProviders(
|
||||
<CallToAction
|
||||
title="Vragen?"
|
||||
titleId="q"
|
||||
lead="Stuur me een bericht."
|
||||
>
|
||||
<LinkButton to="/">Contact</LinkButton>
|
||||
</CallToAction>,
|
||||
);
|
||||
expect(screen.getByText('Stuur me een bericht.').tagName).toBe('P');
|
||||
});
|
||||
|
||||
it('leaves out the lead when there is none', async () => {
|
||||
await renderWithProviders(
|
||||
<CallToAction title="Vragen?" titleId="q">
|
||||
<LinkButton to="/">Contact</LinkButton>
|
||||
</CallToAction>,
|
||||
);
|
||||
expect(screen.queryByRole('paragraph')).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,50 @@
|
||||
import type { ReactNode } from 'react';
|
||||
import { Box, Heading, Text } from '@chakra-ui/react';
|
||||
import PageSection from '@/components/PageSection/PageSection';
|
||||
import Reveal from '@/components/Reveal/Reveal';
|
||||
|
||||
type CallToActionProps = {
|
||||
title: string;
|
||||
// Id of the h2, which names the section
|
||||
titleId: string;
|
||||
// Plain text, or a paragraph with links in it (e.g. RichParagraph)
|
||||
lead?: ReactNode;
|
||||
'data-testid'?: string;
|
||||
// The action below the text, e.g. a LinkButton
|
||||
children: ReactNode;
|
||||
};
|
||||
|
||||
// Closing block of a page (design .section--alt.section--tight with a narrow,
|
||||
// centred column): a heading, a short lead and one action. The page chooses
|
||||
// the action and any link in the lead.
|
||||
export default function CallToAction({
|
||||
title,
|
||||
titleId,
|
||||
lead,
|
||||
'data-testid': testId,
|
||||
children,
|
||||
}: CallToActionProps) {
|
||||
return (
|
||||
<PageSection
|
||||
labelledBy={titleId}
|
||||
tone="alt"
|
||||
width="narrow"
|
||||
spacing="tight"
|
||||
data-testid={testId}
|
||||
>
|
||||
<Reveal textAlign="center">
|
||||
<Heading as="h2" id={titleId} textStyle="sectionTitle">
|
||||
{title}
|
||||
</Heading>
|
||||
{lead && (
|
||||
// design .lead.mt-sm
|
||||
<Box textStyle="lead" color="ink.soft" mt={4}>
|
||||
{typeof lead === 'string' ? <Text>{lead}</Text> : lead}
|
||||
</Box>
|
||||
)}
|
||||
{/* design .mt-lg */}
|
||||
<Box mt="clamp(2rem, 4vw, 2.5rem)">{children}</Box>
|
||||
</Reveal>
|
||||
</PageSection>
|
||||
);
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { screen } from '@testing-library/react';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { axeResults } from '@/test/axe';
|
||||
import { cssRulesFor } from '@/test/cssRules';
|
||||
import { renderWithProviders } from '@/test/renderWithProviders';
|
||||
import FramedImage from './FramedImage';
|
||||
|
||||
@@ -35,4 +36,32 @@ describe('FramedImage', () => {
|
||||
expect(img).toHaveAttribute('fetchpriority', 'high');
|
||||
expect(img).toHaveAttribute('width', '1200');
|
||||
});
|
||||
|
||||
// The block is a ::before on the photo's wrapper
|
||||
const frameRule = (img: Element) =>
|
||||
cssRulesFor(img.parentElement!).find((rule) =>
|
||||
rule.includes('::before {'),
|
||||
);
|
||||
|
||||
it('puts a sand block behind the photo by default', async () => {
|
||||
await renderWithProviders(
|
||||
<FramedImage image={image} aspectRatio="4 / 3" />,
|
||||
);
|
||||
expect(frameRule(screen.getByRole('img'))).toContain(
|
||||
'background: var(--slp-colors-sand)',
|
||||
);
|
||||
});
|
||||
|
||||
it('colours the block with the given token', async () => {
|
||||
await renderWithProviders(
|
||||
<FramedImage
|
||||
image={image}
|
||||
aspectRatio="4 / 5"
|
||||
frameColor="frame.rust"
|
||||
/>,
|
||||
);
|
||||
expect(frameRule(screen.getByRole('img'))).toContain(
|
||||
'background: var(--slp-colors-frame-rust)',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Box, Image, type ImageProps } from '@chakra-ui/react';
|
||||
import DeferredImage from '@/components/DeferredImage/DeferredImage';
|
||||
import type { ContentImage } from '@/content/types';
|
||||
import type { ContentImage, FrameColor } from '@/content/types';
|
||||
|
||||
type FramedImageProps = {
|
||||
image: ContentImage;
|
||||
@@ -9,16 +9,19 @@ type FramedImageProps = {
|
||||
// For a photo at the top of a page, likely the largest paint: load it
|
||||
// straight away with high priority instead of after the page has loaded
|
||||
priority?: boolean;
|
||||
// Colour token of the block behind the photo
|
||||
frameColor?: FrameColor;
|
||||
};
|
||||
|
||||
// A photo with a soft sand-coloured block offset behind its lower left
|
||||
// corner (design .about__media). The block is pure decoration (a CSS
|
||||
// pseudo-element), so assistive technology never announces it. On phones it
|
||||
// is left out, since it would stick out past the page edge.
|
||||
// A photo with a soft coloured block (sand by default) offset behind its
|
||||
// lower left corner (design .about__media). The block is pure decoration (a
|
||||
// CSS pseudo-element), so assistive technology never announces it. On phones
|
||||
// it is left out, since it would stick out past the page edge.
|
||||
export default function FramedImage({
|
||||
image,
|
||||
aspectRatio,
|
||||
priority = false,
|
||||
frameColor = 'sand',
|
||||
}: FramedImageProps) {
|
||||
const style: ImageProps = {
|
||||
display: 'block',
|
||||
@@ -43,7 +46,7 @@ export default function FramedImage({
|
||||
bottom: '-1.5rem',
|
||||
width: '55%',
|
||||
height: '55%',
|
||||
bg: 'sand',
|
||||
bg: frameColor,
|
||||
zIndex: -1,
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -2,6 +2,7 @@ import { screen } from '@testing-library/react';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import type { ContentImage } from '@/content/types';
|
||||
import { axeResults } from '@/test/axe';
|
||||
import { cssRulesFor } from '@/test/cssRules';
|
||||
import { renderWithProviders } from '@/test/renderWithProviders';
|
||||
import MediaText from './MediaText';
|
||||
|
||||
@@ -43,4 +44,44 @@ describe('MediaText', () => {
|
||||
Node.DOCUMENT_POSITION_FOLLOWING,
|
||||
).toBeTruthy();
|
||||
});
|
||||
|
||||
const photoColumnRules = () =>
|
||||
cssRulesFor(screen.getByRole('img').closest('[data-reveal]')!);
|
||||
|
||||
it('keeps the photo in the first column by default', async () => {
|
||||
await renderWithProviders(
|
||||
<MediaText image={image} aspectRatio="4 / 3">
|
||||
<h2>Hoi! Ik ben Andrea</h2>
|
||||
</MediaText>,
|
||||
);
|
||||
expect(photoColumnRules().join()).not.toContain('order');
|
||||
});
|
||||
|
||||
it('moves the photo to the second column from lg when reversed, without changing the reading order', async () => {
|
||||
await renderWithProviders(
|
||||
<MediaText image={image} aspectRatio="4 / 5" reverse>
|
||||
<h2>Newborn</h2>
|
||||
</MediaText>,
|
||||
);
|
||||
expect(photoColumnRules()).toContainEqual(
|
||||
expect.stringMatching(/min-width: 64rem.*order: 2;/),
|
||||
);
|
||||
const photo = screen.getByRole('img');
|
||||
const heading = screen.getByRole('heading');
|
||||
expect(
|
||||
photo.compareDocumentPosition(heading) &
|
||||
Node.DOCUMENT_POSITION_FOLLOWING,
|
||||
).toBeTruthy();
|
||||
});
|
||||
|
||||
it('passes the frame colour on to the photo', async () => {
|
||||
await renderWithProviders(
|
||||
<MediaText image={image} aspectRatio="4 / 5" frameColor="accent">
|
||||
<h2>Gezin</h2>
|
||||
</MediaText>,
|
||||
);
|
||||
expect(
|
||||
cssRulesFor(screen.getByRole('img').parentElement!).join(),
|
||||
).toContain('var(--slp-colors-accent)');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { ReactNode } from 'react';
|
||||
import { Grid } from '@chakra-ui/react';
|
||||
import FramedImage from '@/components/FramedImage/FramedImage';
|
||||
import Reveal from '@/components/Reveal/Reveal';
|
||||
import type { ContentImage } from '@/content/types';
|
||||
import type { ContentImage, FrameColor } from '@/content/types';
|
||||
|
||||
type MediaTextProps = {
|
||||
image: ContentImage;
|
||||
@@ -10,18 +10,25 @@ type MediaTextProps = {
|
||||
aspectRatio: string;
|
||||
// The photo is at the top of the page and should not wait (FramedImage)
|
||||
priority?: boolean;
|
||||
// Photo in the right-hand column from `lg` (design .about--reverse).
|
||||
// Only the visual order changes: the photo stays first in the DOM.
|
||||
reverse?: boolean;
|
||||
// Colour of the block behind the photo (FramedImage)
|
||||
frameColor?: FrameColor;
|
||||
'data-testid'?: string;
|
||||
// The text column; each page fills in its own heading and text
|
||||
children: ReactNode;
|
||||
};
|
||||
|
||||
// A framed photo next to a text column (design .about), used on the
|
||||
// homepage and the about page. Stacked on phones and tablets, two equal
|
||||
// columns from `lg`; both columns fade in on scroll.
|
||||
// homepage, the about page and the shoot types page. Stacked on phones and
|
||||
// tablets, two equal columns from `lg`; both columns fade in on scroll.
|
||||
export default function MediaText({
|
||||
image,
|
||||
aspectRatio,
|
||||
priority,
|
||||
reverse = false,
|
||||
frameColor,
|
||||
'data-testid': testId,
|
||||
children,
|
||||
}: MediaTextProps) {
|
||||
@@ -32,11 +39,12 @@ export default function MediaText({
|
||||
alignItems="center"
|
||||
data-testid={testId}
|
||||
>
|
||||
<Reveal>
|
||||
<Reveal order={reverse ? { lg: 2 } : undefined}>
|
||||
<FramedImage
|
||||
image={image}
|
||||
aspectRatio={aspectRatio}
|
||||
priority={priority}
|
||||
frameColor={frameColor}
|
||||
/>
|
||||
</Reveal>
|
||||
<Reveal>{children}</Reveal>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Stack } from '@chakra-ui/react';
|
||||
import RichParagraph from '@/components/about/RichParagraph/RichParagraph';
|
||||
import RichParagraph from '@/components/RichParagraph/RichParagraph';
|
||||
import MediaText from '@/components/MediaText/MediaText';
|
||||
import PageSection from '@/components/PageSection/PageSection';
|
||||
import SectionHeading from '@/components/SectionHeading/SectionHeading';
|
||||
|
||||
@@ -32,6 +32,16 @@ describe('Pricing', () => {
|
||||
expect(await axeResults(container)).toHaveNoViolations();
|
||||
});
|
||||
|
||||
it('can be linked to as /#prijzen', async () => {
|
||||
await renderWithProviders(
|
||||
<Pricing content={content} packages={packages} />,
|
||||
);
|
||||
expect(screen.getByRole('region', { name: 'Prijzen' })).toHaveAttribute(
|
||||
'id',
|
||||
'prijzen',
|
||||
);
|
||||
});
|
||||
|
||||
it('keeps the decorations away from assistive technology', async () => {
|
||||
const { container } = await renderWithProviders(
|
||||
<Pricing content={content} packages={packages} />,
|
||||
|
||||
@@ -32,7 +32,12 @@ export default function Pricing({ content, packages }: PricingProps) {
|
||||
if (shown.length === 0) return null;
|
||||
|
||||
return (
|
||||
<PageSection labelledBy={TITLE_ID} data-testid="pricing">
|
||||
<PageSection
|
||||
labelledBy={TITLE_ID}
|
||||
// Anchor for links such as "de pakketten" (/#prijzen)
|
||||
id="prijzen"
|
||||
data-testid="pricing"
|
||||
>
|
||||
<Box position="relative" isolation="isolate">
|
||||
{content.decorations.map((decoration, index) => (
|
||||
<DeferredImage
|
||||
|
||||
Reference in New Issue
Block a user