49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
import { describe, it, expect } from "vitest"
|
|
import { eventDuration } from "../../app/utils/eventDuration"
|
|
|
|
describe("eventDuration", () => {
|
|
it("formats a duration under an hour as minutes", () => {
|
|
expect(
|
|
eventDuration("2026-06-08T10:00:00Z", "2026-06-08T10:23:00Z"),
|
|
).toBe("23 min")
|
|
})
|
|
|
|
it("formats a whole-hour duration without minutes", () => {
|
|
expect(
|
|
eventDuration("2026-06-08T10:00:00Z", "2026-06-08T12:00:00Z"),
|
|
).toBe("2 h")
|
|
})
|
|
|
|
it("formats hours and minutes, zero-padding the minutes", () => {
|
|
expect(
|
|
eventDuration("2026-06-08T10:00:00Z", "2026-06-08T11:30:00Z"),
|
|
).toBe("1 h 30")
|
|
expect(
|
|
eventDuration("2026-06-08T10:00:00Z", "2026-06-08T11:05:00Z"),
|
|
).toBe("1 h 05")
|
|
})
|
|
|
|
it("rounds to the nearest minute", () => {
|
|
expect(
|
|
eventDuration("2026-06-08T10:00:00Z", "2026-06-08T10:23:40Z"),
|
|
).toBe("24 min")
|
|
})
|
|
|
|
it("returns null for an equal start and end", () => {
|
|
expect(
|
|
eventDuration("2026-06-08T10:00:00Z", "2026-06-08T10:00:00Z"),
|
|
).toBeNull()
|
|
})
|
|
|
|
it("returns null for a negative duration (end before start)", () => {
|
|
expect(
|
|
eventDuration("2026-06-08T12:00:00Z", "2026-06-08T10:00:00Z"),
|
|
).toBeNull()
|
|
})
|
|
|
|
it("returns null when an argument is missing", () => {
|
|
expect(eventDuration(null, "2026-06-08T10:23:00Z")).toBeNull()
|
|
expect(eventDuration("2026-06-08T10:00:00Z", null)).toBeNull()
|
|
expect(eventDuration()).toBeNull()
|
|
})
|
|
})
|