Files
AndreaSlopFotografie/web/src/lib/shootLinks.test.ts
T
SluijsensandClaude Opus 5.5 e92b652061 Adds the Contact page
The contact page in the approved layout: the form next to a photo with
the contact card on wide screens, and the card with a small portrait
above the form on phones, where the large photo is never downloaded.
/contact?pakket= preselects a package. The page is indexed, with its
own title, description, preview image and ContactPage structured data.
Over mij and Soorten fotoshoots now link to /contact. The green button
gets a darker background, so its white text meets the contrast minimum.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 19:27:18 +01:00

95 lines
3.1 KiB
TypeScript

import fc from 'fast-check';
import { describe, expect, it } from 'vitest';
import packages from '../content/packages';
import shootTypes from '../content/shootTypes';
import sitePages from '../sitePages';
import { anyPackage, shootType } from '../test/arbitraries';
import {
isPortfolioLive,
shootContactLink,
shootPortfolioLink,
} from './shootLinks';
import { visiblePackages } from './visiblePackages';
const shoot = (id: string) => shootTypes.find((item) => item.id === id)!;
describe('shootContactLink', () => {
it('preselects the package of a shoot that has one', () => {
expect(shootContactLink(shoot('newborn'), packages)).toEqual({
to: '/contact',
search: { pakket: 'newborn' },
});
});
it('links without a package for a shoot that has none', () => {
expect(shootContactLink(shoot('loveshoot'), packages)).toEqual({
to: '/contact',
});
});
it('leaves out a package that is not shown', () => {
expect(
shootContactLink(
shoot('gezin'),
packages.filter((pkg) => pkg.id !== 'gezin'),
),
).toEqual({ to: '/contact' });
});
it('always goes to the contact page (invariant)', () => {
fc.assert(
fc.property(shootType, fc.array(anyPackage), (item, list) => {
return shootContactLink(item, list).to === '/contact';
}),
);
});
it('only preselects a shown package, and then exactly that one (invariant)', () => {
fc.assert(
fc.property(shootType, fc.array(anyPackage), (item, list) => {
const link = shootContactLink(item, list);
const shownIds = visiblePackages(list).map((pkg) => pkg.id);
const expected = shownIds.includes(item.packageId ?? '');
expect(link.search !== undefined).toBe(expected);
if (link.search !== undefined) {
expect(link.search.pakket).toBe(item.packageId);
expect(shownIds).toContain(link.search.pakket);
}
}),
);
});
});
describe('shootPortfolioLink', () => {
it('filters the portfolio on the shoot type (invariant)', () => {
fc.assert(
fc.property(shootType, (item) => {
expect(shootPortfolioLink(item)).toEqual({
to: '/portfolio',
search: { shoot: item.id },
});
}),
);
});
});
describe('isPortfolioLive', () => {
it('follows whether the portfolio page is indexed', () => {
expect(isPortfolioLive(sitePages)).toBe(
sitePages['/portfolio'].indexed,
);
expect(
isPortfolioLive({
...sitePages,
'/portfolio': { ...sitePages['/portfolio'], indexed: true },
}),
).toBe(true);
expect(
isPortfolioLive({
...sitePages,
'/portfolio': { ...sitePages['/portfolio'], indexed: false },
}),
).toBe(false);
});
});