import { renderHook } from "@testing-library/react" import { expect, test } from "vitest" import { useDateRangeFormatter } from "./useDateRangeFormatter" test.each([ // [startDate, endDate, exampleDate, exampleOutput] [ new Date("2024-01-01T00:00:00Z"), new Date("2024-01-01T00:30:00Z"), new Date("2024-01-01T00:15:00Z"), "12:15 AM", ], // 1D [ new Date("2024-01-01T00:00:00Z"), new Date("2024-01-01T12:00:00Z"), new Date("2024-01-01T06:00:00Z"), "6 AM", ], // 7D [ new Date("2024-01-01T00:00:00Z"), new Date("2024-01-08T23:59:59Z"), new Date("2024-01-03T00:15:00Z"), "Jan 3", ], // 30D [ new Date("2024-01-01T00:00:00Z"), new Date("2024-01-29T23:59:59Z"), new Date("2024-01-15T00:15:00Z"), "Jan 15", ], // 1Y [ new Date("2023-01-02T07:37:35Z"), new Date("2024-01-02T07:37:35Z"), new Date("2023-06-01T00:15:00Z"), "Jun 01, 23", ], // Over 1Y [ new Date("2022-01-01T00:00:00Z"), new Date("2024-01-01T00:00:00Z"), new Date("2023-06-01T00:00:00Z"), "Jun 01, 23", ], ])( "formats range from %s to %s", (startDate, endDate, exampleDate, expectedOutput) => { const { result } = renderHook(() => useDateRangeFormatter(startDate, endDate), ) expect(result.current(exampleDate)).toBe(expectedOutput) }, )