Hero from the CMS: markers HERO-HTML and HERO-PRELOAD, hero key in the data block, picture per ratio, baked fallback
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>
This commit is contained in:
@@ -74,6 +74,8 @@ describe('markers in de gebouwde pagina', () => {
|
||||
'OFFERINGS-HTML',
|
||||
'BANNER-TOP-HTML',
|
||||
'BANNER-BOTTOM-HTML',
|
||||
'HERO-HTML',
|
||||
'HERO-PRELOAD',
|
||||
]) {
|
||||
expect(home.split(`<!--CMS:${marker}-->`)).toHaveLength(2);
|
||||
expect(home.split(`<!--/CMS:${marker}-->`)).toHaveLength(2);
|
||||
@@ -337,3 +339,86 @@ describe('zonder host die injecteert', () => {
|
||||
expect(messages).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
const hostHero = (extra: Record<string, unknown> = {}) => ({
|
||||
display: 'slideshow',
|
||||
title: 'Nieuwe titel',
|
||||
tagline: 'Nieuw label',
|
||||
buttons: [{ label: 'Boek nu', target: '#contact' }],
|
||||
slides: ['een', 'twee'].map((name) => ({
|
||||
id: name,
|
||||
alt: `Alt ${name}`,
|
||||
decorative: false,
|
||||
image: {
|
||||
width: 100,
|
||||
height: 80,
|
||||
focus: { x: 0.25, y: 0.75 },
|
||||
src: '/favicon.png',
|
||||
variants: [],
|
||||
},
|
||||
})),
|
||||
...extra,
|
||||
});
|
||||
|
||||
describe('de hero van de host', () => {
|
||||
it('schrijft de eerste foto, de titel en de preload in de HTML', async () => {
|
||||
inject({ offerings: FIVE, banners: NO_BANNERS, hero: hostHero() });
|
||||
const home = await html('/');
|
||||
const region = home.slice(
|
||||
home.indexOf('<!--CMS:HERO-HTML-->'),
|
||||
home.indexOf('<!--/CMS:HERO-HTML-->'),
|
||||
);
|
||||
expect(region).toContain('Nieuwe titel');
|
||||
expect(region).toContain('alt="Alt een"');
|
||||
expect(region).not.toContain('Alt twee');
|
||||
expect(region).toContain('style="object-position:25% 75%"');
|
||||
expect(region).toContain('href="#contact"');
|
||||
expect(home).toContain(
|
||||
'<!--CMS:HERO-PRELOAD--><link rel="preload" as="image" href="/favicon.png" fetchpriority="high"><!--/CMS:HERO-PRELOAD-->',
|
||||
);
|
||||
});
|
||||
|
||||
it('toont na hydratatie de slides van de host, zonder API-verzoek', async () => {
|
||||
inject({ offerings: FIVE, banners: NO_BANNERS, hero: hostHero() });
|
||||
const requested: string[] = [];
|
||||
const { page, messages } = await openPage(server.origin + '/', {
|
||||
prepare: async (p) => {
|
||||
p.on('request', (request) => {
|
||||
if (request.url().includes('/api/v1/hero')) {
|
||||
requested.push(request.url());
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
await waitForHydration(page);
|
||||
await eventually(() =>
|
||||
page.locator('[aria-roledescription="carousel"] h1').textContent(),
|
||||
).toContain('Nieuwe titel');
|
||||
expect(
|
||||
await page
|
||||
.locator('[aria-roledescription="carousel"] img')
|
||||
.first()
|
||||
.getAttribute('alt'),
|
||||
).toBe('Alt een');
|
||||
expect(requested).toEqual([]);
|
||||
expect(messages).toEqual([]);
|
||||
});
|
||||
|
||||
it('laat de gebakken hero staan als de data niet bruikbaar is', async () => {
|
||||
inject({
|
||||
offerings: FIVE,
|
||||
banners: NO_BANNERS,
|
||||
hero: hostHero({ slides: [] }),
|
||||
});
|
||||
const home = await html('/');
|
||||
// The data block still holds what the host sent; the region keeps the
|
||||
// baked hero
|
||||
const region = home.slice(
|
||||
home.indexOf('<!--CMS:HERO-HTML-->'),
|
||||
home.indexOf('<!--/CMS:HERO-HTML-->'),
|
||||
);
|
||||
expect(region).not.toContain('Nieuwe titel');
|
||||
expect(region).toContain('Andrea Slop');
|
||||
expect(home).toContain('<!--CMS:HERO-PRELOAD--><link');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user