From c23d78d42c188aef83fd9525bc58994875c134f5 Mon Sep 17 00:00:00 2001 From: Mark Tolmacs Date: Fri, 15 Aug 2025 21:58:09 +0200 Subject: [PATCH] fix(tests): Update tests --- packages/excalidraw/components/App.tsx | 38 +- .../tests/__snapshots__/history.test.tsx.snap | 619 +++++++----------- .../regressionTests.test.tsx.snap | 249 ++----- packages/excalidraw/tests/history.test.tsx | 121 ++-- .../excalidraw/tests/regressionTests.test.tsx | 1 - 5 files changed, 367 insertions(+), 661 deletions(-) diff --git a/packages/excalidraw/components/App.tsx b/packages/excalidraw/components/App.tsx index 7770436ea1..72f45c428b 100644 --- a/packages/excalidraw/components/App.tsx +++ b/packages/excalidraw/components/App.tsx @@ -8806,18 +8806,26 @@ class App extends React.Component { this.setState(newState); }); } - - this.scene.mutateElement(element, { - points: [ - ...element.points.slice(0, -1), - pointFrom( - (this.lastPointerMoveCoords?.x ?? - pointerDownState.origin.x) - element.x, - (this.lastPointerMoveCoords?.y ?? - pointerDownState.origin.y) - element.y, - ), - ], - }); + const selectedPointIndices = + this.state.selectedLinearElement?.selectedPointsIndices; + const nextPoint = pointFrom( + (this.lastPointerMoveCoords?.x ?? + pointerDownState.origin.x) - element.x, + (this.lastPointerMoveCoords?.y ?? + pointerDownState.origin.y) - element.y, + ); + if ( + selectedPointIndices?.length === 1 && + selectedPointIndices[0] === 0 + ) { + this.scene.mutateElement(element, { + points: [nextPoint, ...element.points.slice(1)], + }); + } else { + this.scene.mutateElement(element, { + points: [...element.points.slice(0, -1), nextPoint], + }); + } } this.bindModeHandler = null; @@ -9790,7 +9798,11 @@ class App extends React.Component { } if (isLinearElement(newElement)) { - if (newElement!.points.length > 1) { + if ( + newElement!.points.length > 1 && + newElement.points[1][0] !== 0 && + newElement.points[1][1] !== 0 + ) { this.store.scheduleCapture(); } const pointerCoords = viewportCoordsToSceneCoords( diff --git a/packages/excalidraw/tests/__snapshots__/history.test.tsx.snap b/packages/excalidraw/tests/__snapshots__/history.test.tsx.snap index 6bcdee65f7..47fe286a4b 100644 --- a/packages/excalidraw/tests/__snapshots__/history.test.tsx.snap +++ b/packages/excalidraw/tests/__snapshots__/history.test.tsx.snap @@ -7736,7 +7736,7 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh "strokeWidth": 2, "type": "arrow", "updated": 1, - "version": 9, + "version": 7, "width": 10, "x": 0, "y": 0, @@ -7827,59 +7827,7 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh }, }, }, - "id": "id13", - }, - { - "appState": AppStateDelta { - "delta": Delta { - "deleted": {}, - "inserted": {}, - }, - }, - "elements": { - "added": {}, - "removed": {}, - "updated": { - "id0": { - "deleted": { - "height": 10, - "lastCommittedPoint": [ - 10, - 10, - ], - "points": [ - [ - 0, - 0, - ], - [ - 10, - 10, - ], - ], - "version": 9, - "width": 10, - }, - "inserted": { - "height": 0, - "lastCommittedPoint": null, - "points": [ - [ - 0, - 0, - ], - [ - 0, - 0, - ], - ], - "version": 8, - "width": 0, - }, - }, - }, - }, - "id": "id14", + "id": "id10", }, { "appState": AppStateDelta { @@ -7903,7 +7851,7 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh "removed": {}, "updated": {}, }, - "id": "id15", + "id": "id11", }, { "appState": AppStateDelta { @@ -7927,7 +7875,7 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh "removed": {}, "updated": {}, }, - "id": "id16", + "id": "id12", }, ] `; @@ -10733,11 +10681,14 @@ exports[`history > multiplayer undo/redo > should override remotely added points "fillStyle": "solid", "frameId": null, "groupIds": [], - "height": 0, + "height": 30, "id": "id0", "index": "a0", "isDeleted": false, - "lastCommittedPoint": null, + "lastCommittedPoint": [ + 30, + 30, + ], "link": null, "locked": false, "opacity": 100, @@ -10747,8 +10698,20 @@ exports[`history > multiplayer undo/redo > should override remotely added points 0, ], [ - 0, - 0, + 5, + 5, + ], + [ + 10, + 10, + ], + [ + 15, + 15, + ], + [ + 20, + 20, ], ], "roughness": 1, @@ -10762,8 +10725,8 @@ exports[`history > multiplayer undo/redo > should override remotely added points "strokeWidth": 2, "type": "arrow", "updated": 1, - "version": 10, - "width": 0, + "version": 12, + "width": 30, "x": 0, "y": 0, } @@ -10771,131 +10734,9 @@ exports[`history > multiplayer undo/redo > should override remotely added points exports[`history > multiplayer undo/redo > should override remotely added points on undo, but restore them on redo > [end of test] number of elements 1`] = `1`; -exports[`history > multiplayer undo/redo > should override remotely added points on undo, but restore them on redo > [end of test] number of renders 1`] = `10`; +exports[`history > multiplayer undo/redo > should override remotely added points on undo, but restore them on redo > [end of test] number of renders 1`] = `12`; -exports[`history > multiplayer undo/redo > should override remotely added points on undo, but restore them on redo > [end of test] redo stack 1`] = ` -[ - { - "appState": AppStateDelta { - "delta": Delta { - "deleted": {}, - "inserted": {}, - }, - }, - "elements": { - "added": {}, - "removed": {}, - "updated": { - "id0": { - "deleted": { - "height": 10, - "lastCommittedPoint": [ - 10, - 10, - ], - "points": [ - [ - 0, - 0, - ], - [ - 10, - 10, - ], - ], - "version": 9, - "width": 10, - }, - "inserted": { - "height": 30, - "lastCommittedPoint": [ - 30, - 30, - ], - "points": [ - [ - 0, - 0, - ], - [ - 5, - 5, - ], - [ - 10, - 10, - ], - [ - 15, - 15, - ], - [ - 20, - 20, - ], - ], - "version": 8, - "width": 30, - }, - }, - }, - }, - "id": "id7", - }, - { - "appState": AppStateDelta { - "delta": Delta { - "deleted": {}, - "inserted": {}, - }, - }, - "elements": { - "added": {}, - "removed": {}, - "updated": { - "id0": { - "deleted": { - "height": 0, - "lastCommittedPoint": null, - "points": [ - [ - 0, - 0, - ], - [ - 0, - 0, - ], - ], - "version": 10, - "width": 0, - }, - "inserted": { - "height": 10, - "lastCommittedPoint": [ - 10, - 10, - ], - "points": [ - [ - 0, - 0, - ], - [ - 10, - 10, - ], - ], - "version": 9, - "width": 10, - }, - }, - }, - }, - "id": "id8", - }, -] -`; +exports[`history > multiplayer undo/redo > should override remotely added points on undo, but restore them on redo > [end of test] redo stack 1`] = `[]`; exports[`history > multiplayer undo/redo > should override remotely added points on undo, but restore them on redo > [end of test] undo stack 1`] = ` [ @@ -10932,10 +10773,13 @@ exports[`history > multiplayer undo/redo > should override remotely added points "fillStyle": "solid", "frameId": null, "groupIds": [], - "height": 0, + "height": 10, "index": "a0", "isDeleted": false, - "lastCommittedPoint": null, + "lastCommittedPoint": [ + 10, + 10, + ], "link": null, "locked": false, "opacity": 100, @@ -10945,8 +10789,8 @@ exports[`history > multiplayer undo/redo > should override remotely added points 0, ], [ - 0, - 0, + 10, + 10, ], ], "roughness": 1, @@ -10959,20 +10803,87 @@ exports[`history > multiplayer undo/redo > should override remotely added points "strokeStyle": "solid", "strokeWidth": 2, "type": "arrow", - "version": 3, - "width": 0, + "version": 11, + "width": 10, "x": 0, "y": 0, }, "inserted": { "isDeleted": true, - "version": 2, + "version": 10, }, }, }, "updated": {}, }, - "id": "id2", + "id": "id7", + }, + { + "appState": AppStateDelta { + "delta": Delta { + "deleted": {}, + "inserted": {}, + }, + }, + "elements": { + "added": {}, + "removed": {}, + "updated": { + "id0": { + "deleted": { + "height": 30, + "lastCommittedPoint": [ + 30, + 30, + ], + "points": [ + [ + 0, + 0, + ], + [ + 5, + 5, + ], + [ + 10, + 10, + ], + [ + 15, + 15, + ], + [ + 20, + 20, + ], + ], + "version": 12, + "width": 30, + }, + "inserted": { + "height": 10, + "lastCommittedPoint": [ + 10, + 10, + ], + "points": [ + [ + 0, + 0, + ], + [ + 10, + 10, + ], + ], + "version": 11, + "width": 10, + }, + }, + }, + }, + "id": "id8", }, ] `; @@ -21370,13 +21281,13 @@ exports[`history > singleplayer undo/redo > should support linear element creati "fillStyle": "solid", "frameId": null, "groupIds": [], - "height": 10, + "height": 20, "id": "id0", "index": "a0", "isDeleted": false, "lastCommittedPoint": [ - 10, - 10, + 20, + 0, ], "link": null, "locked": false, @@ -21390,6 +21301,10 @@ exports[`history > singleplayer undo/redo > should support linear element creati 10, 10, ], + [ + 20, + 20, + ], ], "roughness": 1, "roundness": { @@ -21402,8 +21317,8 @@ exports[`history > singleplayer undo/redo > should support linear element creati "strokeWidth": 2, "type": "arrow", "updated": 1, - "version": 10, - "width": 10, + "version": 14, + "width": 20, "x": 0, "y": 0, } @@ -21411,170 +21326,9 @@ exports[`history > singleplayer undo/redo > should support linear element creati exports[`history > singleplayer undo/redo > should support linear element creation and points manipulation through the editor > [end of test] number of elements 1`] = `1`; -exports[`history > singleplayer undo/redo > should support linear element creation and points manipulation through the editor > [end of test] number of renders 1`] = `17`; +exports[`history > singleplayer undo/redo > should support linear element creation and points manipulation through the editor > [end of test] number of renders 1`] = `23`; -exports[`history > singleplayer undo/redo > should support linear element creation and points manipulation through the editor > [end of test] redo stack 1`] = ` -[ - { - "appState": AppStateDelta { - "delta": Delta { - "deleted": { - "selectedLinearElement": { - "elementId": "id0", - "isEditing": true, - }, - }, - "inserted": { - "selectedLinearElement": { - "elementId": "id0", - "isEditing": false, - }, - }, - }, - }, - "elements": { - "added": {}, - "removed": {}, - "updated": {}, - }, - "id": "id14", - }, - { - "appState": AppStateDelta { - "delta": Delta { - "deleted": {}, - "inserted": {}, - }, - }, - "elements": { - "added": {}, - "removed": {}, - "updated": { - "id0": { - "deleted": { - "height": 10, - "points": [ - [ - 0, - 0, - ], - [ - 10, - 10, - ], - [ - 20, - 0, - ], - ], - "version": 9, - }, - "inserted": { - "height": 20, - "points": [ - [ - 0, - 0, - ], - [ - 10, - 10, - ], - [ - 20, - 20, - ], - ], - "version": 8, - }, - }, - }, - }, - "id": "id18", - }, - { - "appState": AppStateDelta { - "delta": Delta { - "deleted": { - "selectedLinearElement": { - "elementId": "id0", - "isEditing": false, - }, - }, - "inserted": { - "selectedLinearElement": { - "elementId": "id0", - "isEditing": true, - }, - }, - }, - }, - "elements": { - "added": {}, - "removed": {}, - "updated": {}, - }, - "id": "id19", - }, - { - "appState": AppStateDelta { - "delta": Delta { - "deleted": {}, - "inserted": {}, - }, - }, - "elements": { - "added": {}, - "removed": {}, - "updated": { - "id0": { - "deleted": { - "lastCommittedPoint": [ - 10, - 10, - ], - "points": [ - [ - 0, - 0, - ], - [ - 10, - 10, - ], - ], - "version": 10, - "width": 10, - }, - "inserted": { - "lastCommittedPoint": [ - 20, - 0, - ], - "points": [ - [ - 0, - 0, - ], - [ - 10, - 10, - ], - [ - 20, - 0, - ], - ], - "version": 9, - "width": 20, - }, - }, - }, - }, - "id": "id20", - }, -] -`; +exports[`history > singleplayer undo/redo > should support linear element creation and points manipulation through the editor > [end of test] redo stack 1`] = `[]`; exports[`history > singleplayer undo/redo > should support linear element creation and points manipulation through the editor > [end of test] undo stack 1`] = ` [ @@ -21611,10 +21365,13 @@ exports[`history > singleplayer undo/redo > should support linear element creati "fillStyle": "solid", "frameId": null, "groupIds": [], - "height": 0, + "height": 10, "index": "a0", "isDeleted": false, - "lastCommittedPoint": null, + "lastCommittedPoint": [ + 10, + 10, + ], "link": null, "locked": false, "opacity": 100, @@ -21624,8 +21381,8 @@ exports[`history > singleplayer undo/redo > should support linear element creati 0, ], [ - 0, - 0, + 10, + 10, ], ], "roughness": 1, @@ -21638,20 +21395,20 @@ exports[`history > singleplayer undo/redo > should support linear element creati "strokeStyle": "solid", "strokeWidth": 2, "type": "arrow", - "version": 3, - "width": 0, + "version": 12, + "width": 10, "x": 0, "y": 0, }, "inserted": { "isDeleted": true, - "version": 2, + "version": 11, }, }, }, "updated": {}, }, - "id": "id2", + "id": "id20", }, { "appState": AppStateDelta { @@ -21666,7 +21423,28 @@ exports[`history > singleplayer undo/redo > should support linear element creati "updated": { "id0": { "deleted": { - "height": 10, + "lastCommittedPoint": [ + 20, + 0, + ], + "points": [ + [ + 0, + 0, + ], + [ + 10, + 10, + ], + [ + 20, + 0, + ], + ], + "version": 13, + "width": 20, + }, + "inserted": { "lastCommittedPoint": [ 10, 10, @@ -21681,29 +21459,114 @@ exports[`history > singleplayer undo/redo > should support linear element creati 10, ], ], - "version": 5, + "version": 12, "width": 10, }, - "inserted": { - "height": 0, - "lastCommittedPoint": null, + }, + }, + }, + "id": "id21", + }, + { + "appState": AppStateDelta { + "delta": Delta { + "deleted": { + "selectedLinearElement": { + "elementId": "id0", + "isEditing": true, + }, + }, + "inserted": { + "selectedLinearElement": { + "elementId": "id0", + "isEditing": false, + }, + }, + }, + }, + "elements": { + "added": {}, + "removed": {}, + "updated": {}, + }, + "id": "id22", + }, + { + "appState": AppStateDelta { + "delta": Delta { + "deleted": {}, + "inserted": {}, + }, + }, + "elements": { + "added": {}, + "removed": {}, + "updated": { + "id0": { + "deleted": { + "height": 20, "points": [ [ 0, 0, ], + [ + 10, + 10, + ], + [ + 20, + 20, + ], + ], + "version": 14, + }, + "inserted": { + "height": 10, + "points": [ [ 0, 0, ], + [ + 10, + 10, + ], + [ + 20, + 0, + ], ], - "version": 3, - "width": 0, + "version": 13, }, }, }, }, - "id": "id4", + "id": "id23", + }, + { + "appState": AppStateDelta { + "delta": Delta { + "deleted": { + "selectedLinearElement": { + "elementId": "id0", + "isEditing": false, + }, + }, + "inserted": { + "selectedLinearElement": { + "elementId": "id0", + "isEditing": true, + }, + }, + }, + }, + "elements": { + "added": {}, + "removed": {}, + "updated": {}, + }, + "id": "id24", }, ] `; diff --git a/packages/excalidraw/tests/__snapshots__/regressionTests.test.tsx.snap b/packages/excalidraw/tests/__snapshots__/regressionTests.test.tsx.snap index 7aa2f42d28..b16d6d0028 100644 --- a/packages/excalidraw/tests/__snapshots__/regressionTests.test.tsx.snap +++ b/packages/excalidraw/tests/__snapshots__/regressionTests.test.tsx.snap @@ -6601,10 +6601,13 @@ exports[`regression tests > draw every type of shape > [end of test] undo stack "fillStyle": "solid", "frameId": null, "groupIds": [], - "height": 0, + "height": 10, "index": "a5", "isDeleted": false, - "lastCommittedPoint": null, + "lastCommittedPoint": [ + 50, + 10, + ], "link": null, "locked": false, "opacity": 100, @@ -6614,8 +6617,8 @@ exports[`regression tests > draw every type of shape > [end of test] undo stack 0, ], [ - 0, - 0, + 50, + 10, ], ], "roughness": 1, @@ -6628,14 +6631,14 @@ exports[`regression tests > draw every type of shape > [end of test] undo stack "strokeStyle": "solid", "strokeWidth": 2, "type": "arrow", - "version": 3, - "width": 0, + "version": 5, + "width": 50, "x": 310, "y": -10, }, "inserted": { "isDeleted": true, - "version": 2, + "version": 4, }, }, }, @@ -6643,58 +6646,6 @@ exports[`regression tests > draw every type of shape > [end of test] undo stack }, "id": "id17", }, - { - "appState": AppStateDelta { - "delta": Delta { - "deleted": {}, - "inserted": {}, - }, - }, - "elements": { - "added": {}, - "removed": {}, - "updated": { - "id15": { - "deleted": { - "height": 10, - "lastCommittedPoint": [ - 50, - 10, - ], - "points": [ - [ - 0, - 0, - ], - [ - 50, - 10, - ], - ], - "version": 5, - "width": 50, - }, - "inserted": { - "height": 0, - "lastCommittedPoint": null, - "points": [ - [ - 0, - 0, - ], - [ - 0, - 0, - ], - ], - "version": 3, - "width": 0, - }, - }, - }, - }, - "id": "id19", - }, { "appState": AppStateDelta { "delta": Delta { @@ -6752,13 +6703,15 @@ exports[`regression tests > draw every type of shape > [end of test] undo stack }, }, }, - "id": "id21", + "id": "id19", }, { "appState": AppStateDelta { "delta": Delta { "deleted": { - "selectedElementIds": {}, + "selectedElementIds": { + "id20": true, + }, "selectedLinearElement": null, }, "inserted": { @@ -6775,7 +6728,7 @@ exports[`regression tests > draw every type of shape > [end of test] undo stack "elements": { "added": {}, "removed": { - "id22": { + "id20": { "deleted": { "angle": 0, "backgroundColor": "transparent", @@ -6786,10 +6739,13 @@ exports[`regression tests > draw every type of shape > [end of test] undo stack "fillStyle": "solid", "frameId": null, "groupIds": [], - "height": 0, + "height": 10, "index": "a6", "isDeleted": false, - "lastCommittedPoint": null, + "lastCommittedPoint": [ + 50, + 10, + ], "link": null, "locked": false, "opacity": 100, @@ -6799,8 +6755,8 @@ exports[`regression tests > draw every type of shape > [end of test] undo stack 0, ], [ - 0, - 0, + 50, + 10, ], ], "polygon": false, @@ -6812,78 +6768,20 @@ exports[`regression tests > draw every type of shape > [end of test] undo stack "strokeStyle": "solid", "strokeWidth": 2, "type": "line", - "version": 3, - "width": 0, + "version": 5, + "width": 50, "x": 430, "y": -10, }, "inserted": { "isDeleted": true, - "version": 2, + "version": 4, }, }, }, "updated": {}, }, - "id": "id24", - }, - { - "appState": AppStateDelta { - "delta": Delta { - "deleted": { - "selectedElementIds": { - "id22": true, - }, - }, - "inserted": { - "selectedElementIds": {}, - }, - }, - }, - "elements": { - "added": {}, - "removed": {}, - "updated": { - "id22": { - "deleted": { - "height": 10, - "lastCommittedPoint": [ - 50, - 10, - ], - "points": [ - [ - 0, - 0, - ], - [ - 50, - 10, - ], - ], - "version": 5, - "width": 50, - }, - "inserted": { - "height": 0, - "lastCommittedPoint": null, - "points": [ - [ - 0, - 0, - ], - [ - 0, - 0, - ], - ], - "version": 3, - "width": 0, - }, - }, - }, - }, - "id": "id26", + "id": "id22", }, { "appState": AppStateDelta { @@ -6896,7 +6794,7 @@ exports[`regression tests > draw every type of shape > [end of test] undo stack "added": {}, "removed": {}, "updated": { - "id22": { + "id20": { "deleted": { "height": 20, "lastCommittedPoint": [ @@ -6942,14 +6840,14 @@ exports[`regression tests > draw every type of shape > [end of test] undo stack }, }, }, - "id": "id28", + "id": "id24", }, { "appState": AppStateDelta { "delta": Delta { "deleted": { "selectedLinearElement": { - "elementId": "id22", + "elementId": "id20", "isEditing": false, }, }, @@ -6963,7 +6861,7 @@ exports[`regression tests > draw every type of shape > [end of test] undo stack "removed": {}, "updated": {}, }, - "id": "id30", + "id": "id26", }, { "appState": AppStateDelta { @@ -6973,7 +6871,7 @@ exports[`regression tests > draw every type of shape > [end of test] undo stack }, "inserted": { "selectedElementIds": { - "id22": true, + "id20": true, }, }, }, @@ -6983,7 +6881,7 @@ exports[`regression tests > draw every type of shape > [end of test] undo stack "removed": {}, "updated": {}, }, - "id": "id32", + "id": "id28", }, { "appState": AppStateDelta { @@ -6993,7 +6891,7 @@ exports[`regression tests > draw every type of shape > [end of test] undo stack }, "inserted": { "selectedLinearElement": { - "elementId": "id22", + "elementId": "id20", "isEditing": false, }, }, @@ -7002,7 +6900,7 @@ exports[`regression tests > draw every type of shape > [end of test] undo stack "elements": { "added": {}, "removed": { - "id33": { + "id29": { "deleted": { "angle": 0, "backgroundColor": "transparent", @@ -7060,7 +6958,7 @@ exports[`regression tests > draw every type of shape > [end of test] undo stack }, "updated": {}, }, - "id": "id35", + "id": "id31", }, ] `; @@ -14632,7 +14530,7 @@ exports[`regression tests > undo/redo drawing an element > [end of test] appStat exports[`regression tests > undo/redo drawing an element > [end of test] number of elements 1`] = `0`; -exports[`regression tests > undo/redo drawing an element > [end of test] number of renders 1`] = `19`; +exports[`regression tests > undo/redo drawing an element > [end of test] number of renders 1`] = `18`; exports[`regression tests > undo/redo drawing an element > [end of test] redo stack 1`] = ` [ @@ -14693,59 +14591,7 @@ exports[`regression tests > undo/redo drawing an element > [end of test] redo st }, }, }, - "id": "id13", - }, - { - "appState": AppStateDelta { - "delta": Delta { - "deleted": {}, - "inserted": {}, - }, - }, - "elements": { - "added": {}, - "removed": {}, - "updated": { - "id6": { - "deleted": { - "height": 0, - "lastCommittedPoint": null, - "points": [ - [ - 0, - 0, - ], - [ - 0, - 0, - ], - ], - "version": 9, - "width": 0, - }, - "inserted": { - "height": 10, - "lastCommittedPoint": [ - 60, - 10, - ], - "points": [ - [ - 0, - 0, - ], - [ - 60, - 10, - ], - ], - "version": 8, - "width": 60, - }, - }, - }, - }, - "id": "id14", + "id": "id11", }, { "appState": AppStateDelta { @@ -14772,7 +14618,7 @@ exports[`regression tests > undo/redo drawing an element > [end of test] redo st "id6": { "deleted": { "isDeleted": true, - "version": 10, + "version": 9, }, "inserted": { "angle": 0, @@ -14785,10 +14631,13 @@ exports[`regression tests > undo/redo drawing an element > [end of test] redo st "fillStyle": "solid", "frameId": null, "groupIds": [], - "height": 0, + "height": 10, "index": "a2", "isDeleted": false, - "lastCommittedPoint": null, + "lastCommittedPoint": [ + 60, + 10, + ], "link": null, "locked": false, "opacity": 100, @@ -14798,8 +14647,8 @@ exports[`regression tests > undo/redo drawing an element > [end of test] redo st 0, ], [ - 0, - 0, + 60, + 10, ], ], "roughness": 1, @@ -14812,8 +14661,8 @@ exports[`regression tests > undo/redo drawing an element > [end of test] redo st "strokeStyle": "solid", "strokeWidth": 2, "type": "arrow", - "version": 9, - "width": 0, + "version": 8, + "width": 60, "x": 130, "y": 10, }, @@ -14822,7 +14671,7 @@ exports[`regression tests > undo/redo drawing an element > [end of test] redo st "removed": {}, "updated": {}, }, - "id": "id15", + "id": "id12", }, ] `; @@ -14933,7 +14782,7 @@ exports[`regression tests > undo/redo drawing an element > [end of test] undo st }, "updated": {}, }, - "id": "id17", + "id": "id14", }, ] `; diff --git a/packages/excalidraw/tests/history.test.tsx b/packages/excalidraw/tests/history.test.tsx index 124a17fb24..4fe1096dfc 100644 --- a/packages/excalidraw/tests/history.test.tsx +++ b/packages/excalidraw/tests/history.test.tsx @@ -1070,7 +1070,7 @@ describe("history", () => { // leave editor Keyboard.keyPress(KEYS.ESCAPE); - expect(API.getUndoStack().length).toBe(6); + expect(API.getUndoStack().length).toBe(5); expect(API.getRedoStack().length).toBe(0); expect(assertSelectedElements(h.elements[0])); expect(h.state.selectedLinearElement?.isEditing ?? false).toBe(false); @@ -1087,7 +1087,7 @@ describe("history", () => { ]); Keyboard.undo(); - expect(API.getUndoStack().length).toBe(5); + expect(API.getUndoStack().length).toBe(4); expect(API.getRedoStack().length).toBe(1); expect(assertSelectedElements(h.elements[0])); expect(h.state.selectedLinearElement?.isEditing).toBe(true); @@ -1107,11 +1107,11 @@ describe("history", () => { mouse.clickAt(0, 0); mouse.clickAt(10, 10); mouse.clickAt(20, 20); - expect(API.getUndoStack().length).toBe(5); + expect(API.getUndoStack().length).toBe(4); expect(API.getRedoStack().length).toBe(1); Keyboard.undo(); - expect(API.getUndoStack().length).toBe(4); + expect(API.getUndoStack().length).toBe(3); expect(API.getRedoStack().length).toBe(2); expect(assertSelectedElements(h.elements[0])); expect(h.state.selectedLinearElement?.isEditing).toBe(true); @@ -1128,7 +1128,7 @@ describe("history", () => { ]); Keyboard.undo(); - expect(API.getUndoStack().length).toBe(3); + expect(API.getUndoStack().length).toBe(2); expect(API.getRedoStack().length).toBe(3); expect(assertSelectedElements(h.elements[0])); expect(h.state.selectedLinearElement?.isEditing).toBe(false); // undo `open editor` @@ -1144,29 +1144,29 @@ describe("history", () => { }), ]); - Keyboard.undo(); - expect(API.getUndoStack().length).toBe(2); - expect(API.getRedoStack().length).toBe(4); - expect(assertSelectedElements(h.elements[0])); - expect(h.state.selectedLinearElement?.isEditing).toBe(false); - expect(h.state.selectedLinearElement).toBeNull(); // undo `actionFinalize` - expect(h.elements).toEqual([ - expect.objectContaining({ - isDeleted: false, - points: [ - [0, 0], - [10, 10], - [20, 0], - ], - }), - ]); + // Keyboard.undo(); + // expect(API.getUndoStack().length).toBe(2); + // expect(API.getRedoStack().length).toBe(4); + // expect(assertSelectedElements(h.elements[0])); + // expect(h.state.selectedLinearElement?.isEditing).toBe(false); + // expect(h.state.selectedLinearElement).toBeNull(); // undo `actionFinalize` + // expect(h.elements).toEqual([ + // expect.objectContaining({ + // isDeleted: false, + // points: [ + // [0, 0], + // [10, 10], + // [20, 0], + // ], + // }), + // ]); Keyboard.undo(); expect(API.getUndoStack().length).toBe(1); - expect(API.getRedoStack().length).toBe(5); + expect(API.getRedoStack().length).toBe(4); expect(assertSelectedElements(h.elements[0])); expect(h.state.selectedLinearElement?.isEditing).toBe(false); - expect(h.state.selectedLinearElement).toBeNull(); + expect(h.state.selectedLinearElement?.elementId).toBe(h.elements[0].id); expect(h.elements).toEqual([ expect.objectContaining({ isDeleted: false, @@ -1179,9 +1179,8 @@ describe("history", () => { Keyboard.undo(); expect(API.getUndoStack().length).toBe(0); - expect(API.getRedoStack().length).toBe(6); + expect(API.getRedoStack().length).toBe(5); expect(API.getSelectedElements().length).toBe(0); - expect(h.state.selectedLinearElement?.isEditing).toBe(false); expect(h.state.selectedLinearElement).toBeNull(); expect(h.elements).toEqual([ expect.objectContaining({ @@ -1195,39 +1194,39 @@ describe("history", () => { Keyboard.redo(); expect(API.getUndoStack().length).toBe(1); - expect(API.getRedoStack().length).toBe(5); - expect(assertSelectedElements(h.elements[0])); - expect(h.state.selectedLinearElement?.isEditing).toBe(false); - expect(h.state.selectedLinearElement).toBeNull(); - expect(h.elements).toEqual([ - expect.objectContaining({ - isDeleted: false, - points: [ - [0, 0], - [10, 10], - ], - }), - ]); - - Keyboard.redo(); - expect(API.getUndoStack().length).toBe(2); expect(API.getRedoStack().length).toBe(4); expect(assertSelectedElements(h.elements[0])); expect(h.state.selectedLinearElement?.isEditing).toBe(false); - expect(h.state.selectedLinearElement).toBeNull(); // undo `actionFinalize` + expect(h.state.selectedLinearElement?.elementId).toBe(h.elements[0].id); expect(h.elements).toEqual([ expect.objectContaining({ isDeleted: false, points: [ [0, 0], [10, 10], - [20, 0], ], }), ]); + // Keyboard.redo(); + // expect(API.getUndoStack().length).toBe(2); + // expect(API.getRedoStack().length).toBe(3); + // expect(assertSelectedElements(h.elements[0])); + // expect(h.state.selectedLinearElement?.isEditing).toBe(false); + // expect(h.state.selectedLinearElement).toBeNull(); // undo `actionFinalize` + // expect(h.elements).toEqual([ + // expect.objectContaining({ + // isDeleted: false, + // points: [ + // [0, 0], + // [10, 10], + // [20, 0], + // ], + // }), + // ]); + Keyboard.redo(); - expect(API.getUndoStack().length).toBe(3); + expect(API.getUndoStack().length).toBe(2); expect(API.getRedoStack().length).toBe(3); expect(assertSelectedElements(h.elements[0])); expect(h.state.selectedLinearElement?.isEditing ?? false).toBe(false); // undo `open editor` @@ -1244,7 +1243,7 @@ describe("history", () => { ]); Keyboard.redo(); - expect(API.getUndoStack().length).toBe(4); + expect(API.getUndoStack().length).toBe(3); expect(API.getRedoStack().length).toBe(2); expect(assertSelectedElements(h.elements[0])); expect(h.state.selectedLinearElement?.isEditing).toBe(true); @@ -1261,7 +1260,7 @@ describe("history", () => { ]); Keyboard.redo(); - expect(API.getUndoStack().length).toBe(5); + expect(API.getUndoStack().length).toBe(4); expect(API.getRedoStack().length).toBe(1); expect(assertSelectedElements(h.elements[0])); expect(h.state.selectedLinearElement?.isEditing).toBe(true); @@ -1278,7 +1277,7 @@ describe("history", () => { ]); Keyboard.redo(); - expect(API.getUndoStack().length).toBe(6); + expect(API.getUndoStack().length).toBe(5); expect(API.getRedoStack().length).toBe(0); expect(assertSelectedElements(h.elements[0])); expect(h.state.selectedLinearElement?.isEditing ?? false).toBe(false); @@ -2495,10 +2494,9 @@ describe("history", () => { captureUpdate: CaptureUpdateAction.NEVER, }); - Keyboard.undo(); // undo `actionFinalize` Keyboard.undo(); expect(API.getUndoStack().length).toBe(1); - expect(API.getRedoStack().length).toBe(2); + expect(API.getRedoStack().length).toBe(1); expect(h.elements).toEqual([ expect.objectContaining({ points: [ @@ -2512,7 +2510,7 @@ describe("history", () => { Keyboard.undo(); expect(API.getUndoStack().length).toBe(0); - expect(API.getRedoStack().length).toBe(3); + expect(API.getRedoStack().length).toBe(2); expect(h.elements).toEqual([ expect.objectContaining({ isDeleted: true, @@ -2525,7 +2523,7 @@ describe("history", () => { Keyboard.redo(); expect(API.getUndoStack().length).toBe(1); - expect(API.getRedoStack().length).toBe(2); + expect(API.getRedoStack().length).toBe(1); expect(h.elements).toEqual([ expect.objectContaining({ isDeleted: false, @@ -2538,21 +2536,6 @@ describe("history", () => { Keyboard.redo(); expect(API.getUndoStack().length).toBe(2); - expect(API.getRedoStack().length).toBe(1); - expect(h.elements).toEqual([ - expect.objectContaining({ - points: [ - [0, 0], - [5, 5], - [10, 10], - [15, 15], - [20, 20], - ], - }), - ]); - - Keyboard.redo(); // redo `actionFinalize` - expect(API.getUndoStack().length).toBe(3); expect(API.getRedoStack().length).toBe(0); expect(h.elements).toEqual([ expect.objectContaining({ @@ -3052,7 +3035,7 @@ describe("history", () => { // leave editor Keyboard.keyPress(KEYS.ESCAPE); - expect(API.getUndoStack().length).toBe(4); + expect(API.getUndoStack().length).toBe(3); expect(API.getRedoStack().length).toBe(0); expect(h.state.selectedLinearElement).not.toBeNull(); expect(h.state.selectedLinearElement?.isEditing).toBe(false); @@ -3069,11 +3052,11 @@ describe("history", () => { Keyboard.undo(); expect(API.getUndoStack().length).toBe(0); - expect(API.getRedoStack().length).toBe(4); + expect(API.getRedoStack().length).toBe(3); expect(h.state.selectedLinearElement).toBeNull(); Keyboard.redo(); - expect(API.getUndoStack().length).toBe(4); + expect(API.getUndoStack().length).toBe(3); expect(API.getRedoStack().length).toBe(0); expect(h.state.selectedLinearElement).toBeNull(); expect(h.state.selectedLinearElement?.isEditing ?? false).toBe(false); diff --git a/packages/excalidraw/tests/regressionTests.test.tsx b/packages/excalidraw/tests/regressionTests.test.tsx index d4b5185bac..929ee797ff 100644 --- a/packages/excalidraw/tests/regressionTests.test.tsx +++ b/packages/excalidraw/tests/regressionTests.test.tsx @@ -363,7 +363,6 @@ describe("regression tests", () => { Keyboard.withModifierKeys({ ctrl: true }, () => { Keyboard.keyPress(KEYS.Z); Keyboard.keyPress(KEYS.Z); - Keyboard.keyPress(KEYS.Z); }); expect(h.elements.filter((element) => !element.isDeleted).length).toBe(2); Keyboard.withModifierKeys({ ctrl: true }, () => {