33 lines
1.0 KiB
TypeScript
33 lines
1.0 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
||
import { addDays } from "date-fns";
|
||
import { formatEventRangeLabel, formatEventStartLabel } from "@/lib/event-date-format";
|
||
|
||
describe("event-date-format", () => {
|
||
test("formats a timed start-only event with a friendly day label", () => {
|
||
const today = new Date();
|
||
today.setHours(10, 0, 0, 0);
|
||
|
||
expect(formatEventStartLabel(today.toISOString(), false)).toContain("Today · 10:00");
|
||
});
|
||
|
||
test("formats a same-day timed range without native locale helpers", () => {
|
||
const today = new Date();
|
||
today.setHours(10, 0, 0, 0);
|
||
const end = new Date(today);
|
||
end.setHours(11, 30, 0, 0);
|
||
|
||
expect(
|
||
formatEventRangeLabel({ start: today.toISOString(), end: end.toISOString(), allDay: false }),
|
||
).toContain("10:00–11:30");
|
||
});
|
||
|
||
test("formats all-day events with tomorrow labels when applicable", () => {
|
||
const tomorrow = addDays(new Date(), 1);
|
||
tomorrow.setHours(0, 0, 0, 0);
|
||
|
||
expect(
|
||
formatEventRangeLabel({ start: tomorrow.toISOString(), end: undefined, allDay: true }),
|
||
).toBe("Tomorrow");
|
||
});
|
||
});
|