The prerendered hero is plain HTML between the markers (first photo, h1, buttons), the slider takes over after hydration with the hero of the host block, the API or the build. The head preload is added to the finished HTML. Hero texts move into nl.json. The stand-in host and the e2e tests cover the hero. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
37 lines
1.5 KiB
TypeScript
37 lines
1.5 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { injectHeroPreload } from './heroPreload.ts';
|
|
|
|
const page = (body: string, head = '<title>t</title>') =>
|
|
`<html><head>${head}</head><body>${body}</body></html>`;
|
|
|
|
describe('injectHeroPreload', () => {
|
|
it('writes the preload of the first photo between markers before </head>', () => {
|
|
const out = injectHeroPreload(
|
|
page(
|
|
'<img class="cms-hero-image" src="/assets/hero-8-abc.jpg" width="1" height="1" alt="">',
|
|
),
|
|
);
|
|
expect(out).toContain(
|
|
'<title>t</title><!--CMS:HERO-PRELOAD--><link rel="preload" as="image" href="/assets/hero-8-abc.jpg" fetchpriority="high"><!--/CMS:HERO-PRELOAD--></head>',
|
|
);
|
|
});
|
|
|
|
it('finds the image when src comes before class', () => {
|
|
const out = injectHeroPreload(
|
|
page('<img src="/a.jpg" alt="" class="cms-hero-image">'),
|
|
);
|
|
expect(out).toContain('href="/a.jpg"');
|
|
});
|
|
|
|
it('leaves a page without a hero, without a head and a done page alone', () => {
|
|
const plain = page('<img src="/a.jpg" alt="">');
|
|
expect(injectHeroPreload(plain)).toBe(plain);
|
|
const noHead = '<img class="cms-hero-image" src="/a.jpg">';
|
|
expect(injectHeroPreload(noHead)).toBe(noHead);
|
|
const once = injectHeroPreload(
|
|
page('<img class="cms-hero-image" src="/a.jpg" alt="">'),
|
|
);
|
|
expect(injectHeroPreload(once)).toBe(once);
|
|
});
|
|
});
|