|
@@ -4,6 +4,13 @@ import { render, fireEvent } from "./test-utils";
|
|
|
import App from "../components/App";
|
|
|
import * as Renderer from "../renderer/renderScene";
|
|
|
import { reseed } from "../random";
|
|
|
+import { bindOrUnbindLinearElement } from "../element/binding";
|
|
|
+import {
|
|
|
+ ExcalidrawLinearElement,
|
|
|
+ NonDeleted,
|
|
|
+ ExcalidrawRectangleElement,
|
|
|
+} from "../element/types";
|
|
|
+import { UI, Pointer, Keyboard } from "./helpers/ui";
|
|
|
|
|
|
// Unmount ReactDOM from root
|
|
|
ReactDOM.unmountComponentAtNode(document.getElementById("root")!);
|
|
@@ -50,6 +57,53 @@ describe("move element", () => {
|
|
|
|
|
|
h.elements.forEach((element) => expect(element).toMatchSnapshot());
|
|
|
});
|
|
|
+
|
|
|
+ it("rectangles with binding arrow", () => {
|
|
|
+ render(<App />);
|
|
|
+
|
|
|
+ // create elements
|
|
|
+ const rectA = UI.createElement("rectangle", { size: 100 });
|
|
|
+ const rectB = UI.createElement("rectangle", { x: 200, y: 0, size: 300 });
|
|
|
+ const line = UI.createElement("line", { x: 110, y: 50, size: 80 });
|
|
|
+
|
|
|
+ // bind line to two rectangles
|
|
|
+ bindOrUnbindLinearElement(
|
|
|
+ line as NonDeleted<ExcalidrawLinearElement>,
|
|
|
+ rectA as ExcalidrawRectangleElement,
|
|
|
+ rectB as ExcalidrawRectangleElement,
|
|
|
+ );
|
|
|
+
|
|
|
+ // select the second rectangles
|
|
|
+ new Pointer("mouse").clickOn(rectB);
|
|
|
+
|
|
|
+ expect(renderScene).toHaveBeenCalledTimes(19);
|
|
|
+ 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([line.x, line.y]).toEqual([110, 50]);
|
|
|
+ expect([line.width, line.height]).toEqual([80, 80]);
|
|
|
+
|
|
|
+ renderScene.mockClear();
|
|
|
+
|
|
|
+ // Move selected rectangle
|
|
|
+ Keyboard.keyDown("ArrowRight");
|
|
|
+ Keyboard.keyDown("ArrowDown");
|
|
|
+ Keyboard.keyDown("ArrowDown");
|
|
|
+
|
|
|
+ // Check that the arrow size has been changed according to moving the rectangle
|
|
|
+ expect(renderScene).toHaveBeenCalledTimes(3);
|
|
|
+ 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([201, 2]);
|
|
|
+ expect([Math.round(line.x), Math.round(line.y)]).toEqual([110, 50]);
|
|
|
+ expect([Math.round(line.width), Math.round(line.height)]).toEqual([81, 81]);
|
|
|
+
|
|
|
+ h.elements.forEach((element) => expect(element).toMatchSnapshot());
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
describe("duplicate element on move when ALT is clicked", () => {
|