feat: default journal period to last 7 days
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { compareDateDesc, isValidPeriod, moscowDate } from "./calendar";
|
||||
import {
|
||||
compareDateDesc,
|
||||
defaultPeriod,
|
||||
isValidPeriod,
|
||||
moscowDate,
|
||||
} from "./calendar";
|
||||
import { calendarDate } from "./calendar.schema";
|
||||
|
||||
describe("calendar dates", () => {
|
||||
@@ -33,6 +38,15 @@ describe("calendar dates", () => {
|
||||
expect(moscowDate(new Date("2026-12-31T21:00:00Z"))).toBe("2027-01-01");
|
||||
});
|
||||
|
||||
it("defaults to the last 7 days including today", () => {
|
||||
const [from, to] = defaultPeriod();
|
||||
|
||||
expect(calendarDate.safeParse(from).success).toBe(true);
|
||||
expect(to).toBe(moscowDate(new Date()));
|
||||
expect((Date.parse(to) - Date.parse(from)) / 86_400_000).toBe(6);
|
||||
expect(from <= to).toBe(true);
|
||||
});
|
||||
|
||||
it("compares dates newest first and keeps dateless rows last", () => {
|
||||
const dates = [null, "2026-01-01", "2026-03-01", "2026-02-01"];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user