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>
77 lines
2.5 KiB
TypeScript
77 lines
2.5 KiB
TypeScript
// @vitest-environment node
|
|
import { ChakraProvider } from '@chakra-ui/react';
|
|
import {
|
|
createMemoryHistory,
|
|
createRouter,
|
|
HeadContent,
|
|
RouterProvider,
|
|
rootRouteId,
|
|
} from '@tanstack/react-router';
|
|
import type { ReactNode } from 'react';
|
|
import { prerender } from 'react-dom/static';
|
|
import { describe, expect, it } from 'vitest';
|
|
import { routerOptions } from './router';
|
|
import sitePages from './sitePages';
|
|
import system from './theme';
|
|
|
|
// What the HTML of every page holds for visitors without JavaScript: all
|
|
// content visible, and every empty deferred photo next to a twin that shows
|
|
// it (BR-RVL-01, BR-IMG-01). Rendered like src/prerender.test.tsx does.
|
|
const TestShell = ({ children }: { children: ReactNode }) => (
|
|
<>
|
|
<HeadContent />
|
|
{children}
|
|
</>
|
|
);
|
|
|
|
async function prerenderPath(path: string) {
|
|
const router = createRouter({
|
|
...routerOptions(),
|
|
history: createMemoryHistory({ initialEntries: [path] }),
|
|
});
|
|
const rootOptions = router.routesById[rootRouteId].options as {
|
|
shellComponent?: typeof TestShell;
|
|
};
|
|
rootOptions.shellComponent = TestShell;
|
|
await router.load();
|
|
const { prelude } = await prerender(
|
|
<ChakraProvider value={system}>
|
|
<RouterProvider router={router} />
|
|
</ChakraProvider>,
|
|
);
|
|
return new Response(prelude).text();
|
|
}
|
|
|
|
const count = (html: string, pattern: RegExp) =>
|
|
html.match(pattern)?.length ?? 0;
|
|
|
|
describe('prerendered display fallbacks', () => {
|
|
it.each([...Object.keys(sitePages), '/onbekend'])(
|
|
'shows %s with one noscript twin per deferred photo and nothing hidden',
|
|
async (path) => {
|
|
const html = await prerenderPath(path);
|
|
const deferred = count(html, /<img\b[^>]*\bdata-deferred\b[^>]*>/g);
|
|
const twins = count(html, /<noscript><img\b[^>]*\bsrc="[^"]+"/g);
|
|
expect(twins).toBe(deferred);
|
|
expect(html).not.toContain('data-reveal="hidden"');
|
|
},
|
|
30_000,
|
|
);
|
|
|
|
it.each(['/', '/portfolio', '/over-mij'])(
|
|
'writes the content of %s as visible Reveals',
|
|
async (path) => {
|
|
const html = await prerenderPath(path);
|
|
expect(count(html, /data-reveal="visible"/g)).toBeGreaterThan(0);
|
|
},
|
|
30_000,
|
|
);
|
|
|
|
it('has deferred photos on the pages that show many', async () => {
|
|
const html = await prerenderPath('/portfolio');
|
|
expect(
|
|
count(html, /<img\b[^>]*\bdata-deferred\b[^>]*>/g),
|
|
).toBeGreaterThan(3);
|
|
});
|
|
});
|