Files
AndreaSlopFotografie/web/src/lib/emailAddress.test.ts
T
SluijsensandClaude Opus 5.5 2c2e27e337 Makes the first render match the prerendered HTML
Search values, the 404 buttons and the footer year now apply after hydration.
The e-mail address stays out of the HTML behind a placeholder, and all review
texts are in the page, so crawlers can read them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 18:17:26 +01:00

79 lines
2.6 KiB
TypeScript

import fc from 'fast-check';
import { describe, expect, it } from 'vitest';
import { anyEmail, validEmail } from '../test/arbitraries';
import { emailAddress, isEmailAddressValid } from './emailAddress';
describe('emailAddress', () => {
it('voegt geldige delen samen', () => {
expect(emailAddress({ user: 'info', domain: 'andreaslop.nl' })).toBe(
'info@andreaslop.nl',
);
});
it('geeft null bij ongeldige delen', () => {
for (const parts of [
{ user: '', domain: 'andreaslop.nl' },
{ user: 'info', domain: '' },
{ user: 'in fo', domain: 'andreaslop.nl' },
{ user: 'info@x', domain: 'andreaslop.nl' },
{ user: 'info', domain: 'andreaslop' },
{ user: 'info', domain: 'andrea@slop.nl' },
]) {
expect(emailAddress(parts)).toBeNull();
}
});
it('splitsen bij @ geeft de delen terug (round-trip)', () => {
fc.assert(
fc.property(validEmail, (parts) => {
const address = emailAddress(parts);
expect(address).not.toBeNull();
const [user, domain] = address!.split('@');
expect({ user, domain }).toEqual(parts);
}),
);
});
it('is null of bevat precies één @ en geen witruimte (invariant)', () => {
fc.assert(
fc.property(anyEmail, (parts) => {
const address = emailAddress(parts);
return (
address === null ||
(address.split('@').length === 2 && !/\s/.test(address))
);
}),
);
});
});
describe('isEmailAddressValid', () => {
it('is waar voor geldige delen', () => {
expect(
isEmailAddressValid({ user: 'info', domain: 'andreaslop.nl' }),
).toBe(true);
});
it('is onwaar bij ongeldige delen', () => {
for (const parts of [
{ user: '', domain: 'andreaslop.nl' },
{ user: 'info', domain: '' },
{ user: 'in fo', domain: 'andreaslop.nl' },
{ user: 'info', domain: 'andreaslop' },
{ user: 'info', domain: 'andrea@slop.nl' },
]) {
expect(isEmailAddressValid(parts)).toBe(false);
}
});
it('is precies dan waar als emailAddress een adres geeft (oracle)', () => {
fc.assert(
fc.property(anyEmail, (parts) => {
expect(isEmailAddressValid(parts)).toBe(
emailAddress(parts) !== null,
);
}),
);
});
});