29 lines
1004 B
TypeScript
29 lines
1004 B
TypeScript
|
|
import { test } from 'node:test';
|
||
|
|
import assert from 'node:assert/strict';
|
||
|
|
import dayjs from 'dayjs';
|
||
|
|
import { messageAriaLabel } from './a11y';
|
||
|
|
import { timeDayMonthYear, timeHourMinute } from './time';
|
||
|
|
|
||
|
|
test('messageAriaLabel composes sender, date and time (24h)', () => {
|
||
|
|
const ts = dayjs('2026-07-01T14:30:00').valueOf();
|
||
|
|
assert.equal(
|
||
|
|
messageAriaLabel('Alice', ts, true),
|
||
|
|
`Alice, ${timeDayMonthYear(ts)} ${timeHourMinute(ts, true)}`,
|
||
|
|
);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('messageAriaLabel honours the 12-hour clock preference', () => {
|
||
|
|
const ts = dayjs('2026-07-01T14:30:00').valueOf();
|
||
|
|
assert.equal(
|
||
|
|
messageAriaLabel('Bob', ts, false),
|
||
|
|
`Bob, ${timeDayMonthYear(ts)} ${timeHourMinute(ts, false)}`,
|
||
|
|
);
|
||
|
|
});
|
||
|
|
|
||
|
|
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, true);
|
||
|
|
assert.ok(label.startsWith('@user:example.org, '));
|
||
|
|
assert.ok(!label.includes('<'));
|
||
|
|
});
|