Files
cinny/src/app/utils/a11y.test.ts
T

31 lines
1.0 KiB
TypeScript
Raw Normal View History

import { test } from 'node:test';
import assert from 'node:assert/strict';
import dayjs from 'dayjs';
import { messageAriaLabel } from './a11y';
test('messageAriaLabel composes sender, date and time (24h)', () => {
const ts = dayjs('2026-07-01T14:30:00').valueOf();
assert.equal(
messageAriaLabel('Alice', ts, { hour24Clock: true, dateFormatString: 'D MMM YYYY' }),
'Alice, 1 Jul 2026 14:30',
);
});
test('messageAriaLabel honours the 12-hour clock and date-format preferences', () => {
const ts = dayjs('2026-07-01T14:30:00').valueOf();
assert.equal(
messageAriaLabel('Bob', ts, { hour24Clock: false, dateFormatString: 'MM/DD/YYYY' }),
'Bob, 07/01/2026 02:30 PM',
);
});
test('messageAriaLabel keeps the sender name verbatim as plain text', () => {
const ts = dayjs('2026-07-01T09:05:00').valueOf();
const label = messageAriaLabel('@user:example.org', ts, {
hour24Clock: true,
dateFormatString: '',
});
assert.ok(label.startsWith('@user:example.org, '));
assert.ok(!label.includes('<'));
});