import fc from 'fast-check'; import { describe, expect, it } from 'vitest'; import { mailSubject, mailtoLink } from './mailLink'; describe('mailSubject', () => { it('names the package when there is one', () => { expect(mailSubject('Newborn')).toBe('Aanvraag fotoshoot: Newborn'); expect(mailSubject()).toBe('Vraag via andreaslop.nl'); }); it('contains the package name whenever one is given (invariant)', () => { fc.assert( fc.property(fc.string({ minLength: 1 }), (name) => { expect(mailSubject(name)).toContain(name); }), ); }); }); describe('mailtoLink', () => { it('builds a mail link with an encoded subject', () => { expect(mailtoLink('a@b.nl', 'Aanvraag fotoshoot: Gezin')).toBe( 'mailto:a@b.nl?subject=Aanvraag%20fotoshoot%3A%20Gezin', ); }); it('gives back the subject when decoded (round-trip)', () => { fc.assert( fc.property(fc.string(), (subject) => { const link = mailtoLink('a@b.nl', subject); expect(link.startsWith('mailto:a@b.nl?subject=')).toBe(true); const encoded = link.slice('mailto:a@b.nl?subject='.length); expect(decodeURIComponent(encoded)).toBe(subject); }), ); }); });