mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-03 23:43:13 +00:00
68 lines
2.1 KiB
TypeScript
68 lines
2.1 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
addDaysIso,
|
|
businessTodayIso,
|
|
dashboardRangeParams,
|
|
mondayOf,
|
|
monthEndIso,
|
|
monthStartIso,
|
|
} from "@/domain/dashboard/utils/dashboard-range-utils";
|
|
|
|
describe("businessTodayIso", () => {
|
|
it("formats the America/New_York calendar date regardless of UTC time", () => {
|
|
expect(businessTodayIso(new Date("2026-09-16T23:30:00Z"))).toBe("2026-09-16");
|
|
expect(businessTodayIso(new Date("2026-09-17T02:30:00Z"))).toBe("2026-09-16");
|
|
expect(businessTodayIso(new Date("2026-01-01T04:30:00Z"))).toBe("2025-12-31");
|
|
});
|
|
});
|
|
|
|
describe("addDaysIso", () => {
|
|
it("rolls over month and year boundaries", () => {
|
|
expect(addDaysIso("2026-01-31", 1)).toBe("2026-02-01");
|
|
expect(addDaysIso("2026-12-31", 1)).toBe("2027-01-01");
|
|
expect(addDaysIso("2026-09-14", -7)).toBe("2026-09-07");
|
|
});
|
|
});
|
|
|
|
describe("mondayOf", () => {
|
|
it("returns the Monday of the ISO week", () => {
|
|
expect(mondayOf("2026-09-16")).toBe("2026-09-14");
|
|
expect(mondayOf("2026-09-14")).toBe("2026-09-14");
|
|
expect(mondayOf("2026-09-13")).toBe("2026-09-07");
|
|
});
|
|
});
|
|
|
|
describe("monthStartIso / monthEndIso", () => {
|
|
it("returns month bounds", () => {
|
|
expect(monthStartIso("2026-09-16")).toBe("2026-09-01");
|
|
expect(monthEndIso("2026-09-16")).toBe("2026-09-30");
|
|
expect(monthEndIso("2026-02-16")).toBe("2026-02-28");
|
|
});
|
|
});
|
|
|
|
describe("dashboardRangeParams", () => {
|
|
it("maps today to the business date", () => {
|
|
expect(dashboardRangeParams("today", "2026-09-16")).toEqual({
|
|
dateFrom: "2026-09-16",
|
|
dateTo: "2026-09-16",
|
|
});
|
|
});
|
|
|
|
it("maps this week to the Monday-Friday business week", () => {
|
|
expect(dashboardRangeParams("this-week", "2026-09-16")).toEqual({
|
|
dateFrom: "2026-09-14",
|
|
dateTo: "2026-09-18",
|
|
});
|
|
});
|
|
|
|
it("maps last 3 months to the trailing month span", () => {
|
|
expect(dashboardRangeParams("last-3-months", "2026-09-16")).toEqual({
|
|
dateFrom: "2026-07-01",
|
|
dateTo: "2026-09-30",
|
|
});
|
|
});
|
|
|
|
it("maps all time to unbounded params", () => {
|
|
expect(dashboardRangeParams("all-time", "2026-09-16")).toEqual({});
|
|
});
|
|
});
|