ptitlutins/test/utils/formatDateRange.test.ts
2026-06-10 23:37:21 +02:00

31 lines
1.2 KiB
TypeScript
Raw Permalink 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, it, expect } from "vitest"
import { formatDateRange } from "../../app/utils/formatDateRange"
describe("formatDateRange", () => {
it("returns a single full date when both ISO datetimes fall on the same day", () => {
const out = formatDateRange("2026-06-13T08:00:00Z", "2026-06-13T22:30:00Z")
expect(out).toContain("juin 2026")
expect(out).not.toContain(" ")
expect(out).toBe("13 juin 2026")
})
it("collapses the start day when same month different day", () => {
const out = formatDateRange("2026-06-13T10:00:00Z", "2026-06-14T18:00:00Z")
expect(out).toBe("13 14 juin 2026")
})
it("renders both full dates with months when the range crosses months", () => {
const out = formatDateRange("2026-06-28T10:00:00Z", "2026-07-02T18:00:00Z")
expect(out).toContain(" ")
expect(out).toContain("juin")
expect(out).toContain("juillet")
expect(out).toBe("28 juin 2026 2 juillet 2026")
})
it("renders both full dates when the range crosses years", () => {
const out = formatDateRange("2026-12-30T10:00:00Z", "2027-01-02T18:00:00Z")
expect(out).toContain(" ")
expect(out).toContain("2026")
expect(out).toContain("2027")
})
})