' +
+ ``,
+ }}
+ />
+ );
+}
diff --git a/web/src/components/CmsRegion/CmsRegion.test.tsx b/web/src/components/CmsRegion/CmsRegion.test.tsx
new file mode 100644
index 0000000..28f664b
--- /dev/null
+++ b/web/src/components/CmsRegion/CmsRegion.test.tsx
@@ -0,0 +1,51 @@
+import { renderToString } from 'react-dom/server';
+import { screen } from '@testing-library/react';
+import { describe, expect, it } from 'vitest';
+import { renderWithProviders } from '@/test/renderWithProviders';
+import CmsDataIsland from './CmsDataIsland';
+import CmsRegion from './CmsRegion';
+
+describe('CmsRegion', () => {
+ it('is plain HTML between two markers on the server', () => {
+ const html = renderToString(
+
',
+ );
+ expect(html).not.toContain('gestijld');
+ });
+
+ it('shows the styled content once it runs in the browser', async () => {
+ await renderWithProviders(
+
,
+ );
+ expect(screen.getByText('gestijld')).toBeInTheDocument();
+ });
+});
+
+describe('CmsDataIsland', () => {
+ it('writes the marker and the baked block, hidden, with the build as source', () => {
+ const html = renderToString(
`,
+ }}
+ />
+ );
+ }
return (
- {topBanner && (
-
-
-
- )}
+ {/* Packages and banners are CMS data: the CMS host may rewrite
+ them in the HTML it sends (CmsRegion), so they are plain
+ HTML until the page has hydrated */}
+
+ {topBanner && (
+
+
+
+ )}
+
{/* Wrapping flex, not a grid: a grid leaves the last row at
the left. Every card is exactly a third of the row minus
the gaps, so the cards of a full row line up and an
incomplete last row is centred. */}
-
+
+ {shown.map((pkg, index) => (
+
+
+
+ ))}
+
+
+
- {shown.map((pkg, index) => (
-
-
+ {banner && (
+
+
- ))}
-
- {banner && (
-
-
-
- )}
+ )}
+
);
diff --git a/web/src/lib/cmsData.test.ts b/web/src/lib/cmsData.test.ts
index 9ba2080..6c2473c 100644
--- a/web/src/lib/cmsData.test.ts
+++ b/web/src/lib/cmsData.test.ts
@@ -1,6 +1,9 @@
import { describe, expect, it } from 'vitest';
import {
bakedCmsData,
+ BUILD_SOURCE,
+ hostCmsData,
+ liveFromData,
parseCmsData,
rawBanner,
rawOfferings,
@@ -132,3 +135,64 @@ describe('the baked block', () => {
).toEqual(['newborn', 'gezin']);
});
});
+
+const docWith = (json: string) =>
+ ({
+ getElementById: () => ({ textContent: json }),
+ }) as unknown as Document;
+
+describe('hostCmsData', () => {
+ it('is the block the host wrote', () => {
+ expect(hostCmsData(docWith('{"offerings":[]}'))?.offerings).toEqual([]);
+ });
+
+ it('is null for the block the build baked, and for no block', () => {
+ const baked = JSON.stringify(
+ bakedCmsData('https://andreaslop.nl', packages, null, null),
+ );
+ expect(parseCmsData(baked)?.source).toBe(BUILD_SOURCE);
+ expect(hostCmsData(docWith(baked))).toBeNull();
+ expect(
+ hostCmsData({ getElementById: () => null } as unknown as Document),
+ ).toBeNull();
+ });
+});
+
+describe('liveFromData', () => {
+ it('gives nothing for no data', () => {
+ expect(liveFromData(null)).toBeNull();
+ });
+
+ it('takes only what the block has', () => {
+ expect(liveFromData({ siteUrl: 'https://andreaslop.nl' })).toEqual({});
+ });
+
+ it('trusts the host: an empty or unusable list is no packages', () => {
+ expect(liveFromData({ offerings: [] })).toEqual({ packages: [] });
+ expect(liveFromData({ offerings: [{ slug: 'Bad Slug' }] })).toEqual({
+ packages: [],
+ });
+ expect(
+ liveFromData({
+ offerings: [
+ { slug: 'x', title: 'X', price: '€ 5', features: ['a'] },
+ ],
+ })?.packages?.map((pkg) => pkg.id),
+ ).toEqual(['x']);
+ });
+
+ it('maps both banners, null meaning none and an unusable answer too', () => {
+ expect(liveFromData({ banners: { top: null, bottom: null } })).toEqual({
+ topBanner: null,
+ banner: null,
+ });
+ expect(
+ liveFromData({
+ banners: { top: { text: 'Boven' }, bottom: { title: '' } },
+ }),
+ ).toEqual({
+ topBanner: { title: undefined, text: 'Boven', link: undefined },
+ banner: null,
+ });
+ });
+});
diff --git a/web/src/lib/cmsData.ts b/web/src/lib/cmsData.ts
index e0cf9df..7c6fe45 100644
--- a/web/src/lib/cmsData.ts
+++ b/web/src/lib/cmsData.ts
@@ -1,7 +1,12 @@
import type { PricingBanner, PricingPackage } from '@/content/types';
-import { formatPrice } from './formatPrice';
-import type { OfferingTopBanner } from './offerings';
-import { resolveSiteUrl } from './siteUrl';
+import { formatPrice } from './formatPrice.ts';
+import {
+ mapBanner,
+ mapOfferings,
+ mapTopBanner,
+ type OfferingTopBanner,
+} from './offerings.ts';
+import { resolveSiteUrl } from './siteUrl.ts';
// The data island of a page: what the CMS host writes into
//