From 6332d1a2e2517a9ee461971e3c8f3e892f009bec Mon Sep 17 00:00:00 2001 From: Mark Tolmacs Date: Sat, 8 Nov 2025 18:40:36 +0100 Subject: [PATCH] fix: Tests --- .../tests/__snapshots__/move.test.tsx.snap | 138 ++++++++++++++++++ packages/excalidraw/tests/history.test.tsx | 6 +- packages/excalidraw/tests/move.test.tsx | 8 +- packages/excalidraw/tests/rotate.test.tsx | 8 +- 4 files changed, 149 insertions(+), 11 deletions(-) diff --git a/packages/excalidraw/tests/__snapshots__/move.test.tsx.snap b/packages/excalidraw/tests/__snapshots__/move.test.tsx.snap index 556a41c35b..16f49c8210 100644 --- a/packages/excalidraw/tests/__snapshots__/move.test.tsx.snap +++ b/packages/excalidraw/tests/__snapshots__/move.test.tsx.snap @@ -95,3 +95,141 @@ exports[`move element > rectangle 5`] = ` "y": 40, } `; + +exports[`move element > rectangles with binding arrow 5`] = ` +{ + "angle": 0, + "backgroundColor": "transparent", + "boundElements": [ + { + "id": "id6", + "type": "arrow", + }, + ], + "customData": undefined, + "fillStyle": "solid", + "frameId": null, + "groupIds": [], + "height": 100, + "id": "id0", + "index": "a0", + "isDeleted": false, + "link": null, + "locked": false, + "opacity": 100, + "roughness": 1, + "roundness": null, + "seed": 1278240551, + "strokeColor": "#1e1e1e", + "strokeStyle": "solid", + "strokeWidth": 2, + "type": "rectangle", + "updated": 1, + "version": 4, + "versionNonce": 760410951, + "width": 100, + "x": 0, + "y": 0, +} +`; + +exports[`move element > rectangles with binding arrow 6`] = ` +{ + "angle": 0, + "backgroundColor": "transparent", + "boundElements": [ + { + "id": "id6", + "type": "arrow", + }, + ], + "customData": undefined, + "fillStyle": "solid", + "frameId": null, + "groupIds": [], + "height": 300, + "id": "id3", + "index": "a1", + "isDeleted": false, + "link": null, + "locked": false, + "opacity": 100, + "roughness": 1, + "roundness": null, + "seed": 1116226695, + "strokeColor": "#1e1e1e", + "strokeStyle": "solid", + "strokeWidth": 2, + "type": "rectangle", + "updated": 1, + "version": 7, + "versionNonce": 651223591, + "width": 300, + "x": 201, + "y": 2, +} +`; + +exports[`move element > rectangles with binding arrow 7`] = ` +{ + "angle": 0, + "backgroundColor": "transparent", + "boundElements": null, + "customData": undefined, + "elbowed": false, + "endArrowhead": "arrow", + "endBinding": { + "elementId": "id3", + "fixedPoint": [ + "-0.02000", + "0.44666", + ], + "mode": "orbit", + }, + "fillStyle": "solid", + "frameId": null, + "groupIds": [], + "height": "89.98900", + "id": "id6", + "index": "a2", + "isDeleted": false, + "link": null, + "locked": false, + "moveMidPointsWithElement": false, + "opacity": 100, + "points": [ + [ + 0, + 0, + ], + [ + "89.00000", + "89.98900", + ], + ], + "roughness": 1, + "roundness": { + "type": 2, + }, + "seed": 23633383, + "startArrowhead": null, + "startBinding": { + "elementId": "id0", + "fixedPoint": [ + "1.06000", + "0.46011", + ], + "mode": "orbit", + }, + "strokeColor": "#1e1e1e", + "strokeStyle": "solid", + "strokeWidth": 2, + "type": "arrow", + "updated": 1, + "version": 14, + "versionNonce": 348321737, + "width": "89.00000", + "x": 106, + "y": "46.01050", +} +`; diff --git a/packages/excalidraw/tests/history.test.tsx b/packages/excalidraw/tests/history.test.tsx index 4ac4289751..b54dc32f15 100644 --- a/packages/excalidraw/tests/history.test.tsx +++ b/packages/excalidraw/tests/history.test.tsx @@ -1588,7 +1588,7 @@ describe("history", () => { expect(API.getUndoStack().length).toBe(5); expect(arrow.startBinding).toEqual({ elementId: rect1.id, - fixedPoint: expect.arrayContaining([1, 0.5001]), + fixedPoint: expect.arrayContaining([0.5001, 0.5001]), mode: "orbit", }); expect(arrow.endBinding).toEqual({ @@ -4621,12 +4621,12 @@ describe("history", () => { id: arrowId, startBinding: expect.objectContaining({ elementId: rect1.id, - fixedPoint: [1, 0.6], + fixedPoint: [0.6363636363636364, 0.6363636363636364], mode: "orbit", }), endBinding: expect.objectContaining({ elementId: rect2.id, - fixedPoint: [0, 0.6], + fixedPoint: [0.4109529004289598, 0.5890470995710405], mode: "orbit", }), }), diff --git a/packages/excalidraw/tests/move.test.tsx b/packages/excalidraw/tests/move.test.tsx index 6fe3d8d1a1..ac6b05008d 100644 --- a/packages/excalidraw/tests/move.test.tsx +++ b/packages/excalidraw/tests/move.test.tsx @@ -102,16 +102,16 @@ describe("move element", () => { new Pointer("mouse").clickOn(rectB); expect(renderInteractiveScene.mock.calls.length).toMatchInlineSnapshot( - `15`, + `16`, ); - expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`14`); + expect(renderStaticScene.mock.calls.length).toMatchInlineSnapshot(`15`); expect(h.state.selectionElement).toBeNull(); expect(h.elements.length).toEqual(3); expect(h.state.selectedElementIds[rectB.id]).toBeTruthy(); expect([rectA.x, rectA.y]).toEqual([0, 0]); expect([rectB.x, rectB.y]).toEqual([200, 0]); - expect([[arrow.x, arrow.y]]).toCloselyEqualPoints([[110, 50]], 0); - expect([[arrow.width, arrow.height]]).toCloselyEqualPoints([[80, 80]], 0); + expect([[arrow.x, arrow.y]]).toCloselyEqualPoints([[106, 46.011]], 0); + expect([[arrow.width, arrow.height]]).toCloselyEqualPoints([[88, 88]], 0); renderInteractiveScene.mockClear(); renderStaticScene.mockClear(); diff --git a/packages/excalidraw/tests/rotate.test.tsx b/packages/excalidraw/tests/rotate.test.tsx index 03b5f615ec..285672aa8f 100644 --- a/packages/excalidraw/tests/rotate.test.tsx +++ b/packages/excalidraw/tests/rotate.test.tsx @@ -35,8 +35,8 @@ test("unselected bound arrow updates when rotating its target element", async () expect(arrow.endBinding?.elementId).toEqual(rectangle.id); expect(arrow.x).toBeCloseTo(-80); expect(arrow.y).toBeCloseTo(50); - expect(arrow.width).toBeCloseTo(84.9, 1); - expect(arrow.height).toBeCloseTo(52.717, 1); + expect(arrow.width).toBeCloseTo(132.491, 1); + expect(arrow.height).toBeCloseTo(82.267, 1); }); test("unselected bound arrows update when rotating their target elements", async () => { @@ -73,8 +73,8 @@ test("unselected bound arrows update when rotating their target elements", async expect(ellipseArrow.x).toEqual(-10); expect(ellipseArrow.y).toEqual(80); expect(ellipseArrow.points[0]).toEqual([0, 0]); - expect(ellipseArrow.points[1][0]).toBeCloseTo(42.318, 1); - expect(ellipseArrow.points[1][1]).toBeCloseTo(92.133, 1); + expect(ellipseArrow.points[1][0]).toBeCloseTo(66.317, 1); + expect(ellipseArrow.points[1][1]).toBeCloseTo(144.38, 1); expect(textArrow.endBinding?.elementId).toEqual(text.id); expect(textArrow.x).toEqual(360);