44 lines
1.5 KiB
TypeScript
44 lines
1.5 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { computeDragDates, pixelsToDays, shiftDate } from "./dragMath.js";
|
|
|
|
describe("dragMath", () => {
|
|
it("returns zero days for invalid cell widths instead of leaking invalid drag deltas", () => {
|
|
expect(pixelsToDays(40, 0)).toBe(0);
|
|
expect(pixelsToDays(40, Number.NaN)).toBe(0);
|
|
expect(pixelsToDays(40, Number.POSITIVE_INFINITY)).toBe(0);
|
|
});
|
|
|
|
it("shifts dates without mutating the original date", () => {
|
|
const original = new Date("2026-04-10T00:00:00.000Z");
|
|
|
|
const shifted = shiftDate(original, 3);
|
|
|
|
expect(shifted.toISOString()).toBe("2026-04-13T00:00:00.000Z");
|
|
expect(original.toISOString()).toBe("2026-04-10T00:00:00.000Z");
|
|
});
|
|
|
|
it("clamps resize-start drags so the start does not cross the end", () => {
|
|
const { start, end } = computeDragDates(
|
|
"resize-start",
|
|
new Date("2026-04-10T00:00:00.000Z"),
|
|
new Date("2026-04-12T00:00:00.000Z"),
|
|
5,
|
|
);
|
|
|
|
expect(start.toISOString()).toBe("2026-04-12T00:00:00.000Z");
|
|
expect(end.toISOString()).toBe("2026-04-12T00:00:00.000Z");
|
|
});
|
|
|
|
it("clamps resize-end drags so the end does not cross the start", () => {
|
|
const { start, end } = computeDragDates(
|
|
"resize-end",
|
|
new Date("2026-04-10T00:00:00.000Z"),
|
|
new Date("2026-04-12T00:00:00.000Z"),
|
|
-5,
|
|
);
|
|
|
|
expect(start.toISOString()).toBe("2026-04-10T00:00:00.000Z");
|
|
expect(end.toISOString()).toBe("2026-04-10T00:00:00.000Z");
|
|
});
|
|
});
|