Files
AndreaSlopFotografie/web/src/lib/shootOptions.test.ts
SluijsensandClaude Sonnet 5.5 a1444b7b2a Adds the captcha frame hosts to the CSP and handles a widget that cannot load
frame-src gets the three exact Friendly Captcha global hosts (no wildcard).
When the widget errors, is blocked or shows no sign of life, the form says so
and offers the mail button instead of blocking silently. Adds an e2e for the
form with a mocked API, a draft privacy text for approval, and label tests.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-10 23:27:29 +01:00

57 lines
2.3 KiB
TypeScript

import fc from 'fast-check';
import { describe, expect, it } from 'vitest';
import packages from '../content/packages';
import { anyPackage } from '../test/arbitraries';
import { OTHER_SHOOT, shootOptions } from './shootOptions';
import { visiblePackages } from './visiblePackages';
describe('shootOptions', () => {
it('lists the live packages, then Overig', () => {
expect(shootOptions(packages)).toEqual([
{ value: 'Zwangerschap', label: 'Zwangerschap' },
{ value: 'Newborn', label: 'Newborn' },
{ value: 'Gezin', label: 'Gezin' },
{ value: 'Overig', label: 'Overig' },
]);
});
it('is the shown packages in order followed by Overig (invariant)', () => {
fc.assert(
fc.property(fc.array(anyPackage), (input) => {
const options = shootOptions(input);
expect(options.at(-1)).toEqual(OTHER_SHOOT);
expect(options.slice(0, -1)).toEqual(
visiblePackages(input).map((pkg) => ({
value: pkg.name,
label: pkg.name,
})),
);
}),
);
});
it('has 1 to 100 characters per label and no double values (the subject limits)', () => {
const options = shootOptions(packages);
for (const option of options) {
expect(option.label.length).toBeGreaterThanOrEqual(1);
expect(option.label.length).toBeLessThanOrEqual(100);
// The label is what is sent, so the value is the label
expect(option.value).toBe(option.label);
}
expect(new Set(options.map((o) => o.value)).size).toBe(options.length);
});
it('keeps a label with special characters unchanged through the JSON of the payload (round trip)', () => {
fc.assert(
fc.property(
fc.string({ minLength: 1, maxLength: 100 }),
fc.constantFrom('&', "'", '"', '<', '>'),
(text, special) => {
const label = `${special}${text}${special}`.slice(0, 100);
const payload = JSON.stringify({ subject: label });
expect(JSON.parse(payload).subject).toBe(label);
},
),
);
});
});