Extracts shared section blocks for use beyond the homepage
HomeSection becomes PageSection, since every page needs the same section frame, and gains a flushTop spacing for a block right below a page head. The framed photo next to text from the homepage About block becomes MediaText, and the accent label that four components wrote out by hand becomes Eyebrow, which can also render as a heading. The homepage renders exactly as before: a layout comparison of every element against master at three widths shows no differences. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
import { screen } from '@testing-library/react';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { axeResults } from '@/test/axe';
|
||||
import { renderWithProviders } from '@/test/renderWithProviders';
|
||||
import PageSection from './PageSection';
|
||||
|
||||
describe('PageSection', () => {
|
||||
it('is a region named by its heading', async () => {
|
||||
const { container } = await renderWithProviders(
|
||||
<PageSection labelledBy="about-title" data-testid="about">
|
||||
<h2 id="about-title">Over mij</h2>
|
||||
</PageSection>,
|
||||
);
|
||||
expect(screen.getByRole('region', { name: 'Over mij' })).toBe(
|
||||
screen.getByTestId('about'),
|
||||
);
|
||||
expect(await axeResults(container)).toHaveNoViolations();
|
||||
});
|
||||
|
||||
it('passes the anchor id through for every tone, width and spacing', async () => {
|
||||
await renderWithProviders(
|
||||
<PageSection
|
||||
labelledBy="contact-title"
|
||||
id="contact"
|
||||
tone="alt"
|
||||
width="narrow"
|
||||
spacing="tight"
|
||||
>
|
||||
<h2 id="contact-title">Contact</h2>
|
||||
</PageSection>,
|
||||
);
|
||||
expect(screen.getByRole('region', { name: 'Contact' })).toHaveAttribute(
|
||||
'id',
|
||||
'contact',
|
||||
);
|
||||
});
|
||||
|
||||
it('has no space above when it sits flush below a page head', async () => {
|
||||
await renderWithProviders(
|
||||
<>
|
||||
<PageSection labelledBy="flush-title" data-testid="flush">
|
||||
<h2 id="flush-title">Hoi!</h2>
|
||||
</PageSection>
|
||||
<PageSection
|
||||
labelledBy="next-title"
|
||||
spacing="flushTop"
|
||||
data-testid="flush-top"
|
||||
>
|
||||
<h2 id="next-title">Verder</h2>
|
||||
</PageSection>
|
||||
</>,
|
||||
);
|
||||
const regular = getComputedStyle(screen.getByTestId('flush'));
|
||||
const flush = getComputedStyle(screen.getByTestId('flush-top'));
|
||||
expect(flush.paddingTop).toBe('0px');
|
||||
expect(flush.paddingBottom).toBe(regular.paddingBottom);
|
||||
expect(regular.paddingTop).not.toBe('0px');
|
||||
});
|
||||
|
||||
it('leaves out the content column at full width', async () => {
|
||||
await renderWithProviders(
|
||||
<PageSection labelledBy="insta-title" width="full">
|
||||
<h2 id="insta-title" data-testid="child">
|
||||
Instagram
|
||||
</h2>
|
||||
</PageSection>,
|
||||
);
|
||||
// The heading is a direct child of the section, not of a Container
|
||||
expect(screen.getByTestId('child').parentElement).toBe(
|
||||
screen.getByRole('region', { name: 'Instagram' }),
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user