refactor: simplify calendar and form state
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { isValidPeriod, moscowDate } from "./calendar";
|
||||
import { calendarDate } from "./calendar.schema";
|
||||
|
||||
describe("calendar dates", () => {
|
||||
it.each([
|
||||
["0000-02-29", true],
|
||||
["0001-01-01", true],
|
||||
["0099-12-31", true],
|
||||
["1900-02-29", false],
|
||||
["2000-02-29", true],
|
||||
["2024-02-29", true],
|
||||
["2026-02-29", false],
|
||||
["2026-99-99", false],
|
||||
["2026-1-01", false],
|
||||
["", false],
|
||||
])("validates %s without Date normalization", (value, valid) => {
|
||||
expect(calendarDate.safeParse(value).success).toBe(valid);
|
||||
});
|
||||
|
||||
it("accepts open or single-day periods and rejects reversed ranges", () => {
|
||||
expect(isValidPeriod(null, null)).toBe(true);
|
||||
expect(isValidPeriod(null, "2026-09-01")).toBe(true);
|
||||
expect(isValidPeriod("2026-09-01", null)).toBe(true);
|
||||
expect(isValidPeriod("2026-09-01", "2026-09-01")).toBe(true);
|
||||
expect(isValidPeriod("2026-09-02", "2026-09-01")).toBe(false);
|
||||
expect(isValidPeriod("", "2026-09-01")).toBe(false);
|
||||
});
|
||||
|
||||
it("changes the calendar day at Moscow midnight across a year boundary", () => {
|
||||
expect(moscowDate(new Date("2026-12-31T20:59:59Z"))).toBe("2026-12-31");
|
||||
expect(moscowDate(new Date("2026-12-31T21:00:00Z"))).toBe("2027-01-01");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user