Adds the fallbacks for visitors without JavaScript
The mobile menu works through CSS, and controls that need JavaScript are hidden without it. The contact photo gets its own preload, and the tests cover the new Reveal behaviour, the first row and the noscript markup. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -175,4 +175,14 @@ describe('ContactDetails in the prerendered HTML', () => {
|
||||
);
|
||||
expect(html).not.toContain('data-testid="details"');
|
||||
});
|
||||
|
||||
it('loads the small portrait lazily, so a hidden one is never fetched', async () => {
|
||||
const html = await serverHtml(card({ portrait }));
|
||||
const doc = new DOMParser().parseFromString(html, 'text/html');
|
||||
expect(
|
||||
doc
|
||||
.querySelector('[data-testid="contact-details-portrait"]')
|
||||
?.getAttribute('loading'),
|
||||
).toBe('lazy');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -70,6 +70,7 @@ export default function ContactDetails({
|
||||
rounded="full"
|
||||
objectFit="cover"
|
||||
flexShrink={0}
|
||||
loading="lazy"
|
||||
data-testid="contact-details-portrait"
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import { ChakraProvider } from '@chakra-ui/react';
|
||||
import { act, screen } from '@testing-library/react';
|
||||
import { prerender } from 'react-dom/static';
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import { FakeIntersectionObserver } from '@/test/fakeIntersectionObserver';
|
||||
import { hydratePage, serverHtml } from '@/test/hydrate';
|
||||
import { renderWithProviders } from '@/test/renderWithProviders';
|
||||
import system from '@/theme';
|
||||
import DeferredImage, { DEFERRED_LOAD_MARGIN } from './DeferredImage';
|
||||
|
||||
const image = {
|
||||
@@ -73,3 +77,80 @@ describe('DeferredImage', () => {
|
||||
expect(FakeIntersectionObserver.instances).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('DeferredImage without JavaScript', () => {
|
||||
const imgTags = (html: string) => html.match(/<img\b[^>]*>/g) ?? [];
|
||||
const attribute = (tag: string, name: string) =>
|
||||
new RegExp(` ${name}="([^"]*)"`).exec(tag)?.[1];
|
||||
const hasAttribute = (tag: string, name: string) =>
|
||||
new RegExp(` ${name}[ =/>]`).test(tag);
|
||||
|
||||
it('renders the empty image and, in a noscript, a twin with the photo', async () => {
|
||||
const html = await serverHtml(
|
||||
<DeferredImage image={image} id="foto" data-testid="foto" />,
|
||||
);
|
||||
const [first = '', twin = '', ...others] = imgTags(html);
|
||||
expect(others).toEqual([]);
|
||||
expect(html.match(/<noscript>/g)).toHaveLength(1);
|
||||
expect(html).toMatch(/<noscript><img\b[^>]*src="\/foto\.jpg"/);
|
||||
|
||||
expect(hasAttribute(first, 'data-deferred')).toBe(true);
|
||||
expect(hasAttribute(first, 'src')).toBe(false);
|
||||
expect(attribute(first, 'loading')).toBe('lazy');
|
||||
expect(attribute(first, 'id')).toBe('foto');
|
||||
expect(attribute(first, 'data-testid')).toBe('foto');
|
||||
|
||||
expect(attribute(twin, 'src')).toBe('/foto.jpg');
|
||||
expect(attribute(twin, 'alt')).toBe('Een foto');
|
||||
expect(attribute(twin, 'width')).toBe('800');
|
||||
expect(attribute(twin, 'height')).toBe('1200');
|
||||
expect(hasAttribute(twin, 'loading')).toBe(false);
|
||||
expect(hasAttribute(twin, 'id')).toBe(false);
|
||||
expect(hasAttribute(twin, 'data-testid')).toBe(false);
|
||||
expect(hasAttribute(twin, 'data-deferred')).toBe(false);
|
||||
});
|
||||
|
||||
it('gives the twin the class of the first image, so it has the same box', async () => {
|
||||
const html = await serverHtml(
|
||||
<DeferredImage image={image} w="100%" objectFit="cover" />,
|
||||
);
|
||||
const [first = '', twin = ''] = imgTags(html);
|
||||
expect(attribute(first, 'class')).toBeTruthy();
|
||||
expect(attribute(twin, 'class')).toBe(attribute(first, 'class'));
|
||||
});
|
||||
|
||||
it('adds no preload for the twin when it is rendered in a document', async () => {
|
||||
const { prelude } = await prerender(
|
||||
<html lang="nl">
|
||||
<head />
|
||||
<body>
|
||||
<ChakraProvider value={system}>
|
||||
<DeferredImage image={image} />
|
||||
<img src="/gewoon.jpg" alt="" />
|
||||
</ChakraProvider>
|
||||
</body>
|
||||
</html>,
|
||||
);
|
||||
const html = await new Response(prelude).text();
|
||||
const preloads = html.match(/<link\b[^>]*rel="preload"[^>]*>/g) ?? [];
|
||||
// React hoists the plain photo, which shows the check can see a preload
|
||||
expect(preloads).toHaveLength(1);
|
||||
expect(preloads[0]).toContain('href="/gewoon.jpg"');
|
||||
expect(html).toMatch(/<noscript><img\b[^>]*src="\/foto\.jpg"/);
|
||||
});
|
||||
|
||||
it('hydrates the pair without a mismatch and renders no twin in the browser', async () => {
|
||||
const { container, errors } = await hydratePage(
|
||||
<DeferredImage image={image} />,
|
||||
);
|
||||
expect(errors).toEqual([]);
|
||||
expect(container.querySelectorAll('img')).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('renders an empty noscript when the browser renders it', async () => {
|
||||
const { container } = await renderWithProviders(
|
||||
<DeferredImage image={image} />,
|
||||
);
|
||||
expect(container.querySelector('noscript')).toBeEmptyDOMElement();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,6 +2,7 @@ import { screen, within } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { axeResults } from '@/test/axe';
|
||||
import { serverHtml } from '@/test/hydrate';
|
||||
import { renderWithProviders } from '@/test/renderWithProviders';
|
||||
import FilterBar from './FilterBar';
|
||||
|
||||
@@ -101,4 +102,21 @@ describe('FilterBar', () => {
|
||||
0,
|
||||
);
|
||||
});
|
||||
|
||||
it('is marked as needing JavaScript in the prerendered HTML', async () => {
|
||||
const html = await serverHtml(
|
||||
<FilterBar
|
||||
options={options}
|
||||
value="alles"
|
||||
onChange={() => {}}
|
||||
label={LABEL}
|
||||
/>,
|
||||
);
|
||||
const doc = new DOMParser().parseFromString(html, 'text/html');
|
||||
expect(
|
||||
doc
|
||||
.querySelector('[data-testid="filter-bar"]')
|
||||
?.hasAttribute('data-requires-js'),
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -28,6 +28,7 @@ export default function FilterBar({
|
||||
role="group"
|
||||
aria-label={label}
|
||||
data-testid="filter-bar"
|
||||
data-requires-js
|
||||
display="flex"
|
||||
// One row, always: when the web font replaces the fallback, a
|
||||
// wrapping row could gain or lose a line and push the photos
|
||||
|
||||
@@ -220,4 +220,14 @@ describe('Footer in the prerendered HTML', () => {
|
||||
vi.unstubAllEnvs();
|
||||
}
|
||||
});
|
||||
|
||||
it('marks only the Contact column as needing JavaScript in the prerendered HTML', async () => {
|
||||
const html = await serverHtml(<Footer content={siteContent} />);
|
||||
const doc = new DOMParser().parseFromString(html, 'text/html');
|
||||
const marked = doc.querySelectorAll('[data-requires-js]');
|
||||
expect(marked).toHaveLength(1);
|
||||
expect(marked[0].querySelector('h2')?.getAttribute('aria-label')).toBe(
|
||||
'Contact',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -106,7 +106,7 @@ export default function Footer({ content }: FooterProps) {
|
||||
)}
|
||||
|
||||
{available && (
|
||||
<FooterColumn title="Contact">
|
||||
<FooterColumn title="Contact" requiresJs>
|
||||
{address === null ? (
|
||||
// Even hoog als FooterLink (44px onder lg, daarna
|
||||
// een tekstregel), zodat de kolom niet verspringt
|
||||
|
||||
@@ -3,14 +3,20 @@ import { Box, Heading, Stack } from '@chakra-ui/react';
|
||||
|
||||
type FooterColumnProps = {
|
||||
title: string;
|
||||
// Hidden without JavaScript, for a column that only holds items that need it
|
||||
requiresJs?: boolean;
|
||||
children: ReactNode;
|
||||
};
|
||||
|
||||
// Kolom in de footer: kopje als label, daaronder een lijst. De kop is een h2,
|
||||
// want de kolommen zijn hoofdsecties van de pagina (BR-SEO-09).
|
||||
export default function FooterColumn({ title, children }: FooterColumnProps) {
|
||||
export default function FooterColumn({
|
||||
title,
|
||||
requiresJs,
|
||||
children,
|
||||
}: FooterColumnProps) {
|
||||
return (
|
||||
<Box>
|
||||
<Box data-requires-js={requiresJs || undefined}>
|
||||
<Heading
|
||||
as="h2"
|
||||
// Mobiele schermlezers lezen de CSS-hoofdletters ("SOCIALS") als
|
||||
|
||||
@@ -186,6 +186,7 @@ export default function Hero({ content, socials }: HeroProps) {
|
||||
key={active}
|
||||
aria-hidden
|
||||
data-testid="hero-progress"
|
||||
data-requires-js
|
||||
data-state={paused ? 'paused' : 'running'}
|
||||
position="absolute"
|
||||
left={0}
|
||||
|
||||
@@ -16,6 +16,7 @@ export default function HeroArrows({ onPrev, onNext }: HeroArrowsProps) {
|
||||
side="left"
|
||||
aria-label="Vorige foto"
|
||||
data-testid="hero-prev-button"
|
||||
data-requires-js
|
||||
onClick={onPrev}
|
||||
>
|
||||
<Icon icon={leftOutlined} aria-hidden />
|
||||
@@ -24,6 +25,7 @@ export default function HeroArrows({ onPrev, onNext }: HeroArrowsProps) {
|
||||
side="right"
|
||||
aria-label="Volgende foto"
|
||||
data-testid="hero-next-button"
|
||||
data-requires-js
|
||||
onClick={onNext}
|
||||
>
|
||||
<Icon icon={rightOutlined} aria-hidden />
|
||||
|
||||
@@ -25,6 +25,7 @@ export default function HeroPauseButton({
|
||||
: 'Diavoorstelling pauzeren'
|
||||
}
|
||||
data-testid="hero-pause-button"
|
||||
data-requires-js
|
||||
onClick={onToggle}
|
||||
css={iconControl()}
|
||||
position="absolute"
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import heroContent from '@/content/heroContent';
|
||||
import siteContent from '@/content/siteContent';
|
||||
import { serverHtml } from '@/test/hydrate';
|
||||
import Hero from './Hero';
|
||||
|
||||
// Controls that do nothing without JavaScript carry the marker the head CSS
|
||||
// hides (BR-NJS-01, BR-NJS-03)
|
||||
describe('Hero in the prerendered HTML', () => {
|
||||
it('marks the arrows, the pause button and the progress bar', async () => {
|
||||
const html = await serverHtml(
|
||||
<Hero content={heroContent} socials={siteContent.socials} />,
|
||||
);
|
||||
const doc = new DOMParser().parseFromString(html, 'text/html');
|
||||
const marked = (testId: string) =>
|
||||
doc
|
||||
.querySelector(`[data-testid="${testId}"]`)
|
||||
?.hasAttribute('data-requires-js');
|
||||
|
||||
expect(marked('hero-prev-button')).toBe(true);
|
||||
expect(marked('hero-next-button')).toBe(true);
|
||||
expect(marked('hero-pause-button')).toBe(true);
|
||||
expect(marked('hero-progress')).toBe(true);
|
||||
expect(doc.querySelectorAll('[data-requires-js]')).toHaveLength(4);
|
||||
});
|
||||
});
|
||||
@@ -4,6 +4,7 @@ import type { NavMenuEvent } from '@/lib/navMenuState';
|
||||
import { hasChildren, mainNav } from '@/navigation';
|
||||
import RouterLink from '../RouterLink';
|
||||
import MobileNavGroup from './MobileNavGroup';
|
||||
import { NoScriptMenuClose } from './NoScriptNav';
|
||||
|
||||
// Exact, like the submenu: no link counts as current on an unknown URL
|
||||
// (BR-404-05)
|
||||
@@ -82,6 +83,7 @@ export default function MobileNav({
|
||||
{/* Automatische marges centreren een kort menu en laten een hoog
|
||||
menu bovenaan beginnen (centreren zou de bovenkant afknippen) */}
|
||||
<Box marginBlock="auto">
|
||||
<NoScriptMenuClose />
|
||||
<nav aria-label="Mobiel menu">
|
||||
<Stack as="ul" gap={5} listStyleType="none">
|
||||
{mainNav.map((item) => (
|
||||
|
||||
@@ -46,6 +46,7 @@ export default function MobileNavGroup({
|
||||
</RouterLink>
|
||||
<chakra.button
|
||||
type="button"
|
||||
data-requires-js
|
||||
aria-expanded={open}
|
||||
aria-controls={id}
|
||||
aria-label={`Submenu ${item.label}`}
|
||||
|
||||
@@ -54,6 +54,7 @@ export default function NavSubmenu({
|
||||
return (
|
||||
<Box
|
||||
ref={wrapper}
|
||||
data-submenu
|
||||
position="relative"
|
||||
display="flex"
|
||||
alignItems="center"
|
||||
@@ -80,6 +81,7 @@ export default function NavSubmenu({
|
||||
<chakra.button
|
||||
ref={toggleRef}
|
||||
type="button"
|
||||
data-requires-js
|
||||
aria-expanded={open}
|
||||
aria-controls={id}
|
||||
aria-label={`Submenu ${item.label}`}
|
||||
@@ -102,6 +104,7 @@ export default function NavSubmenu({
|
||||
</chakra.button>
|
||||
<Box
|
||||
id={id}
|
||||
data-submenu-panel
|
||||
position="absolute"
|
||||
top="calc(100% + 0.75rem)"
|
||||
left="4"
|
||||
|
||||
@@ -8,10 +8,12 @@ import {
|
||||
} from '@chakra-ui/react';
|
||||
import NavLink from './NavLink';
|
||||
import MobileNav from './MobileNav';
|
||||
import { NoScriptMenuOpen } from './NoScriptNav';
|
||||
import NavSubmenu from './NavSubmenu';
|
||||
import { hasChildren, mainNav } from '@/navigation';
|
||||
import RouterLink from '../RouterLink';
|
||||
import useScrolledPast from '@/hooks/useScrolledPast';
|
||||
import { HEADER_ID, MOBILE_NAV_ID } from '../NoScript/noScriptCss';
|
||||
import { isSectionCurrent } from '@/lib/navCurrent';
|
||||
import { initialNavMenuState, navMenuReducer } from '@/lib/navMenuState';
|
||||
import { useEffect, useReducer, useRef } from 'react';
|
||||
@@ -79,6 +81,7 @@ export default function NavigationBar() {
|
||||
return (
|
||||
<>
|
||||
<chakra.header
|
||||
id={HEADER_ID}
|
||||
position="fixed"
|
||||
top={0}
|
||||
insetX={0}
|
||||
@@ -135,6 +138,9 @@ export default function NavigationBar() {
|
||||
alt=""
|
||||
htmlWidth={500}
|
||||
htmlHeight={500}
|
||||
// Not shown on pages with a solid header, so
|
||||
// not fetched there (BR-PRE-05)
|
||||
loading={isHome ? undefined : 'lazy'}
|
||||
display={overlay('none', 'block')}
|
||||
/>
|
||||
</RouterLink>
|
||||
@@ -183,8 +189,10 @@ export default function NavigationBar() {
|
||||
display="flex"
|
||||
justifyContent="flex-end"
|
||||
>
|
||||
<NoScriptMenuOpen />
|
||||
<chakra.button
|
||||
ref={hamburgerRef}
|
||||
data-requires-js
|
||||
onClick={() =>
|
||||
dispatch({
|
||||
type: 'toggleMenu',
|
||||
@@ -202,7 +210,7 @@ export default function NavigationBar() {
|
||||
: 'Menu openen'
|
||||
}
|
||||
aria-expanded={state.menuOpen}
|
||||
aria-controls="mobile-nav"
|
||||
aria-controls={MOBILE_NAV_ID}
|
||||
data-open={state.menuOpen || undefined}
|
||||
// Op desktop opent deze knop straks het info-menu (side area)
|
||||
display={{ base: 'block', lg: 'none' }}
|
||||
@@ -253,7 +261,7 @@ export default function NavigationBar() {
|
||||
</Container>
|
||||
</chakra.header>
|
||||
<MobileNav
|
||||
id="mobile-nav"
|
||||
id={MOBILE_NAV_ID}
|
||||
open={state.menuOpen}
|
||||
groupOpen={state.groupOpen}
|
||||
pathname={pathname}
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { hydratePage, renderToString, serverHtml } from '@/test/hydrate';
|
||||
import NavigationBar from './NavigationBar';
|
||||
import { NoScriptMenuClose, NoScriptMenuOpen } from './NoScriptNav';
|
||||
|
||||
// The noscript wrappers are dropped first: this document runs scripts, so the
|
||||
// parser would keep their content as text
|
||||
function parse(markup: string) {
|
||||
const container = document.createElement('div');
|
||||
container.innerHTML = markup.replaceAll(/<\/?noscript>/g, '');
|
||||
return container;
|
||||
}
|
||||
|
||||
const FOLLOWING = Node.DOCUMENT_POSITION_FOLLOWING;
|
||||
|
||||
describe('NoScriptMenuOpen', () => {
|
||||
it('renders one link to the panel inside a noscript', () => {
|
||||
const markup = renderToString(<NoScriptMenuOpen />);
|
||||
expect(markup.startsWith('<noscript>')).toBe(true);
|
||||
expect(markup.endsWith('</noscript>')).toBe(true);
|
||||
const links = parse(markup).querySelectorAll('a');
|
||||
expect(links).toHaveLength(1);
|
||||
expect(links[0]).toHaveAttribute('href', '#mobile-nav');
|
||||
expect(links[0]).toHaveAttribute('aria-label', 'Menu openen');
|
||||
expect(links[0]).toHaveAttribute('class', 'ns-menu-open');
|
||||
expect(links[0]).toHaveAttribute('data-testid', 'nav-noscript-open');
|
||||
expect(
|
||||
links[0].querySelectorAll('span[aria-hidden="true"]'),
|
||||
).toHaveLength(3);
|
||||
});
|
||||
|
||||
it('has no style element inside the noscript', () => {
|
||||
expect(renderToString(<NoScriptMenuOpen />)).not.toContain('<style');
|
||||
});
|
||||
});
|
||||
|
||||
describe('NoScriptMenuClose', () => {
|
||||
it('renders one link to the header inside a noscript', () => {
|
||||
const markup = renderToString(<NoScriptMenuClose />);
|
||||
expect(markup.startsWith('<noscript>')).toBe(true);
|
||||
const links = parse(markup).querySelectorAll('a');
|
||||
expect(links).toHaveLength(1);
|
||||
expect(links[0]).toHaveAttribute('href', '#site-header');
|
||||
expect(links[0]).toHaveAttribute('class', 'ns-menu-close');
|
||||
expect(links[0]).toHaveAttribute('data-testid', 'nav-noscript-close');
|
||||
expect(links[0]).toHaveTextContent('Menu sluiten');
|
||||
});
|
||||
|
||||
it('has no style element inside the noscript', () => {
|
||||
expect(renderToString(<NoScriptMenuClose />)).not.toContain('<style');
|
||||
});
|
||||
});
|
||||
|
||||
describe('NavigationBar server markup', () => {
|
||||
it('puts the open link before the hamburger and the close link first in the panel', async () => {
|
||||
const navigation = parse(await serverHtml(<NavigationBar />));
|
||||
const open = navigation.querySelector('.ns-menu-open')!;
|
||||
const hamburger = navigation.querySelector(
|
||||
'[data-testid="nav-menu-toggle"]',
|
||||
)!;
|
||||
expect(
|
||||
open.compareDocumentPosition(hamburger) & FOLLOWING,
|
||||
).toBeTruthy();
|
||||
const panel = navigation.querySelector('#mobile-nav')!;
|
||||
const close = panel.querySelector('.ns-menu-close')!;
|
||||
const list = panel.querySelector('nav')!;
|
||||
expect(list.contains(close)).toBe(false);
|
||||
expect(close.compareDocumentPosition(list) & FOLLOWING).toBeTruthy();
|
||||
});
|
||||
|
||||
it('makes the light logo lazy except on the home page (BR-PRE-05)', async () => {
|
||||
const logos = async (path: string) =>
|
||||
parse(await serverHtml(<NavigationBar />, path)).querySelectorAll(
|
||||
'header img',
|
||||
);
|
||||
const inner = await logos('/over-mij');
|
||||
expect(inner[1]).toHaveAttribute('loading', 'lazy');
|
||||
expect(inner[0]).not.toHaveAttribute('loading');
|
||||
const home = await logos('/');
|
||||
expect(home[1]).not.toHaveAttribute('loading');
|
||||
expect(home[0]).not.toHaveAttribute('loading');
|
||||
});
|
||||
|
||||
it('hydrates without a mismatch with the noscript links in place', async () => {
|
||||
const { errors, container } = await hydratePage(<NavigationBar />);
|
||||
expect(errors).toEqual([]);
|
||||
expect(
|
||||
container.querySelector('[data-testid="nav-menu-toggle"]'),
|
||||
).not.toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,35 @@
|
||||
import { HEADER_ID, MOBILE_NAV_ID } from '../NoScript/noScriptCss';
|
||||
|
||||
// Menu links for a visitor without JavaScript. Plain elements: a browser with
|
||||
// scripting on ignores the noscript content, and the CSS in the head
|
||||
// (noScriptCss.ts) styles them.
|
||||
export function NoScriptMenuOpen() {
|
||||
return (
|
||||
<noscript>
|
||||
<a
|
||||
className="ns-menu-open"
|
||||
href={`#${MOBILE_NAV_ID}`}
|
||||
aria-label="Menu openen"
|
||||
data-testid="nav-noscript-open"
|
||||
>
|
||||
<span aria-hidden="true" />
|
||||
<span aria-hidden="true" />
|
||||
<span aria-hidden="true" />
|
||||
</a>
|
||||
</noscript>
|
||||
);
|
||||
}
|
||||
|
||||
export function NoScriptMenuClose() {
|
||||
return (
|
||||
<noscript>
|
||||
<a
|
||||
className="ns-menu-close"
|
||||
href={`#${HEADER_ID}`}
|
||||
data-testid="nav-noscript-close"
|
||||
>
|
||||
Menu sluiten
|
||||
</a>
|
||||
</noscript>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import siteContent from '@/content/siteContent';
|
||||
import { emailAddress } from '@/lib/emailAddress';
|
||||
import { serverHtml } from '@/test/hydrate';
|
||||
import NavigationBar from '../NavigationBar/NavigationBar';
|
||||
import { HEADER_ID, MOBILE_NAV_ID, NO_SCRIPT_CSS } from './noScriptCss';
|
||||
|
||||
// The navigation as the prerender writes it, without the noscript wrappers:
|
||||
// this document runs scripts, so the parser would keep their content as text
|
||||
async function navigationDocument(path = '/') {
|
||||
const container = document.createElement('div');
|
||||
container.innerHTML = (
|
||||
await serverHtml(<NavigationBar />, path)
|
||||
).replaceAll(/<\/?noscript>/g, '');
|
||||
return container;
|
||||
}
|
||||
|
||||
describe('NO_SCRIPT_CSS', () => {
|
||||
it('cannot end the noscript early or fetch anything (BR-NAV-02)', () => {
|
||||
expect(NO_SCRIPT_CSS).not.toContain('</');
|
||||
expect(NO_SCRIPT_CSS).not.toContain('url(');
|
||||
expect(NO_SCRIPT_CSS).not.toContain('@import');
|
||||
});
|
||||
|
||||
it('has balanced braces and no empty rule', () => {
|
||||
const opening = NO_SCRIPT_CSS.match(/\{/g)?.length ?? 0;
|
||||
const closing = NO_SCRIPT_CSS.match(/\}/g)?.length ?? 0;
|
||||
expect(opening).toBeGreaterThan(0);
|
||||
expect(opening).toBe(closing);
|
||||
expect(NO_SCRIPT_CSS).not.toContain('{}');
|
||||
});
|
||||
|
||||
it('holds no e-mail address', () => {
|
||||
expect(NO_SCRIPT_CSS).not.toContain(emailAddress(siteContent.email)!);
|
||||
});
|
||||
|
||||
it.each([
|
||||
['wrapper', 'noscript{display:contents}'],
|
||||
[
|
||||
'empty photo',
|
||||
'img[data-deferred]:not([src]){display:none!important}',
|
||||
],
|
||||
[
|
||||
'hidden controls',
|
||||
'[data-requires-js],[data-email-pending]{display:none!important}',
|
||||
],
|
||||
['open link', '.ns-menu-open{'],
|
||||
[
|
||||
'open link hidden from lg',
|
||||
'@media (min-width:64rem){.ns-menu-open{display:none}}',
|
||||
],
|
||||
['close link', '.ns-menu-close{'],
|
||||
[
|
||||
'focus ring',
|
||||
'.ns-menu-open:focus-visible,.ns-menu-close:focus-visible{outline:',
|
||||
],
|
||||
[
|
||||
'panel open',
|
||||
'#mobile-nav:target{clip-path:inset(0);visibility:visible}',
|
||||
],
|
||||
[
|
||||
'group expanded',
|
||||
'#mobile-nav [id^="mobile-group-"]{grid-template-rows:1fr;visibility:visible;transition:none}',
|
||||
],
|
||||
[
|
||||
'desktop submenu',
|
||||
'[data-submenu]:focus-within>[data-submenu-panel]{visibility:visible;opacity:1;transform:none;pointer-events:auto;transition:none}',
|
||||
],
|
||||
])('has the %s rule', (_group, rule) => {
|
||||
expect(NO_SCRIPT_CSS).toContain(rule);
|
||||
});
|
||||
|
||||
it('does not set display on the panel, so it stays hidden from lg', () => {
|
||||
const panelRule = NO_SCRIPT_CSS.match(
|
||||
/#mobile-nav:target\{[^}]*\}/,
|
||||
)![0];
|
||||
expect(panelRule).not.toContain('display');
|
||||
});
|
||||
});
|
||||
|
||||
describe('what the CSS names exists in the navigation', () => {
|
||||
it('uses the ids the components render', async () => {
|
||||
expect(MOBILE_NAV_ID).toBe('mobile-nav');
|
||||
expect(HEADER_ID).toBe('site-header');
|
||||
const navigation = await navigationDocument();
|
||||
expect(navigation.querySelector(`header#${HEADER_ID}`)).not.toBeNull();
|
||||
expect(navigation.querySelector(`#${MOBILE_NAV_ID}`)).not.toBeNull();
|
||||
expect(
|
||||
navigation.querySelector('[id^="mobile-group-"]'),
|
||||
).not.toBeNull();
|
||||
});
|
||||
|
||||
it('marks the buttons that do nothing without JavaScript', async () => {
|
||||
const navigation = await navigationDocument();
|
||||
const marked = [...navigation.querySelectorAll('[data-requires-js]')];
|
||||
// Hamburger, desktop chevron, mobile chevron
|
||||
expect(marked).toHaveLength(3);
|
||||
expect(marked.every((element) => element.tagName === 'BUTTON')).toBe(
|
||||
true,
|
||||
);
|
||||
expect(
|
||||
navigation.querySelector('[data-testid="nav-menu-toggle"]'),
|
||||
).toHaveAttribute('data-requires-js');
|
||||
});
|
||||
|
||||
it('marks the desktop submenu wrapper and its panel', async () => {
|
||||
const navigation = await navigationDocument();
|
||||
const wrapper = navigation.querySelector('[data-submenu]')!;
|
||||
const panel = wrapper.querySelector('[data-submenu-panel]')!;
|
||||
expect(panel).toHaveAttribute('id', 'submenu-soorten-fotoshoots');
|
||||
});
|
||||
});
|
||||
@@ -2,9 +2,58 @@
|
||||
// <noscript><style> in the head, so a browser with scripting on never parses
|
||||
// it. No `</`, `url(` or `@import`: it must not end the noscript early or
|
||||
// fetch anything (BR-NAV-02).
|
||||
export const NO_SCRIPT_CSS = [
|
||||
// The wrapper takes no part in flex, grid or positioning of its twin
|
||||
'noscript{display:contents}',
|
||||
// The empty deferred photo would draw as a broken-image box
|
||||
'img[data-deferred]:not([src]){display:none!important}',
|
||||
|
||||
// Ids the menu links point at; the components render the same constants
|
||||
export const MOBILE_NAV_ID = 'mobile-nav';
|
||||
export const HEADER_ID = 'site-header';
|
||||
|
||||
// The wrapper takes no part in flex, grid or positioning of its twin
|
||||
const WRAPPER = 'noscript{display:contents}';
|
||||
|
||||
// The empty deferred photo would draw as a broken-image box
|
||||
const EMPTY_PHOTO = 'img[data-deferred]:not([src]){display:none!important}';
|
||||
|
||||
// Controls that do nothing without JavaScript. !important: the style props of
|
||||
// these elements set display, and Emotion's rules come later in the document.
|
||||
const HIDDEN_CONTROLS =
|
||||
'[data-requires-js],[data-email-pending]{display:none!important}';
|
||||
|
||||
// The open link takes the place of the hamburger: same 44px box, same bars
|
||||
const OPEN_LINK = [
|
||||
'.ns-menu-open{display:block;position:relative;width:44px;height:44px;color:inherit}',
|
||||
'.ns-menu-open>span{position:absolute;left:10px;width:24px;height:2px;border-radius:1px;background:currentColor}',
|
||||
'.ns-menu-open>span:nth-of-type(1){top:15px}',
|
||||
'.ns-menu-open>span:nth-of-type(2){top:21px}',
|
||||
'.ns-menu-open>span:nth-of-type(3){top:27px}',
|
||||
'@media (min-width:64rem){.ns-menu-open{display:none}}',
|
||||
].join('');
|
||||
|
||||
const CLOSE_LINK =
|
||||
'.ns-menu-close{display:inline-block;min-height:44px;padding:0.5rem 0;color:inherit;font:inherit}';
|
||||
|
||||
const FOCUS_RING =
|
||||
'.ns-menu-open:focus-visible,.ns-menu-close:focus-visible{outline:2px solid currentColor;outline-offset:2px}';
|
||||
|
||||
// Id selectors outweigh Emotion's single-class rules. No display: the panel
|
||||
// stays hidden from lg up, even when the address ends in the fragment.
|
||||
const PANEL_OPEN = `#${MOBILE_NAV_ID}:target{clip-path:inset(0);visibility:visible}`;
|
||||
|
||||
// The shoot group is always expanded
|
||||
const GROUP_EXPANDED = `#${MOBILE_NAV_ID} [id^="mobile-group-"]{grid-template-rows:1fr;visibility:visible;transition:none}`;
|
||||
|
||||
// The desktop submenu opens on keyboard focus. transition none: a Tab pressed
|
||||
// while the visibility transition starts would skip the panel.
|
||||
const SUBMENU_FOCUS =
|
||||
'[data-submenu]:focus-within>[data-submenu-panel]{visibility:visible;opacity:1;transform:none;pointer-events:auto;transition:none}';
|
||||
|
||||
export const NO_SCRIPT_CSS = [
|
||||
WRAPPER,
|
||||
EMPTY_PHOTO,
|
||||
HIDDEN_CONTROLS,
|
||||
OPEN_LINK,
|
||||
CLOSE_LINK,
|
||||
FOCUS_RING,
|
||||
PANEL_OPEN,
|
||||
GROUP_EXPANDED,
|
||||
SUBMENU_FOCUS,
|
||||
].join('');
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import { fireEvent, screen, within } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { GRID_COLUMNS } from '@/lib/firstRow';
|
||||
import { masonryRowSpan } from '@/lib/masonryRowSpan';
|
||||
import { axeResults } from '@/test/axe';
|
||||
import { cssRulesFor } from '@/test/cssRules';
|
||||
import { galleryItems } from '@/test/galleryFixtures';
|
||||
import { hydratePage, serverHtml } from '@/test/hydrate';
|
||||
import { renderWithProviders } from '@/test/renderWithProviders';
|
||||
import PortfolioGrid from './PortfolioGrid';
|
||||
|
||||
@@ -31,13 +34,9 @@ describe('PortfolioGrid', () => {
|
||||
expect(await axeResults(container)).toHaveNoViolations();
|
||||
});
|
||||
|
||||
it('loads the first photos straight away and defers the rest', async () => {
|
||||
it('loads the first row straight away and defers the rest', async () => {
|
||||
await renderWithProviders(
|
||||
<PortfolioGrid
|
||||
items={galleryItems}
|
||||
eagerFirstRow
|
||||
onOpen={() => {}}
|
||||
/>,
|
||||
<PortfolioGrid items={galleryItems} onOpen={() => {}} />,
|
||||
);
|
||||
const images = screen.getAllByRole('img');
|
||||
images.forEach((image, index) => {
|
||||
@@ -56,6 +55,28 @@ describe('PortfolioGrid', () => {
|
||||
String(galleryItems[index].thumb.width),
|
||||
);
|
||||
});
|
||||
// Only tile 1 is plain; tiles 2 and 3 have a source of their own
|
||||
expect(images[0].closest('picture')).toBeNull();
|
||||
expect(images[1].closest('picture')).not.toBeNull();
|
||||
expect(images[2].closest('picture')).not.toBeNull();
|
||||
expect(images[3].closest('picture')).toBeNull();
|
||||
});
|
||||
|
||||
it('defers every photo when the first row is not eager', async () => {
|
||||
await renderWithProviders(
|
||||
<PortfolioGrid
|
||||
items={galleryItems}
|
||||
eagerFirstRow={false}
|
||||
onOpen={() => {}}
|
||||
/>,
|
||||
);
|
||||
const images = screen.getAllByRole('img');
|
||||
expect(images).toHaveLength(galleryItems.length);
|
||||
for (const image of images) {
|
||||
expect(image).not.toHaveAttribute('fetchpriority');
|
||||
expect(image).toHaveAttribute('loading', 'lazy');
|
||||
expect(image.closest('picture')).toBeNull();
|
||||
}
|
||||
});
|
||||
|
||||
it('asks to open the lightbox on a plain click or Enter', async () => {
|
||||
@@ -107,3 +128,112 @@ describe('PortfolioGrid', () => {
|
||||
expect(screen.getByTestId('portfolio-grid')).toBeEmptyDOMElement();
|
||||
});
|
||||
});
|
||||
|
||||
describe('PortfolioGrid in the prerendered HTML', () => {
|
||||
const tileOf = (page: HTMLElement, number: number) =>
|
||||
page.querySelector(`[data-testid="portfolio-tile-${number}"]`)!;
|
||||
|
||||
const prerendered = async (eagerFirstRow?: boolean) => {
|
||||
const page = document.createElement('div');
|
||||
page.innerHTML = await serverHtml(
|
||||
<PortfolioGrid
|
||||
items={galleryItems}
|
||||
eagerFirstRow={eagerFirstRow}
|
||||
onOpen={() => {}}
|
||||
/>,
|
||||
);
|
||||
return page;
|
||||
};
|
||||
|
||||
it('gives tile 1 a plain photo with its src, whatever the screen width', async () => {
|
||||
const image = tileOf(await prerendered(), 1).querySelector('img')!;
|
||||
expect(image.closest('picture')).toBeNull();
|
||||
expect(image).toHaveAttribute('src', galleryItems[0].thumb.src);
|
||||
expect(image).toHaveAttribute('fetchpriority', 'high');
|
||||
expect(image).not.toHaveAttribute('data-deferred');
|
||||
});
|
||||
|
||||
it('puts tiles 2 and 3 in a picture whose source starts at the width of their column (BR-PRE-10)', async () => {
|
||||
const page = await prerendered();
|
||||
[1, 2].forEach((index) => {
|
||||
const tile = tileOf(page, index + 1);
|
||||
const source = tile.querySelector('picture > source')!;
|
||||
expect(source).toHaveAttribute('media', GRID_COLUMNS[index].media);
|
||||
expect(source).toHaveAttribute(
|
||||
'srcset',
|
||||
galleryItems[index].thumb.src,
|
||||
);
|
||||
const image = tile.querySelector('picture > img')!;
|
||||
expect(image).toHaveAttribute('data-deferred');
|
||||
expect(image).not.toHaveAttribute('src');
|
||||
expect(image).toHaveAttribute('loading', 'eager');
|
||||
expect(image).toHaveAttribute('fetchpriority', 'high');
|
||||
});
|
||||
});
|
||||
|
||||
it('leaves tile 4 and up deferred, without a src', async () => {
|
||||
const page = await prerendered();
|
||||
expect(galleryItems.length).toBeGreaterThan(3);
|
||||
for (let number = 4; number <= galleryItems.length; number++) {
|
||||
const tile = tileOf(page, number);
|
||||
const image = tile.querySelector('img')!;
|
||||
expect(tile.querySelector('picture')).toBeNull();
|
||||
expect(image).toHaveAttribute('data-deferred');
|
||||
expect(image).not.toHaveAttribute('src');
|
||||
expect(image).toHaveAttribute('loading', 'lazy');
|
||||
}
|
||||
});
|
||||
|
||||
it('defers every tile when the first row is not eager', async () => {
|
||||
const page = await prerendered(false);
|
||||
for (let number = 1; number <= galleryItems.length; number++) {
|
||||
const tile = tileOf(page, number);
|
||||
const image = tile.querySelector('img')!;
|
||||
expect(tile.querySelector('picture, source')).toBeNull();
|
||||
expect(image).toHaveAttribute('data-deferred');
|
||||
expect(image).not.toHaveAttribute('src');
|
||||
}
|
||||
});
|
||||
|
||||
it('hydrates without a mismatch, with the first row and without it', async () => {
|
||||
const eager = await hydratePage(
|
||||
<PortfolioGrid items={galleryItems} onOpen={() => {}} />,
|
||||
);
|
||||
expect(eager.errors).toEqual([]);
|
||||
eager.unmount();
|
||||
|
||||
const deferred = await hydratePage(
|
||||
<PortfolioGrid
|
||||
items={galleryItems}
|
||||
eagerFirstRow={false}
|
||||
onOpen={() => {}}
|
||||
/>,
|
||||
);
|
||||
expect(deferred.errors).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('PortfolioGrid columns', () => {
|
||||
it('lays out as many columns per width as GRID_COLUMNS names, the ones the first row follows', async () => {
|
||||
await renderWithProviders(
|
||||
<PortfolioGrid items={galleryItems} onOpen={() => {}} />,
|
||||
);
|
||||
const rules = cssRulesFor(screen.getByTestId('portfolio-grid'));
|
||||
const [base, ...wider] = GRID_COLUMNS;
|
||||
const unqueried = rules.filter((rule) => !rule.startsWith('@media'));
|
||||
expect(unqueried.join()).toContain('grid-template-columns: 1fr');
|
||||
expect(unqueried.join()).toContain(`--cols: ${base.columns}`);
|
||||
for (const { media, columns } of wider) {
|
||||
// Chakra writes its breakpoints in rem, the first row in em; both
|
||||
// are relative to the browser's font size
|
||||
const query = media.replace('em)', 'rem)');
|
||||
const inQuery = rules
|
||||
.filter((rule) => rule.startsWith(`@media screen and ${query}`))
|
||||
.join();
|
||||
expect(inQuery).toContain(
|
||||
`grid-template-columns: repeat(${columns}, 1fr)`,
|
||||
);
|
||||
expect(inQuery).toContain(`--cols: ${columns}`);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -9,13 +9,20 @@ import {
|
||||
import DeferredImage from '@/components/DeferredImage/DeferredImage';
|
||||
import Reveal from '@/components/Reveal/Reveal';
|
||||
import type { GalleryItem } from '@/content/types';
|
||||
import { firstRow } from '@/lib/firstRow';
|
||||
import { firstRow, GRID_COLUMNS } from '@/lib/firstRow';
|
||||
import {
|
||||
GAP_ROWS,
|
||||
masonryRowSpan,
|
||||
ROWS_PER_COLUMN_WIDTH,
|
||||
} from '@/lib/masonryRowSpan';
|
||||
|
||||
const [BASE_COLUMNS, MD_COLUMNS, LG_COLUMNS] = GRID_COLUMNS.map(
|
||||
(entry) => entry.columns,
|
||||
);
|
||||
|
||||
const columnTemplate = (columns: number) =>
|
||||
columns === 1 ? '1fr' : `repeat(${columns}, 1fr)`;
|
||||
|
||||
type PortfolioGridProps = {
|
||||
items: readonly GalleryItem[];
|
||||
// The photos of the first row (one column per screen width, see firstRow)
|
||||
@@ -109,17 +116,17 @@ export default function PortfolioGrid({
|
||||
listStyleType="none"
|
||||
display="grid"
|
||||
gridTemplateColumns={{
|
||||
base: '1fr',
|
||||
md: 'repeat(2, 1fr)',
|
||||
lg: 'repeat(3, 1fr)',
|
||||
base: columnTemplate(BASE_COLUMNS),
|
||||
md: columnTemplate(MD_COLUMNS),
|
||||
lg: columnTemplate(LG_COLUMNS),
|
||||
}}
|
||||
columnGap="gridGap"
|
||||
// One implicit row = column width / ROWS_PER_COLUMN_WIDTH
|
||||
gridAutoRows="var(--row)"
|
||||
css={{
|
||||
'--cols': '1',
|
||||
md: { '--cols': '2' },
|
||||
lg: { '--cols': '3' },
|
||||
'--cols': String(BASE_COLUMNS),
|
||||
md: { '--cols': String(MD_COLUMNS) },
|
||||
lg: { '--cols': String(LG_COLUMNS) },
|
||||
'--row': `calc((100cqi - (var(--cols) - 1) * {spacing.gridGap}) / var(--cols) / ${ROWS_PER_COLUMN_WIDTH})`,
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -1,8 +1,29 @@
|
||||
import { screen } from '@testing-library/react';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { act, screen } from '@testing-library/react';
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import { cssRulesFor } from '@/test/cssRules';
|
||||
import { FakeIntersectionObserver } from '@/test/fakeIntersectionObserver';
|
||||
import { renderWithProviders } from '@/test/renderWithProviders';
|
||||
import Reveal from './Reveal';
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals();
|
||||
FakeIntersectionObserver.reset();
|
||||
});
|
||||
|
||||
// The rules of the element outside media queries, as one text
|
||||
const baseRules = (element: Element) =>
|
||||
cssRulesFor(element)
|
||||
.filter((rule) => !rule.startsWith('@media'))
|
||||
.join(' ');
|
||||
|
||||
// jsdom has no layout: put the element below the bottom edge of the viewport
|
||||
function startBelowFold() {
|
||||
vi.stubGlobal('IntersectionObserver', FakeIntersectionObserver);
|
||||
vi.spyOn(Element.prototype, 'getBoundingClientRect').mockReturnValue({
|
||||
top: innerHeight,
|
||||
} as DOMRect);
|
||||
}
|
||||
|
||||
describe('Reveal', () => {
|
||||
it('renders its content visibly when IntersectionObserver is missing', async () => {
|
||||
await renderWithProviders(
|
||||
@@ -25,4 +46,50 @@ describe('Reveal', () => {
|
||||
);
|
||||
expect(screen.getByTestId('reveal').tagName).toBe('FIGURE');
|
||||
});
|
||||
|
||||
it('stays visible, without a transition, when it is in view at load', async () => {
|
||||
vi.stubGlobal('IntersectionObserver', FakeIntersectionObserver);
|
||||
await renderWithProviders(
|
||||
<Reveal delay={0.4} data-testid="reveal">
|
||||
<p>Inhoud</p>
|
||||
</Reveal>,
|
||||
);
|
||||
const reveal = screen.getByTestId('reveal');
|
||||
expect(reveal).toHaveAttribute('data-reveal', 'visible');
|
||||
expect(reveal).toHaveStyle({ opacity: '1' });
|
||||
expect(baseRules(reveal)).toContain('transition: none');
|
||||
});
|
||||
|
||||
it('is hidden without a transition when it starts below the fold', async () => {
|
||||
startBelowFold();
|
||||
await renderWithProviders(
|
||||
<Reveal delay={0.4} data-testid="reveal">
|
||||
<p>Inhoud</p>
|
||||
</Reveal>,
|
||||
);
|
||||
const reveal = screen.getByTestId('reveal');
|
||||
expect(reveal).toHaveAttribute('data-reveal', 'hidden');
|
||||
expect(reveal).toHaveStyle({
|
||||
opacity: '0',
|
||||
transform: 'translateY(24px)',
|
||||
});
|
||||
expect(baseRules(reveal)).toContain('transition: none');
|
||||
});
|
||||
|
||||
it('fades in with its delay once it scrolls into view', async () => {
|
||||
startBelowFold();
|
||||
await renderWithProviders(
|
||||
<Reveal delay={0.4} data-testid="reveal">
|
||||
<p>Inhoud</p>
|
||||
</Reveal>,
|
||||
);
|
||||
act(() => FakeIntersectionObserver.instances[0].trigger(true));
|
||||
const reveal = screen.getByTestId('reveal');
|
||||
expect(reveal).toHaveAttribute('data-reveal', 'visible');
|
||||
expect(reveal).toHaveStyle({ opacity: '1', transform: 'none' });
|
||||
const rules = baseRules(reveal);
|
||||
expect(rules).toContain('transition-property: opacity,transform');
|
||||
expect(rules).toContain('transition-delay: 0.4s');
|
||||
expect(rules).not.toContain('transition: none');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -262,4 +262,20 @@ describe('Testimonials in the prerendered HTML', () => {
|
||||
expect(html.match(/data-testid="testimonial-/g)).toHaveLength(1);
|
||||
expect(html).not.toContain('inert');
|
||||
});
|
||||
|
||||
it('marks the controls spacer and keeps the other copies hidden in the prerendered HTML', async () => {
|
||||
const html = await serverHtml(
|
||||
<Testimonials content={content} testimonials={testimonials} />,
|
||||
);
|
||||
const doc = new DOMParser().parseFromString(html, 'text/html');
|
||||
const marked = doc.querySelectorAll('[data-requires-js]');
|
||||
expect(marked).toHaveLength(1);
|
||||
expect(marked[0].textContent).toBe('');
|
||||
const copies = [...doc.querySelectorAll('[aria-hidden="true"]')].filter(
|
||||
(element) => element.querySelector('blockquote'),
|
||||
);
|
||||
expect(copies.length).toBeGreaterThan(0);
|
||||
for (const copy of copies)
|
||||
expect(copy.hasAttribute('inert')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -98,7 +98,7 @@ function CarouselPlaceholder({
|
||||
</VisuallyHidden>
|
||||
))}
|
||||
{/* The control bar: 48px buttons below the same margin */}
|
||||
<Box mt="clamp(2.5rem, 5vw, 4rem)" h="48px" />
|
||||
<Box mt="clamp(2.5rem, 5vw, 4rem)" h="48px" data-requires-js />
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -64,11 +64,20 @@ describe('PortfolioGallery', () => {
|
||||
screen.getByRole('button', { name: 'Alles', pressed: true }),
|
||||
).toBeInTheDocument();
|
||||
expect(tiles()).toHaveLength(10);
|
||||
// Every photo waits until the page has loaded (none eager)
|
||||
for (const image of screen.getAllByRole('img')) {
|
||||
expect(image).not.toHaveAttribute('fetchpriority');
|
||||
expect(image).toHaveAttribute('loading', 'lazy');
|
||||
}
|
||||
// The first row loads straight away, every later photo waits until
|
||||
// the page has loaded
|
||||
screen.getAllByRole('img').forEach((image, index) => {
|
||||
if (index === 0) {
|
||||
expect(image).toHaveAttribute('fetchpriority', 'high');
|
||||
expect(image).not.toHaveAttribute('loading');
|
||||
} else if (index < 3) {
|
||||
expect(image).toHaveAttribute('fetchpriority', 'high');
|
||||
expect(image).toHaveAttribute('loading', 'eager');
|
||||
} else {
|
||||
expect(image).not.toHaveAttribute('fetchpriority');
|
||||
expect(image).toHaveAttribute('loading', 'lazy');
|
||||
}
|
||||
});
|
||||
expect(await axeResults(container)).toHaveNoViolations();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user