Shares the contact form, contact card and privacy line
ContactPanel holds the coming-soon gate, the shoot options, the package chosen via ?pakket= and the form, which loads as its own chunk either when it comes near the screen (homepage) or right away (contact page). ContactDetails shows the ways to reach Andrea as a card with icons. A privacy line now sits under the form and under the coming-soon notice, and the reply time in the thank-you comes from the site content. Instagram is listed before Facebook, so the footer and hero follow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
import { screen, within } from '@testing-library/react';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import siteContent from '@/content/siteContent';
|
||||
import { axeResults } from '@/test/axe';
|
||||
import { renderWithProviders } from '@/test/renderWithProviders';
|
||||
import ContactDetails from './ContactDetails';
|
||||
|
||||
type Props = Partial<React.ComponentProps<typeof ContactDetails>>;
|
||||
|
||||
const card = (props: Props = {}) => (
|
||||
<ContactDetails
|
||||
titleId="details-title"
|
||||
title="Direct contact"
|
||||
email={siteContent.email}
|
||||
socials={siteContent.socials}
|
||||
data-testid="details"
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
|
||||
const portrait = {
|
||||
src: '/portret.jpg',
|
||||
alt: 'Andrea',
|
||||
width: 144,
|
||||
height: 144,
|
||||
};
|
||||
|
||||
describe('ContactDetails', () => {
|
||||
it('lists e-mail, Instagram and Facebook under a named heading', async () => {
|
||||
const { container } = await renderWithProviders(card());
|
||||
expect(
|
||||
screen.getByRole('heading', { level: 2, name: 'Direct contact' }),
|
||||
).toHaveAttribute('id', 'details-title');
|
||||
const list = screen.getByRole('list', { name: 'Direct contact' });
|
||||
const names = within(list)
|
||||
.getAllByRole('link')
|
||||
.map((link) => link.textContent);
|
||||
expect(names).toEqual([
|
||||
'info@andreaslop.nl',
|
||||
'@andreaslopfotografie (opent in nieuw tabblad)',
|
||||
'Andrea Slop Fotografie (opent in nieuw tabblad)',
|
||||
]);
|
||||
expect(await axeResults(container)).toHaveNoViolations();
|
||||
});
|
||||
|
||||
it('mails with the default subject in the same tab', async () => {
|
||||
await renderWithProviders(card());
|
||||
const mail = screen.getByTestId('contact-details-email');
|
||||
expect(mail).toHaveAttribute(
|
||||
'href',
|
||||
'mailto:info@andreaslop.nl?subject=Vraag%20via%20andreaslop.nl',
|
||||
);
|
||||
expect(mail).not.toHaveAttribute('target');
|
||||
});
|
||||
|
||||
it('opens the socials safely in a new tab and says so', async () => {
|
||||
await renderWithProviders(card());
|
||||
const instagram = screen.getByRole('link', {
|
||||
name: '@andreaslopfotografie (opent in nieuw tabblad)',
|
||||
});
|
||||
expect(instagram).toHaveAttribute('target', '_blank');
|
||||
expect(instagram).toHaveAttribute('rel', 'noopener noreferrer');
|
||||
expect(instagram).toHaveAttribute(
|
||||
'href',
|
||||
'https://www.instagram.com/andreaslopfotografie/',
|
||||
);
|
||||
});
|
||||
|
||||
it('hides the icons from assistive technology', async () => {
|
||||
await renderWithProviders(card());
|
||||
const icons = screen.getByTestId('details').querySelectorAll('svg');
|
||||
expect(icons).toHaveLength(3);
|
||||
icons.forEach((icon) =>
|
||||
expect(icon).toHaveAttribute('aria-hidden', 'true'),
|
||||
);
|
||||
});
|
||||
|
||||
it('renders nothing without a valid channel', async () => {
|
||||
const { container } = await renderWithProviders(
|
||||
card({ email: { user: '', domain: '' }, socials: [] }),
|
||||
);
|
||||
expect(screen.queryByTestId('details')).toBeNull();
|
||||
expect(container.querySelector('h2')).toBeNull();
|
||||
});
|
||||
|
||||
it('shows the portrait as decoration next to the heading', async () => {
|
||||
const { container } = await renderWithProviders(card({ portrait }));
|
||||
const photo = screen.getByTestId('contact-details-portrait');
|
||||
expect(photo).toHaveAttribute('src', '/portret.jpg');
|
||||
expect(photo).toHaveAttribute('alt', '');
|
||||
expect(await axeResults(container)).toHaveNoViolations();
|
||||
});
|
||||
|
||||
it('can appear twice on a page with its own heading ids', async () => {
|
||||
const { container } = await renderWithProviders(
|
||||
<>
|
||||
{card({ titleId: 'details-a', 'data-testid': 'a' })}
|
||||
{card({ titleId: 'details-b', 'data-testid': 'b' })}
|
||||
</>,
|
||||
);
|
||||
expect(
|
||||
screen.getAllByRole('list', { name: 'Direct contact' }),
|
||||
).toHaveLength(2);
|
||||
expect(await axeResults(container)).toHaveNoViolations();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,118 @@
|
||||
import {
|
||||
Box,
|
||||
chakra,
|
||||
Flex,
|
||||
Image,
|
||||
Link,
|
||||
VisuallyHidden,
|
||||
} from '@chakra-ui/react';
|
||||
import mailOutlined from '@iconify-icons/ant-design/mail-outlined';
|
||||
import { Icon } from '@iconify/react/offline';
|
||||
import Eyebrow from '@/components/Eyebrow/Eyebrow';
|
||||
import socialPlatforms from '@/content/socialPlatforms';
|
||||
import type { ContentImage, EmailAddress, SocialLink } from '@/content/types';
|
||||
import { contactChannels, type ContactChannel } from '@/lib/contactChannels';
|
||||
|
||||
type ContactDetailsProps = {
|
||||
// Id of the h2, unique on the page: the card can appear twice
|
||||
titleId: string;
|
||||
title: string;
|
||||
email: EmailAddress;
|
||||
socials: SocialLink[];
|
||||
// Small round photo next to the heading; decorative, the heading and
|
||||
// the page already say whose card it is
|
||||
portrait?: ContentImage;
|
||||
'data-testid'?: string;
|
||||
};
|
||||
|
||||
const iconOf = (channel: ContactChannel) =>
|
||||
channel.kind === 'email'
|
||||
? mailOutlined
|
||||
: socialPlatforms[channel.platform].icon;
|
||||
|
||||
// "Direct contact": a card with the ways to reach Andrea, each an icon and a
|
||||
// link (BR-CD-01..08). Renders nothing when no channel is valid.
|
||||
export default function ContactDetails({
|
||||
titleId,
|
||||
title,
|
||||
email,
|
||||
socials,
|
||||
portrait,
|
||||
'data-testid': testId,
|
||||
}: ContactDetailsProps) {
|
||||
const channels = contactChannels(email, socials);
|
||||
if (channels.length === 0) return null;
|
||||
|
||||
return (
|
||||
<Box
|
||||
bg="white"
|
||||
borderWidth="1px"
|
||||
borderColor="line"
|
||||
boxShadow="panel"
|
||||
p={{ base: 6, md: 8 }}
|
||||
data-testid={testId}
|
||||
>
|
||||
<Flex align="center" gap={4} mb={3}>
|
||||
{portrait && (
|
||||
<Image
|
||||
src={portrait.src}
|
||||
alt=""
|
||||
htmlWidth={portrait.width}
|
||||
htmlHeight={portrait.height}
|
||||
boxSize="72px"
|
||||
rounded="full"
|
||||
objectFit="cover"
|
||||
flexShrink={0}
|
||||
data-testid="contact-details-portrait"
|
||||
/>
|
||||
)}
|
||||
<Eyebrow as="h2" id={titleId} mb={0}>
|
||||
{title}
|
||||
</Eyebrow>
|
||||
</Flex>
|
||||
<chakra.ul listStyleType="none" aria-labelledby={titleId}>
|
||||
{channels.map((channel) => (
|
||||
<chakra.li key={channel.href}>
|
||||
<Link
|
||||
variant="subtle"
|
||||
href={channel.href}
|
||||
display="flex"
|
||||
alignItems="center"
|
||||
gap={4}
|
||||
minH="44px"
|
||||
{...(channel.external && {
|
||||
target: '_blank',
|
||||
rel: 'noopener noreferrer',
|
||||
})}
|
||||
data-testid={`contact-details-${
|
||||
channel.kind === 'email'
|
||||
? 'email'
|
||||
: channel.platform
|
||||
}`}
|
||||
>
|
||||
<Box
|
||||
as="span"
|
||||
color="accent.deep"
|
||||
fontSize="1.375rem"
|
||||
display="inline-flex"
|
||||
>
|
||||
<Icon icon={iconOf(channel)} aria-hidden />
|
||||
</Box>
|
||||
{/* Space outside the hidden text, or it drops out
|
||||
of the announced name */}
|
||||
{channel.label}
|
||||
{channel.external && (
|
||||
<>
|
||||
{' '}
|
||||
<VisuallyHidden>
|
||||
(opent in nieuw tabblad)
|
||||
</VisuallyHidden>
|
||||
</>
|
||||
)}
|
||||
</Link>
|
||||
</chakra.li>
|
||||
))}
|
||||
</chakra.ul>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user