Files
local-cal/tests/event-date-format.test.ts

33 lines
1.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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:0011: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");
});
});