feat: Remove GA code from binding (#9042)

Co-authored-by: dwelle <5153846+dwelle@users.noreply.github.com>
This commit is contained in:
Márk Tolmács 2025-02-25 22:52:06 +01:00 committed by GitHub
parent 31e8476c78
commit 0ffeaeaecf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
44 changed files with 2112 additions and 1832 deletions

View file

@ -197,7 +197,7 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"fillStyle": "solid",
"frameId": null,
"groupIds": [],
"height": 99,
"height": "102.35417",
"id": "id172",
"index": "a2",
"isDeleted": false,
@ -211,8 +211,8 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
0,
],
[
"98.20800",
99,
"101.77517",
"102.35417",
],
],
"roughness": 1,
@ -227,8 +227,8 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"type": "arrow",
"updated": 1,
"version": 40,
"width": "98.20800",
"x": 1,
"width": "101.77517",
"x": "0.70711",
"y": 0,
}
`;
@ -294,24 +294,22 @@ History {
"deleted": {
"endBinding": {
"elementId": "id171",
"fixedPoint": null,
"focus": "0.00990",
"gap": 1,
},
"height": "0.98017",
"height": "0.98597",
"points": [
[
0,
0,
],
[
98,
"-0.98017",
"98.58579",
"-0.98597",
],
],
"startBinding": {
"elementId": "id170",
"fixedPoint": null,
"focus": "0.02970",
"gap": 1,
},
@ -319,24 +317,22 @@ History {
"inserted": {
"endBinding": {
"elementId": "id171",
"fixedPoint": null,
"focus": "-0.02000",
"gap": 1,
},
"height": "0.00169",
"height": "0.00119",
"points": [
[
0,
0,
],
[
98,
"0.00169",
"98.58579",
"0.00119",
],
],
"startBinding": {
"elementId": "id170",
"fixedPoint": null,
"focus": "0.02000",
"gap": 1,
},
@ -393,15 +389,15 @@ History {
"focus": 0,
"gap": 1,
},
"height": 99,
"height": "102.35417",
"points": [
[
0,
0,
],
[
"98.20800",
99,
"101.77517",
"102.35417",
],
],
"startBinding": null,
@ -410,28 +406,26 @@ History {
"inserted": {
"endBinding": {
"elementId": "id171",
"fixedPoint": null,
"focus": "0.00990",
"gap": 1,
},
"height": "0.98161",
"height": "0.98700",
"points": [
[
0,
0,
],
[
98,
"-0.98161",
"98.58579",
"-0.98700",
],
],
"startBinding": {
"elementId": "id170",
"fixedPoint": null,
"focus": "0.02970",
"gap": 1,
},
"y": "0.99245",
"y": "0.99465",
},
},
"id175" => Delta {
@ -824,7 +818,7 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"type": "arrow",
"updated": 1,
"version": 30,
"width": 0,
"width": 50,
"x": 200,
"y": 0,
}
@ -858,7 +852,7 @@ History {
0,
],
[
0,
50,
0,
],
],
@ -934,8 +928,7 @@ History {
"inserted": {
"endBinding": {
"elementId": "id166",
"fixedPoint": null,
"focus": 0,
"focus": -0,
"gap": 1,
},
"points": [
@ -944,13 +937,12 @@ History {
0,
],
[
0,
50,
0,
],
],
"startBinding": {
"elementId": "id165",
"fixedPoint": null,
"focus": 0,
"gap": 1,
},
@ -1246,7 +1238,7 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"fillStyle": "solid",
"frameId": null,
"groupIds": [],
"height": "2.61991",
"height": "2.52823",
"id": "id178",
"index": "Zz",
"isDeleted": false,
@ -1260,8 +1252,8 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
0,
],
[
"98.00000",
"-2.61991",
"98.58579",
"-2.52823",
],
],
"roughness": 1,
@ -1284,9 +1276,9 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"type": "arrow",
"updated": 1,
"version": 11,
"width": "98.00000",
"x": "1.00000",
"y": "3.98333",
"width": "98.58579",
"x": "0.70711",
"y": "3.82861",
}
`;
@ -1617,7 +1609,7 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"fillStyle": "solid",
"frameId": null,
"groupIds": [],
"height": "2.61991",
"height": "2.52823",
"id": "id181",
"index": "a0",
"isDeleted": false,
@ -1631,8 +1623,8 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
0,
],
[
"98.00000",
"-2.61991",
"98.58579",
"-2.52823",
],
],
"roughness": 1,
@ -1655,9 +1647,9 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"type": "arrow",
"updated": 1,
"version": 11,
"width": "98.00000",
"x": "1.00000",
"y": "3.98333",
"width": "98.58579",
"x": "0.70711",
"y": "3.82861",
}
`;
@ -1775,7 +1767,7 @@ History {
"fillStyle": "solid",
"frameId": null,
"groupIds": [],
"height": "22.36242",
"height": "22.07000",
"index": "a0",
"isDeleted": false,
"lastCommittedPoint": null,
@ -1788,8 +1780,8 @@ History {
0,
],
[
"98.00000",
"-22.36242",
"99.27949",
"-22.07000",
],
],
"roughness": 1,
@ -1810,9 +1802,9 @@ History {
"strokeStyle": "solid",
"strokeWidth": 2,
"type": "arrow",
"width": "98.00000",
"x": 1,
"y": 34,
"width": "99.27949",
"x": "0.01341",
"y": "33.34227",
},
"inserted": {
"isDeleted": true,
@ -2322,14 +2314,13 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"endArrowhead": "arrow",
"endBinding": {
"elementId": "id185",
"fixedPoint": null,
"focus": 0,
"focus": -0,
"gap": 1,
},
"fillStyle": "solid",
"frameId": null,
"groupIds": [],
"height": "408.19672",
"height": "410.63965",
"id": "id186",
"index": "a2",
"isDeleted": false,
@ -2343,8 +2334,8 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
0,
],
[
498,
"-408.19672",
"501.24760",
"-410.63965",
],
],
"roughness": 1,
@ -2354,7 +2345,6 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"startArrowhead": null,
"startBinding": {
"elementId": "id184",
"fixedPoint": null,
"focus": 0,
"gap": 1,
},
@ -2364,8 +2354,8 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"type": "arrow",
"updated": 1,
"version": 10,
"width": 498,
"x": 1,
"width": "501.24760",
"x": "0.70711",
"y": 0,
}
`;
@ -2484,8 +2474,7 @@ History {
"endArrowhead": "arrow",
"endBinding": {
"elementId": "id185",
"fixedPoint": null,
"focus": 0,
"focus": -0,
"gap": 1,
},
"fillStyle": "solid",
@ -2515,7 +2504,6 @@ History {
"startArrowhead": null,
"startBinding": {
"elementId": "id184",
"fixedPoint": null,
"focus": 0,
"gap": 1,
},
@ -15122,8 +15110,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"endArrowhead": "arrow",
"endBinding": {
"elementId": "id58",
"fixedPoint": null,
"focus": 0,
"focus": -0,
"gap": 1,
},
"fillStyle": "solid",
@ -15143,7 +15130,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
0,
],
[
"98.00000",
"98.58579",
0,
],
],
@ -15154,7 +15141,6 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"startArrowhead": null,
"startBinding": {
"elementId": "id56",
"fixedPoint": null,
"focus": 0,
"gap": 1,
},
@ -15164,8 +15150,8 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"type": "arrow",
"updated": 1,
"version": 10,
"width": "98.00000",
"x": 1,
"width": "98.58579",
"x": "0.70711",
"y": 0,
}
`;
@ -15493,8 +15479,7 @@ History {
"endArrowhead": "arrow",
"endBinding": {
"elementId": "id58",
"fixedPoint": null,
"focus": 0,
"focus": -0,
"gap": 1,
},
"fillStyle": "solid",
@ -15524,7 +15509,6 @@ History {
"startArrowhead": null,
"startBinding": {
"elementId": "id56",
"fixedPoint": null,
"focus": 0,
"gap": 1,
},
@ -15821,8 +15805,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"endArrowhead": "arrow",
"endBinding": {
"elementId": "id52",
"fixedPoint": null,
"focus": 0,
"focus": -0,
"gap": 1,
},
"fillStyle": "solid",
@ -15842,7 +15825,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
0,
],
[
"98.00000",
"98.58579",
0,
],
],
@ -15853,7 +15836,6 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"startArrowhead": null,
"startBinding": {
"elementId": "id50",
"fixedPoint": null,
"focus": 0,
"gap": 1,
},
@ -15863,8 +15845,8 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"type": "arrow",
"updated": 1,
"version": 10,
"width": "98.00000",
"x": 1,
"width": "98.58579",
"x": "0.70711",
"y": 0,
}
`;
@ -16116,8 +16098,7 @@ History {
"endArrowhead": "arrow",
"endBinding": {
"elementId": "id52",
"fixedPoint": null,
"focus": 0,
"focus": -0,
"gap": 1,
},
"fillStyle": "solid",
@ -16147,7 +16128,6 @@ History {
"startArrowhead": null,
"startBinding": {
"elementId": "id50",
"fixedPoint": null,
"focus": 0,
"gap": 1,
},
@ -16444,8 +16424,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"endArrowhead": "arrow",
"endBinding": {
"elementId": "id64",
"fixedPoint": null,
"focus": 0,
"focus": -0,
"gap": 1,
},
"fillStyle": "solid",
@ -16465,7 +16444,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
0,
],
[
"98.00000",
"98.58579",
0,
],
],
@ -16476,7 +16455,6 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"startArrowhead": null,
"startBinding": {
"elementId": "id62",
"fixedPoint": null,
"focus": 0,
"gap": 1,
},
@ -16486,8 +16464,8 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"type": "arrow",
"updated": 1,
"version": 10,
"width": "98.00000",
"x": 1,
"width": "98.58579",
"x": "0.70711",
"y": 0,
}
`;
@ -16739,8 +16717,7 @@ History {
"endArrowhead": "arrow",
"endBinding": {
"elementId": "id64",
"fixedPoint": null,
"focus": 0,
"focus": -0,
"gap": 1,
},
"fillStyle": "solid",
@ -16770,7 +16747,6 @@ History {
"startArrowhead": null,
"startBinding": {
"elementId": "id62",
"fixedPoint": null,
"focus": 0,
"gap": 1,
},
@ -17065,8 +17041,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"endArrowhead": "arrow",
"endBinding": {
"elementId": "id70",
"fixedPoint": null,
"focus": 0,
"focus": -0,
"gap": 1,
},
"fillStyle": "solid",
@ -17086,7 +17061,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
0,
],
[
"98.00000",
"98.58579",
0,
],
],
@ -17097,7 +17072,6 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"startArrowhead": null,
"startBinding": {
"elementId": "id68",
"fixedPoint": null,
"focus": 0,
"gap": 1,
},
@ -17107,8 +17081,8 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"type": "arrow",
"updated": 1,
"version": 10,
"width": "98.00000",
"x": 1,
"width": "98.58579",
"x": "0.70711",
"y": 0,
}
`;
@ -17170,7 +17144,6 @@ History {
],
"startBinding": {
"elementId": "id68",
"fixedPoint": null,
"focus": 0,
"gap": 1,
},
@ -17431,8 +17404,7 @@ History {
"endArrowhead": "arrow",
"endBinding": {
"elementId": "id70",
"fixedPoint": null,
"focus": 0,
"focus": -0,
"gap": 1,
},
"fillStyle": "solid",
@ -17462,7 +17434,6 @@ History {
"startArrowhead": null,
"startBinding": {
"elementId": "id68",
"fixedPoint": null,
"focus": 0,
"gap": 1,
},
@ -17783,8 +17754,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"endArrowhead": "arrow",
"endBinding": {
"elementId": "id77",
"fixedPoint": null,
"focus": 0,
"focus": -0,
"gap": 1,
},
"fillStyle": "solid",
@ -17804,7 +17774,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
0,
],
[
"98.00000",
"98.58579",
0,
],
],
@ -17815,7 +17785,6 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"startArrowhead": null,
"startBinding": {
"elementId": "id75",
"fixedPoint": null,
"focus": 0,
"gap": 1,
},
@ -17825,8 +17794,8 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"type": "arrow",
"updated": 1,
"version": 11,
"width": "98.00000",
"x": 1,
"width": "98.58579",
"x": "0.70711",
"y": 0,
}
`;
@ -17887,8 +17856,7 @@ History {
"deleted": {
"endBinding": {
"elementId": "id77",
"fixedPoint": null,
"focus": 0,
"focus": -0,
"gap": 1,
},
"points": [
@ -17903,7 +17871,6 @@ History {
],
"startBinding": {
"elementId": "id75",
"fixedPoint": null,
"focus": 0,
"gap": 1,
},
@ -18165,8 +18132,7 @@ History {
"endArrowhead": "arrow",
"endBinding": {
"elementId": "id77",
"fixedPoint": null,
"focus": 0,
"focus": -0,
"gap": 1,
},
"fillStyle": "solid",
@ -18196,7 +18162,6 @@ History {
"startArrowhead": null,
"startBinding": {
"elementId": "id75",
"fixedPoint": null,
"focus": 0,
"gap": 1,
},

View file

@ -190,14 +190,13 @@ exports[`move element > rectangles with binding arrow 7`] = `
"endArrowhead": "arrow",
"endBinding": {
"elementId": "id1",
"fixedPoint": null,
"focus": "-0.46667",
"gap": 10,
},
"fillStyle": "solid",
"frameId": null,
"groupIds": [],
"height": "81.47368",
"height": "84.41974",
"id": "id2",
"index": "a2",
"isDeleted": false,
@ -211,8 +210,8 @@ exports[`move element > rectangles with binding arrow 7`] = `
0,
],
[
81,
"81.47368",
"83.92893",
"84.41974",
],
],
"roughness": 1,
@ -223,7 +222,6 @@ exports[`move element > rectangles with binding arrow 7`] = `
"startArrowhead": null,
"startBinding": {
"elementId": "id0",
"fixedPoint": null,
"focus": "-0.60000",
"gap": 10,
},
@ -234,7 +232,7 @@ exports[`move element > rectangles with binding arrow 7`] = `
"updated": 1,
"version": 11,
"versionNonce": 1051383431,
"width": 81,
"width": "83.92893",
"x": 110,
"y": 50,
}

View file

@ -64,7 +64,6 @@ describe("element binding", () => {
expect(arrow.startBinding).toEqual({
elementId: rect.id,
fixedPoint: null,
focus: expect.toBeNonNaNNumber(),
gap: expect.toBeNonNaNNumber(),
});
@ -77,13 +76,11 @@ describe("element binding", () => {
// Both the start and the end points should be bound
expect(arrow.startBinding).toEqual({
elementId: rect.id,
fixedPoint: null,
focus: expect.toBeNonNaNNumber(),
gap: expect.toBeNonNaNNumber(),
});
expect(arrow.endBinding).toEqual({
elementId: rect.id,
fixedPoint: null,
focus: expect.toBeNonNaNNumber(),
gap: expect.toBeNonNaNNumber(),
});

View file

@ -9,6 +9,7 @@ import {
togglePopover,
getCloneByOrigId,
} from "./test-utils";
import "../../utils/test-utils";
import { Excalidraw } from "../index";
import { Keyboard, Pointer, UI } from "./helpers/ui";
import { API } from "./helpers/api";
@ -1321,13 +1322,11 @@ describe("history", () => {
expect(API.getUndoStack().length).toBe(5);
expect(arrow.startBinding).toEqual({
elementId: rect1.id,
fixedPoint: null,
focus: expect.toBeNonNaNNumber(),
gap: expect.toBeNonNaNNumber(),
});
expect(arrow.endBinding).toEqual({
elementId: rect2.id,
fixedPoint: null,
focus: expect.toBeNonNaNNumber(),
gap: expect.toBeNonNaNNumber(),
});
@ -1346,13 +1345,11 @@ describe("history", () => {
expect(API.getRedoStack().length).toBe(1);
expect(arrow.startBinding).toEqual({
elementId: rect1.id,
fixedPoint: null,
focus: expect.toBeNonNaNNumber(),
gap: expect.toBeNonNaNNumber(),
});
expect(arrow.endBinding).toEqual({
elementId: rect2.id,
fixedPoint: null,
focus: expect.toBeNonNaNNumber(),
gap: expect.toBeNonNaNNumber(),
});
@ -1371,13 +1368,11 @@ describe("history", () => {
expect(API.getRedoStack().length).toBe(0);
expect(arrow.startBinding).toEqual({
elementId: rect1.id,
fixedPoint: null,
focus: expect.toBeNonNaNNumber(),
gap: expect.toBeNonNaNNumber(),
});
expect(arrow.endBinding).toEqual({
elementId: rect2.id,
fixedPoint: null,
focus: expect.toBeNonNaNNumber(),
gap: expect.toBeNonNaNNumber(),
});
@ -1404,13 +1399,11 @@ describe("history", () => {
expect(API.getRedoStack().length).toBe(0);
expect(arrow.startBinding).toEqual({
elementId: rect1.id,
fixedPoint: null,
focus: expect.toBeNonNaNNumber(),
gap: expect.toBeNonNaNNumber(),
});
expect(arrow.endBinding).toEqual({
elementId: rect2.id,
fixedPoint: null,
focus: expect.toBeNonNaNNumber(),
gap: expect.toBeNonNaNNumber(),
});
@ -1429,13 +1422,11 @@ describe("history", () => {
expect(API.getRedoStack().length).toBe(1);
expect(arrow.startBinding).toEqual({
elementId: rect1.id,
fixedPoint: null,
focus: expect.toBeNonNaNNumber(),
gap: expect.toBeNonNaNNumber(),
});
expect(arrow.endBinding).toEqual({
elementId: rect2.id,
fixedPoint: null,
focus: expect.toBeNonNaNNumber(),
gap: expect.toBeNonNaNNumber(),
});
@ -1486,13 +1477,11 @@ describe("history", () => {
id: arrow.id,
startBinding: expect.objectContaining({
elementId: rect1.id,
fixedPoint: null,
focus: expect.toBeNonNaNNumber(),
gap: expect.toBeNonNaNNumber(),
}),
endBinding: expect.objectContaining({
elementId: rect2.id,
fixedPoint: null,
focus: expect.toBeNonNaNNumber(),
gap: expect.toBeNonNaNNumber(),
}),
@ -1533,13 +1522,11 @@ describe("history", () => {
id: arrow.id,
startBinding: expect.objectContaining({
elementId: rect1.id,
fixedPoint: null,
focus: expect.toBeNonNaNNumber(),
gap: expect.toBeNonNaNNumber(),
}),
endBinding: expect.objectContaining({
elementId: rect2.id,
fixedPoint: null,
focus: expect.toBeNonNaNNumber(),
gap: expect.toBeNonNaNNumber(),
}),
@ -1614,13 +1601,11 @@ describe("history", () => {
id: arrow.id,
startBinding: expect.objectContaining({
elementId: rect1.id,
fixedPoint: null,
focus: expect.toBeNonNaNNumber(),
gap: expect.toBeNonNaNNumber(),
}),
endBinding: expect.objectContaining({
elementId: rect2.id,
fixedPoint: null,
focus: expect.toBeNonNaNNumber(),
gap: expect.toBeNonNaNNumber(),
}),
@ -1689,13 +1674,11 @@ describe("history", () => {
id: arrow.id,
startBinding: expect.objectContaining({
elementId: rect1.id,
fixedPoint: null,
focus: expect.toBeNonNaNNumber(),
gap: expect.toBeNonNaNNumber(),
}),
endBinding: expect.objectContaining({
elementId: rect2.id,
fixedPoint: null,
focus: expect.toBeNonNaNNumber(),
gap: expect.toBeNonNaNNumber(),
}),
@ -4276,13 +4259,11 @@ describe("history", () => {
id: arrowId,
startBinding: expect.objectContaining({
elementId: rect1.id,
fixedPoint: null,
focus: expect.toBeNonNaNNumber(),
gap: expect.toBeNonNaNNumber(),
}),
endBinding: expect.objectContaining({
elementId: rect2.id,
fixedPoint: null,
focus: expect.toBeNonNaNNumber(),
gap: expect.toBeNonNaNNumber(),
}),
@ -4347,13 +4328,11 @@ describe("history", () => {
id: arrowId,
startBinding: expect.objectContaining({
elementId: rect1.id,
fixedPoint: null,
focus: expect.toBeNonNaNNumber(),
gap: expect.toBeNonNaNNumber(),
}),
endBinding: expect.objectContaining({
elementId: rect2.id,
fixedPoint: null,
focus: expect.toBeNonNaNNumber(),
gap: expect.toBeNonNaNNumber(),
}),
@ -4414,13 +4393,11 @@ describe("history", () => {
id: arrowId,
startBinding: expect.objectContaining({
elementId: rect1.id,
fixedPoint: null,
focus: expect.toBeNonNaNNumber(),
gap: expect.toBeNonNaNNumber(),
}),
endBinding: expect.objectContaining({
elementId: rect2.id,
fixedPoint: null,
focus: expect.toBeNonNaNNumber(),
gap: expect.toBeNonNaNNumber(),
}),
@ -4489,14 +4466,12 @@ describe("history", () => {
id: arrowId,
startBinding: expect.objectContaining({
elementId: rect1.id,
fixedPoint: null,
focus: expect.toBeNonNaNNumber(),
gap: expect.toBeNonNaNNumber(),
}),
// rebound with previous rectangle
endBinding: expect.objectContaining({
elementId: rect2.id,
fixedPoint: null,
focus: expect.toBeNonNaNNumber(),
gap: expect.toBeNonNaNNumber(),
}),
@ -4788,14 +4763,12 @@ describe("history", () => {
id: arrowId,
startBinding: expect.objectContaining({
elementId: rect1.id,
fixedPoint: null,
focus: 0,
gap: 1,
}),
endBinding: expect.objectContaining({
elementId: rect2.id,
fixedPoint: null,
focus: 0,
focus: -0,
gap: 1,
}),
isDeleted: true,
@ -4838,13 +4811,11 @@ describe("history", () => {
id: arrowId,
startBinding: expect.objectContaining({
elementId: rect1.id,
fixedPoint: null,
focus: expect.toBeNonNaNNumber(),
gap: expect.toBeNonNaNNumber(),
}),
endBinding: expect.objectContaining({
elementId: rect2.id,
fixedPoint: null,
focus: expect.toBeNonNaNNumber(),
gap: expect.toBeNonNaNNumber(),
}),

View file

@ -1238,7 +1238,7 @@ describe("Test Linear Elements", () => {
mouse.downAt(rect.x, rect.y);
mouse.moveTo(200, 0);
mouse.upAt(200, 0);
expect(arrow.width).toBe(200);
expect(arrow.width).toBeCloseTo(204, 0);
expect(rect.x).toBe(200);
expect(rect.y).toBe(0);
expect(handleBindTextResizeSpy).toHaveBeenCalledWith(

View file

@ -123,7 +123,7 @@ describe("move element", () => {
expect([rectB.x, rectB.y]).toEqual([201, 2]);
expect([Math.round(arrow.x), Math.round(arrow.y)]).toEqual([110, 50]);
expect([Math.round(arrow.width), Math.round(arrow.height)]).toEqual([
81, 81,
84, 84,
]);
h.elements.forEach((element) => expect(element).toMatchSnapshot());

View file

@ -181,12 +181,12 @@ describe("generic element", () => {
UI.resize(rectangle, "e", [40, 0]);
expect(arrow.width + arrow.endBinding!.gap).toBeCloseTo(30);
expect(arrow.width + arrow.endBinding!.gap).toBeCloseTo(30, 0);
UI.resize(rectangle, "w", [50, 0]);
expect(arrow.endBinding?.elementId).toEqual(rectangle.id);
expect(arrow.width + arrow.endBinding!.gap).toBeCloseTo(80);
expect(arrow.width + arrow.endBinding!.gap).toBeCloseTo(80, 0);
});
it("resizes with a label", async () => {
@ -501,12 +501,12 @@ describe("arrow element", () => {
h.state,
)[0] as ExcalidrawElbowArrowElement;
expect(arrow.startBinding?.fixedPoint?.[0]).toBeCloseTo(1.05);
expect(arrow.startBinding?.fixedPoint?.[0]).toBeCloseTo(1);
expect(arrow.startBinding?.fixedPoint?.[1]).toBeCloseTo(0.75);
UI.resize(rectangle, "se", [-200, -150]);
expect(arrow.startBinding?.fixedPoint?.[0]).toBeCloseTo(1.05);
expect(arrow.startBinding?.fixedPoint?.[0]).toBeCloseTo(1);
expect(arrow.startBinding?.fixedPoint?.[1]).toBeCloseTo(0.75);
});
@ -529,13 +529,13 @@ describe("arrow element", () => {
h.state,
)[0] as ExcalidrawElbowArrowElement;
expect(arrow.startBinding?.fixedPoint?.[0]).toBeCloseTo(1.05);
expect(arrow.startBinding?.fixedPoint?.[0]).toBeCloseTo(1);
expect(arrow.startBinding?.fixedPoint?.[1]).toBeCloseTo(0.75);
UI.resize([rectangle, arrow], "nw", [300, 350]);
expect(arrow.startBinding?.fixedPoint?.[0]).toBeCloseTo(-0.144);
expect(arrow.startBinding?.fixedPoint?.[1]).toBeCloseTo(0.25);
expect(arrow.startBinding?.fixedPoint?.[0]).toBeCloseTo(-0.13);
expect(arrow.startBinding?.fixedPoint?.[1]).toBeCloseTo(0.11);
});
});
@ -811,15 +811,16 @@ describe("image element", () => {
UI.resize(image, "ne", [40, 0]);
expect(arrow.width + arrow.endBinding!.gap).toBeCloseTo(30);
expect(arrow.width + arrow.endBinding!.gap).toBeCloseTo(31, 0);
const imageWidth = image.width;
const scale = 20 / image.height;
UI.resize(image, "nw", [50, 20]);
expect(arrow.endBinding?.elementId).toEqual(image.id);
expect(arrow.width + arrow.endBinding!.gap).toBeCloseTo(
expect(Math.floor(arrow.width + arrow.endBinding!.gap)).toBeCloseTo(
30 + imageWidth * scale,
0,
);
});
});
@ -1024,7 +1025,7 @@ describe("multiple selection", () => {
expect(leftBoundArrow.x).toBeCloseTo(-110);
expect(leftBoundArrow.y).toBeCloseTo(50);
expect(leftBoundArrow.width).toBeCloseTo(140, 0);
expect(leftBoundArrow.width).toBeCloseTo(143, 0);
expect(leftBoundArrow.height).toBeCloseTo(7, 0);
expect(leftBoundArrow.angle).toEqual(0);
expect(leftBoundArrow.startBinding).toBeNull();
@ -1046,7 +1047,9 @@ describe("multiple selection", () => {
expect(rightBoundArrow.endBinding?.elementId).toBe(
rightArrowBinding.elementId,
);
expect(rightBoundArrow.endBinding?.focus).toBe(rightArrowBinding.focus);
expect(rightBoundArrow.endBinding?.focus).toBeCloseTo(
rightArrowBinding.focus!,
);
});
it("resizes with labeled arrows", async () => {

View file

@ -32,7 +32,7 @@ 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(110.7, 1);
expect(arrow.width).toBeCloseTo(116.7, 1);
expect(arrow.height).toBeCloseTo(0);
});
@ -69,8 +69,8 @@ test("unselected bound arrows update when rotating their target elements", async
expect(ellipseArrow.x).toEqual(0);
expect(ellipseArrow.y).toEqual(0);
expect(ellipseArrow.points[0]).toEqual([0, 0]);
expect(ellipseArrow.points[1][0]).toBeCloseTo(48.5, 1);
expect(ellipseArrow.points[1][1]).toBeCloseTo(126.5, 1);
expect(ellipseArrow.points[1][0]).toBeCloseTo(48.98, 1);
expect(ellipseArrow.points[1][1]).toBeCloseTo(125.79, 1);
expect(textArrow.endBinding?.elementId).toEqual(text.id);
expect(textArrow.x).toEqual(360);

View file

@ -16,7 +16,6 @@ import { STORAGE_KEYS } from "../../../excalidraw-app/app_constants";
import { getSelectedElements } from "../scene/selection";
import type { ExcalidrawElement } from "../element/types";
import { UI } from "./helpers/ui";
import { diffStringsUnified } from "jest-diff";
import ansi from "ansicolor";
import { ORIG_ID } from "../constants";
import { arrayToMap } from "../utils";
@ -259,36 +258,6 @@ expect.extend({
pass: false,
};
},
toCloselyEqualPoints(received, expected, precision) {
if (!Array.isArray(received) || !Array.isArray(expected)) {
throw new Error("expected and received are not point arrays");
}
const COMPARE = 1 / Math.pow(10, precision || 2);
const pass = received.every(
(point, idx) =>
Math.abs(expected[idx]?.[0] - point[0]) < COMPARE &&
Math.abs(expected[idx]?.[1] - point[1]) < COMPARE,
);
if (!pass) {
return {
message: () => ` The provided array of points are not close enough.
${diffStringsUnified(
JSON.stringify(expected, undefined, 2),
JSON.stringify(received, undefined, 2),
)}`,
pass: false,
};
}
return {
message: () => `expected ${received} to not be close to ${expected}`,
pass: true,
};
},
});
/**