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); }, ), ); }); });