2026-07-02 11:45:21 -04:00
|
|
|
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(
|
2026-09-20 00:28:47 -04:00
|
|
|
messageAriaLabel('Alice', ts, { hour24Clock: true, dateFormatString: 'D MMM YYYY' }),
|
|
|
|
|
'Alice, 1 Jul 2026 14:30',
|
2026-07-02 11:45:21 -04:00
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2026-09-20 00:28:47 -04:00
|
|
|
test('messageAriaLabel honours the 12-hour clock and date-format preferences', () => {
|
2026-07-02 11:45:21 -04:00
|
|
|
const ts = dayjs('2026-07-01T14:30:00').valueOf();
|
|
|
|
|
assert.equal(
|
2026-09-20 00:28:47 -04:00
|
|
|
messageAriaLabel('Bob', ts, { hour24Clock: false, dateFormatString: 'MM/DD/YYYY' }),
|
|
|
|
|
'Bob, 07/01/2026 02:30 PM',
|
2026-07-02 11:45:21 -04:00
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('messageAriaLabel keeps the sender name verbatim as plain text', () => {
|
|
|
|
|
const ts = dayjs('2026-07-01T09:05:00').valueOf();
|
2026-09-20 00:28:47 -04:00
|
|
|
const label = messageAriaLabel('@user:example.org', ts, {
|
|
|
|
|
hour24Clock: true,
|
|
|
|
|
dateFormatString: '',
|
|
|
|
|
});
|
2026-07-02 11:45:21 -04:00
|
|
|
assert.ok(label.startsWith('@user:example.org, '));
|
|
|
|
|
assert.ok(!label.includes('<'));
|
|
|
|
|
});
|