test: tighten resizable divider assertions

This commit is contained in:
Peter Steinberger
2026-05-11 07:26:35 +01:00
parent bcb61b8ac7
commit 7ec38cc88f

View File

@@ -80,6 +80,11 @@ function dispatchPointer(target: EventTarget, type: string, clientX: number) {
);
}
function expectLastResizeRatio(resized: ReturnType<typeof vi.fn>, splitRatio: number) {
const event = resized.mock.lastCall?.[0] as CustomEvent<{ splitRatio: number }> | undefined;
expect(event?.detail.splitRatio).toBe(splitRatio);
}
describe("resizable-divider", () => {
beforeEach(() => {
if (!globalThis.PointerEvent) {
@@ -135,9 +140,7 @@ describe("resizable-divider", () => {
});
divider.dispatchEvent(arrowLeft);
expect(arrowLeft.defaultPrevented).toBe(true);
expect(resized).toHaveBeenLastCalledWith(
expect.objectContaining({ detail: { splitRatio: 0.58 } }),
);
expectLastResizeRatio(resized, 0.58);
const arrowRight = new KeyboardEvent("keydown", {
key: "ArrowRight",
@@ -147,19 +150,13 @@ describe("resizable-divider", () => {
});
divider.dispatchEvent(arrowRight);
expect(arrowRight.defaultPrevented).toBe(true);
expect(resized).toHaveBeenLastCalledWith(
expect.objectContaining({ detail: { splitRatio: 0.65 } }),
);
expectLastResizeRatio(resized, 0.65);
divider.dispatchEvent(new KeyboardEvent("keydown", { key: "Home", bubbles: true }));
expect(resized).toHaveBeenLastCalledWith(
expect.objectContaining({ detail: { splitRatio: 0.4 } }),
);
expectLastResizeRatio(resized, 0.4);
divider.dispatchEvent(new KeyboardEvent("keydown", { key: "End", bubbles: true }));
expect(resized).toHaveBeenLastCalledWith(
expect.objectContaining({ detail: { splitRatio: 0.7 } }),
);
expectLastResizeRatio(resized, 0.7);
});
it("uses pointer events for mouse, pen, and touch dragging", async () => {
@@ -179,9 +176,7 @@ describe("resizable-divider", () => {
expect(setPointerCapture).toHaveBeenCalledWith(7);
dispatchPointer(document, "pointermove", 220);
expect(resized).toHaveBeenLastCalledWith(
expect.objectContaining({ detail: { splitRatio: 0.7 } }),
);
expectLastResizeRatio(resized, 0.7);
dispatchPointer(document, "pointerup", 220);
expect(divider.classList.contains("dragging")).toBe(false);