shoc-frontend-new/src/test/domain/work-orders/utils/wizard-date-utils.test.ts
arthur.bassi e2a11926e0 fix(work-orders): use local calendar day for completedDate
Restore todayIso() after parent merge reintroduced UTC slice, and keep the wizard-date-utils regression test.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-10 19:03:07 -03:00

57 lines
1.6 KiB
TypeScript
Raw 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 { afterEach, describe, expect, it, vi } from "vitest";
import {
fmtDateRange,
fmtShortDate,
pad2,
rangeDayCount,
todayIso,
} 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);
});
});
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);
}
});
});