Adds the Instagram section to the homepage
Shows the handle as a link to the profile and six square photos from edge to edge (2, 3 or 6 per row), each linking to the profile in a new tab. The photos are ones the page already loads, so the section adds no downloads; the API will later fill it with the real feed. Without a valid https link to Instagram the section is left out. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
import { screen, within } from '@testing-library/react';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import homeContent from '@/content/homeContent';
|
||||
import { axeResults } from '@/test/axe';
|
||||
import { renderWithProviders } from '@/test/renderWithProviders';
|
||||
import InstagramGrid from './InstagramGrid';
|
||||
|
||||
const instagram = homeContent.instagram;
|
||||
const PROFILE = 'https://www.instagram.com/andreaslopfotografie/';
|
||||
|
||||
function expectExternal(link: HTMLElement) {
|
||||
expect(link).toHaveAttribute('href', PROFILE);
|
||||
expect(link).toHaveAttribute('target', '_blank');
|
||||
expect(link).toHaveAttribute('rel', 'noopener noreferrer');
|
||||
}
|
||||
|
||||
describe('InstagramGrid', () => {
|
||||
it('shows the heading and the handle as a link to the profile', async () => {
|
||||
const { container } = await renderWithProviders(
|
||||
<InstagramGrid content={instagram} profileUrl={PROFILE} />,
|
||||
);
|
||||
const section = screen.getByRole('region', { name: 'Instagram' });
|
||||
expect(
|
||||
within(section).getByRole('heading', { level: 2 }),
|
||||
).toHaveTextContent('Instagram');
|
||||
const handle = screen.getByTestId('instagram-handle-link');
|
||||
expect(handle).toHaveAccessibleName(
|
||||
'@andreaslopfotografie (opent in nieuw tabblad)',
|
||||
);
|
||||
expectExternal(handle);
|
||||
expect(await axeResults(container)).toHaveNoViolations();
|
||||
});
|
||||
|
||||
it('shows six photo tiles in order, each linking to the profile', async () => {
|
||||
await renderWithProviders(
|
||||
<InstagramGrid content={instagram} profileUrl={PROFILE} />,
|
||||
);
|
||||
const items = within(screen.getByRole('list')).getAllByRole('listitem');
|
||||
expect(items).toHaveLength(6);
|
||||
instagram.photos.forEach((photo, index) => {
|
||||
const tile = screen.getByTestId(`instagram-tile-${index + 1}`);
|
||||
expect(items[index]).toContainElement(tile);
|
||||
expectExternal(tile);
|
||||
expect(tile).toHaveAccessibleName(
|
||||
`${photo.alt} (Instagram, opent in nieuw tabblad)`,
|
||||
);
|
||||
const image = within(tile).getByRole('img');
|
||||
expect(image).toHaveAttribute('loading', 'lazy');
|
||||
expect(image).toHaveAttribute('width', String(photo.width));
|
||||
});
|
||||
});
|
||||
|
||||
it('still renders the heading and handle when there are no photos', async () => {
|
||||
await renderWithProviders(
|
||||
<InstagramGrid
|
||||
content={{ ...instagram, photos: [] }}
|
||||
profileUrl={PROFILE}
|
||||
/>,
|
||||
);
|
||||
expect(
|
||||
screen.getByRole('heading', { name: 'Instagram' }),
|
||||
).toBeInTheDocument();
|
||||
expect(screen.getByTestId('instagram-handle-link')).toBeInTheDocument();
|
||||
expect(screen.queryAllByRole('img')).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,117 @@
|
||||
import { Box, chakra, Container, Link, VisuallyHidden } from '@chakra-ui/react';
|
||||
import DeferredImage from '@/components/DeferredImage/DeferredImage';
|
||||
import HomeSection from '@/components/HomeSection/HomeSection';
|
||||
import Reveal from '@/components/Reveal/Reveal';
|
||||
import SectionHeading from '@/components/SectionHeading/SectionHeading';
|
||||
import type { HomeContent } from '@/content/types';
|
||||
|
||||
const TITLE_ID = 'instagram-title';
|
||||
|
||||
type InstagramGridProps = {
|
||||
content: HomeContent['instagram'];
|
||||
// A checked https link (visibleSocials); without one the route leaves
|
||||
// the section out
|
||||
profileUrl: string;
|
||||
};
|
||||
|
||||
// "Instagram" (design .instagram): the handle as a link to the profile and
|
||||
// a row of square photos running from edge to edge, each linking to the
|
||||
// profile too. A fixed selection until the API delivers the real feed.
|
||||
export default function InstagramGrid({
|
||||
content,
|
||||
profileUrl,
|
||||
}: InstagramGridProps) {
|
||||
return (
|
||||
<HomeSection
|
||||
labelledBy={TITLE_ID}
|
||||
spacing="tight"
|
||||
width="full"
|
||||
data-testid="instagram-grid"
|
||||
>
|
||||
<Container maxW="content">
|
||||
<Reveal>
|
||||
<SectionHeading
|
||||
id={TITLE_ID}
|
||||
title={content.title}
|
||||
lead={
|
||||
<Link
|
||||
variant="underline"
|
||||
href={profileUrl}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
data-testid="instagram-handle-link"
|
||||
>
|
||||
{/* Space outside the hidden text, or it drops
|
||||
out of the announced name */}
|
||||
{content.handle}{' '}
|
||||
<VisuallyHidden>
|
||||
(opent in nieuw tabblad)
|
||||
</VisuallyHidden>
|
||||
</Link>
|
||||
}
|
||||
/>
|
||||
</Reveal>
|
||||
</Container>
|
||||
<Reveal>
|
||||
{/* The design's 680px and 1100px steps on the theme breakpoints */}
|
||||
<chakra.ul
|
||||
listStyleType="none"
|
||||
display="grid"
|
||||
gridTemplateColumns={{
|
||||
base: 'repeat(2, 1fr)',
|
||||
md: 'repeat(3, 1fr)',
|
||||
xl: 'repeat(6, 1fr)',
|
||||
}}
|
||||
gap="2px"
|
||||
>
|
||||
{content.photos.map((photo, i) => (
|
||||
// The same photo may appear twice in a feed
|
||||
<chakra.li key={`${i}-${photo.src}`}>
|
||||
<chakra.a
|
||||
href={profileUrl}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
data-testid={`instagram-tile-${i + 1}`}
|
||||
display="block"
|
||||
position="relative"
|
||||
// Keeps the focus ring above the neighbouring
|
||||
// tiles, which sit only 2px away
|
||||
_focusVisible={{ zIndex: 1 }}
|
||||
className="group"
|
||||
>
|
||||
<Box overflow="hidden" bg="paper.deep">
|
||||
<DeferredImage
|
||||
image={photo}
|
||||
w="100%"
|
||||
aspectRatio="1 / 1"
|
||||
objectFit="cover"
|
||||
transitionProperty="transform, opacity"
|
||||
transitionDuration="interaction"
|
||||
transitionTimingFunction="smooth"
|
||||
_groupHover={{
|
||||
transform: 'scale(1.06)',
|
||||
opacity: 0.85,
|
||||
}}
|
||||
_groupFocusVisible={{
|
||||
transform: 'scale(1.06)',
|
||||
opacity: 0.85,
|
||||
}}
|
||||
// Only the fade, no zoom
|
||||
_motionReduce={{
|
||||
transform: 'none !important',
|
||||
}}
|
||||
/>
|
||||
</Box>
|
||||
{/* The photo's alt names the link; this says
|
||||
where it goes */}{' '}
|
||||
<VisuallyHidden>
|
||||
(Instagram, opent in nieuw tabblad)
|
||||
</VisuallyHidden>
|
||||
</chakra.a>
|
||||
</chakra.li>
|
||||
))}
|
||||
</chakra.ul>
|
||||
</Reveal>
|
||||
</HomeSection>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user