diff --git a/ui/src/ui/components/resizable-divider.test.ts b/ui/src/ui/components/resizable-divider.test.ts index 71e2237398a..a98af9d3b92 100644 --- a/ui/src/ui/components/resizable-divider.test.ts +++ b/ui/src/ui/components/resizable-divider.test.ts @@ -80,6 +80,11 @@ function dispatchPointer(target: EventTarget, type: string, clientX: number) { ); } +function expectLastResizeRatio(resized: ReturnType, 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);