shoc-frontend-new/src/test/domain/work-orders/utils/format-audit-timestamp.test.ts
Codex Review Integration e46e42df69 fix(work-orders): show full audit timestamps and previous type values (SH-361, SH-363)
Audit Log entries now show date and time for every entry instead of a
time-only stamp for manual changes. Type and Severity entries read
'Changed Type from X to Y', a severity cleared by a type correction reads
'from SEV N to —', and the generic fallback no longer renders a raw
FieldChanged action name.
2026-09-16 11:43:34 -03:00

34 lines
1.2 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { formatAuditTimestamp } from "@/domain/work-orders/utils/format-audit-timestamp";
describe("formatAuditTimestamp (SH-361)", () => {
it("includes the calendar date and the time for an ISO audit time", () => {
const iso = "2026-09-15T19:42:00";
const date = new Date(iso);
const expectedDate = date.toLocaleDateString("en-US", {
month: "2-digit",
day: "2-digit",
year: "numeric",
});
const formatted = formatAuditTimestamp(iso);
expect(formatted).toBe(`${expectedDate} · 7:42 PM`);
expect(formatted).toMatch(/^\d{2}\/\d{2}\/\d{4} · \d{1,2}:\d{2} (AM|PM)$/);
});
it("distinguishes the same time of day on different dates", () => {
expect(formatAuditTimestamp("2026-09-14T09:48:00")).not.toBe(
formatAuditTimestamp("2026-09-15T09:48:00"),
);
});
it("keeps pre-formatted or unparseable strings unchanged", () => {
expect(formatAuditTimestamp("· 7:42 PM")).toBe("· 7:42 PM");
expect(formatAuditTimestamp("09/15/2026 · 7:42 PM")).toBe("09/15/2026 · 7:42 PM");
});
it("returns an empty string when there is no time", () => {
expect(formatAuditTimestamp("")).toBe("");
});
});