Packages and banners from the CMS, host injection, translation files and the contact form #19
@@ -12,6 +12,8 @@ Source: `GET /api/v1/offerings`. One list feeds the price cards on the home page
|
||||
1. At build time `web/config/fetchOfferings.ts` (the first step of `pnpm build`) asks `OFFERINGS_URL` (10 s timeout, 2 attempts) and writes the gitignored `web/src/content/offerings.generated.json`. The packages are baked into the prerendered HTML (search engines see the prices, no layout jump).
|
||||
2. Without `OFFERINGS_URL`, with a CMS that is down or with an unusable answer, the committed `web/src/content/offerings.snapshot.json` is used. The build never fails and never shows empty prices; the log says which source was used. Tests always use the snapshot.
|
||||
3. After hydration `PackagesProvider` (`web/src/components/PackagesProvider/`) asks the CMS once and replaces the baked list only if the answer differs. A network error, time-out (8 s), bad status or invalid answer keeps what was baked. A change in the CMS therefore shows at once; the nightly build only matters for search engines.
|
||||
- **Featured package** (the star in the CMS admin, field `featured`): the card gets a heidegroen rule along its top, a heidegroen border and a small "Uitgelicht" tab on the top edge (`PriceCard`). The tab is positioned on the border, so the cards of a row keep the same layout. Any number of cards may be featured.
|
||||
- **Description, price note and button label** (`description`, `priceNote`, `ctaLabel`) are optional in the CMS and the site does not use them: they are not shown and a card never depends on them (empty, `null` or absent all give the same card; covered by tests).
|
||||
- **Scheduling in the CMS:** the API only returns packages that are live at the moment of the request (switched on and inside their from/to dates), so the site shows them and nothing else. The baked list reflects the moment of the build; the live refresh after hydration corrects it for every visitor, and the nightly build corrects it for search engines. A package that goes live or expires between two builds is therefore right in the browser but can be stale in the HTML until the next build.
|
||||
- **Keep the snapshot current** when the real packages change (prices, features), because production builds use it (see "Reverse proxy" below).
|
||||
|
||||
|
||||
@@ -42,4 +42,40 @@ describe('PriceCard', () => {
|
||||
expect(link).toHaveTextContent('Boek je shoot');
|
||||
expect(link).toHaveAttribute('href', '/?pakket=bruiloft#contact');
|
||||
});
|
||||
|
||||
it('marks a featured package with a tab and leaves others plain', async () => {
|
||||
const { container } = await renderWithProviders(
|
||||
<>
|
||||
<PriceCard pkg={{ ...newborn, featured: true }} />
|
||||
<PriceCard pkg={packages[0]} />
|
||||
</>,
|
||||
);
|
||||
const featured = screen.getByTestId('price-card-newborn');
|
||||
expect(featured).toHaveAttribute('data-featured', 'true');
|
||||
expect(within(featured).getByText('Uitgelicht')).toBeInTheDocument();
|
||||
const plain = screen.getByTestId(`price-card-${packages[0].id}`);
|
||||
expect(plain).not.toHaveAttribute('data-featured');
|
||||
expect(within(plain).queryByText('Uitgelicht')).not.toBeInTheDocument();
|
||||
expect(await axeResults(container)).toHaveNoViolations();
|
||||
});
|
||||
|
||||
it('does not depend on the description, price note or button label', async () => {
|
||||
await renderWithProviders(
|
||||
<PriceCard
|
||||
pkg={{
|
||||
...newborn,
|
||||
description: 'Een beschrijving',
|
||||
priceNote: 'Een notitie',
|
||||
ctaLabel: 'Een knop',
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
const card = screen.getByTestId('price-card-newborn');
|
||||
expect(card).not.toHaveTextContent('Een beschrijving');
|
||||
expect(card).not.toHaveTextContent('Een notitie');
|
||||
expect(card).not.toHaveTextContent('Een knop');
|
||||
expect(
|
||||
within(card).getByRole('link', { name: 'Boek Newborn' }),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -17,6 +17,12 @@ type PriceCardProps = {
|
||||
|
||||
// One package (design .price-card): name, price, what is included and a
|
||||
// link that takes the visitor to the contact form with this package chosen.
|
||||
// A featured package (the star in the CMS) gets the quiet highlight of the
|
||||
// banners: a heidegroen rule along the top, a heidegroen border and a small
|
||||
// "Uitgelicht" tab on the top edge. The tab sits on the border instead of in
|
||||
// the card, so the cards of a row keep the same layout. The package's
|
||||
// description and price note from the CMS are not shown, so the card never
|
||||
// depends on them.
|
||||
export default function PriceCard({ pkg }: PriceCardProps) {
|
||||
const label = bookLabel(pkg.name);
|
||||
const linkButton = useRecipe({ key: 'linkButton' });
|
||||
@@ -25,6 +31,8 @@ export default function PriceCard({ pkg }: PriceCardProps) {
|
||||
<Box
|
||||
as="article"
|
||||
data-testid={`price-card-${pkg.id}`}
|
||||
data-featured={pkg.featured ? 'true' : undefined}
|
||||
position="relative"
|
||||
display="flex"
|
||||
flexDirection="column"
|
||||
h="100%"
|
||||
@@ -32,11 +40,31 @@ export default function PriceCard({ pkg }: PriceCardProps) {
|
||||
py="clamp(2rem, 3.5vw, 3rem)"
|
||||
bg="white"
|
||||
borderWidth="1px"
|
||||
borderColor="line"
|
||||
borderColor={pkg.featured ? 'accent' : 'line'}
|
||||
// The rule is an inset shadow, so it adds no width to the border
|
||||
boxShadow={
|
||||
pkg.featured ? 'inset 0 3px 0 {colors.accent}' : undefined
|
||||
}
|
||||
// No hover effect on the card itself (owner's choice); only the
|
||||
// booking button reacts
|
||||
textAlign="center"
|
||||
>
|
||||
{pkg.featured && (
|
||||
<Text
|
||||
textStyle="eyebrow"
|
||||
position="absolute"
|
||||
top="0"
|
||||
left="50%"
|
||||
transform="translate(-50%, -50%)"
|
||||
px={3}
|
||||
py={1}
|
||||
bg="accent.deep"
|
||||
color="white"
|
||||
whiteSpace="nowrap"
|
||||
>
|
||||
Uitgelicht
|
||||
</Text>
|
||||
)}
|
||||
{/* Smaller than the design's 1.75rem: stays clearly below the
|
||||
30px section h2 (owner's request) */}
|
||||
<Heading as="h3" fontSize="1.5rem" mb={3}>
|
||||
|
||||
@@ -125,6 +125,22 @@ describe('mapOfferings', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('mapOfferings without description, price note and button label', () => {
|
||||
const bare = { slug: 'x', title: 'X', price: '€ 100', features: ['a'] };
|
||||
|
||||
it.each([
|
||||
['absent', {}],
|
||||
['null', { description: null, priceNote: null, ctaLabel: null }],
|
||||
['empty', { description: '', priceNote: ' ', ctaLabel: '' }],
|
||||
])('still gives the card when they are %s', (_name, extra) => {
|
||||
const mapped = mapOfferings([{ ...bare, ...extra }]);
|
||||
expect(mapped?.packages).toHaveLength(1);
|
||||
expect(mapped?.packages[0]).toMatchObject({ id: 'x', price: 100 });
|
||||
expect(mapped?.packages[0].description).toBeUndefined();
|
||||
expect(mapped?.packages[0].priceNote).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('mapBanner', () => {
|
||||
it('neemt titel, tekst en een volledige link', () => {
|
||||
expect(
|
||||
|
||||
Reference in New Issue
Block a user