2026-08-10 19:03:07 -03:00
|
|
|
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
2026-07-17 10:45:59 -03:00
|
|
|
|
import {
|
|
|
|
|
|
fmtDateRange,
|
|
|
|
|
|
fmtShortDate,
|
2026-08-10 19:03:07 -03:00
|
|
|
|
pad2,
|
2026-07-17 10:45:59 -03:00
|
|
|
|
rangeDayCount,
|
2026-08-10 19:03:07 -03:00
|
|
|
|
todayIso,
|
2026-07-17 10:45:59 -03:00
|
|
|
|
} from "@/domain/work-orders/utils/wizard-date-utils";
|
|
|
|
|
|
|
|
|
|
|
|
describe("fmtShortDate", () => {
|
|
|
|
|
|
it("formats ISO dates as Mon D", () => {
|
|
|
|
|
|
expect(fmtShortDate("2026-06-08")).toBe("Jun 8");
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it("returns em dash for invalid input", () => {
|
|
|
|
|
|
expect(fmtShortDate("")).toBe("—");
|
|
|
|
|
|
expect(fmtShortDate("nope")).toBe("—");
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe("fmtDateRange", () => {
|
|
|
|
|
|
it("joins start and end with en dash", () => {
|
|
|
|
|
|
expect(fmtDateRange("2026-06-08", "2026-06-12")).toBe("Jun 8 – Jun 12");
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe("rangeDayCount", () => {
|
|
|
|
|
|
it("counts inclusive days order-independently", () => {
|
|
|
|
|
|
expect(rangeDayCount("2026-06-08", "2026-06-12")).toBe(5);
|
|
|
|
|
|
expect(rangeDayCount("2026-06-12", "2026-06-08")).toBe(5);
|
|
|
|
|
|
expect(rangeDayCount("2026-06-08", "2026-06-08")).toBe(1);
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
2026-08-10 19:03:07 -03:00
|
|
|
|
|
|
|
|
|
|
describe("todayIso", () => {
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
|
|
vi.useRealTimers();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it("uses local calendar day, not UTC ISO date, near midnight", () => {
|
|
|
|
|
|
// 02:30 UTC is still the previous local evening in Americas (UTC−N).
|
|
|
|
|
|
vi.useFakeTimers();
|
|
|
|
|
|
vi.setSystemTime(new Date("2026-08-11T02:30:00.000Z"));
|
|
|
|
|
|
|
|
|
|
|
|
const now = new Date();
|
|
|
|
|
|
const expectedLocal = `${now.getFullYear()}-${pad2(now.getMonth() + 1)}-${pad2(now.getDate())}`;
|
|
|
|
|
|
const utcSlice = now.toISOString().slice(0, 10);
|
|
|
|
|
|
|
|
|
|
|
|
expect(todayIso()).toBe(expectedLocal);
|
|
|
|
|
|
expect(utcSlice).toBe("2026-08-11");
|
|
|
|
|
|
|
|
|
|
|
|
if (now.getTimezoneOffset() > 0) {
|
|
|
|
|
|
expect(todayIso()).toBe("2026-08-10");
|
|
|
|
|
|
expect(todayIso()).not.toBe(utcSlice);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|