2020-03-23 16:38:41 -07:00
|
|
|
import { reseed } from "../random";
|
|
|
|
import React from "react";
|
|
|
|
import ReactDOM from "react-dom";
|
|
|
|
import * as Renderer from "../renderer/renderScene";
|
2020-08-28 10:15:29 +02:00
|
|
|
import {
|
|
|
|
waitFor,
|
|
|
|
render,
|
|
|
|
screen,
|
|
|
|
fireEvent,
|
|
|
|
GlobalTestState,
|
|
|
|
} from "./test-utils";
|
2020-04-12 16:24:52 +05:30
|
|
|
import App from "../components/App";
|
2020-06-27 12:02:54 +01:00
|
|
|
import { setLanguage } from "../i18n";
|
2020-03-23 16:38:41 -07:00
|
|
|
import { setDateTimeForTests } from "../utils";
|
|
|
|
import { ExcalidrawElement } from "../element/types";
|
2020-08-10 14:16:39 +02:00
|
|
|
import { getTransformHandles as _getTransformHandles } from "../element";
|
2020-07-26 16:29:44 +05:00
|
|
|
import { queryByText } from "@testing-library/react";
|
|
|
|
import { copiedStyles } from "../actions/actionStyles";
|
2020-08-28 10:15:29 +02:00
|
|
|
import { UI, Pointer, Keyboard } from "./helpers/ui";
|
|
|
|
import { API } from "./helpers/api";
|
2020-03-23 16:38:41 -07:00
|
|
|
|
|
|
|
const { h } = window;
|
|
|
|
|
|
|
|
const renderScene = jest.spyOn(Renderer, "renderScene");
|
2020-08-27 20:32:10 +02:00
|
|
|
|
2020-08-27 20:59:46 +02:00
|
|
|
const assertSelectedElements = (...elements: ExcalidrawElement[]) => {
|
|
|
|
expect(
|
2020-08-28 10:15:29 +02:00
|
|
|
API.getSelectedElements().map((element) => {
|
2020-08-27 20:59:46 +02:00
|
|
|
return element.id;
|
|
|
|
}),
|
|
|
|
).toEqual(expect.arrayContaining(elements.map((element) => element.id)));
|
|
|
|
};
|
|
|
|
|
2020-05-28 01:56:18 -07:00
|
|
|
const mouse = new Pointer("mouse");
|
|
|
|
const finger1 = new Pointer("touch", 1);
|
|
|
|
const finger2 = new Pointer("touch", 2);
|
|
|
|
|
2020-05-20 16:21:37 +03:00
|
|
|
const clickLabeledElement = (label: string) => {
|
2020-03-23 16:38:41 -07:00
|
|
|
const element = document.querySelector(`[aria-label='${label}']`);
|
|
|
|
if (!element) {
|
|
|
|
throw new Error(`No labeled element found: ${label}`);
|
|
|
|
}
|
|
|
|
fireEvent.click(element);
|
2020-05-20 16:21:37 +03:00
|
|
|
};
|
2020-03-23 16:38:41 -07:00
|
|
|
|
2020-08-10 14:16:39 +02:00
|
|
|
type HandlerRectanglesRet = keyof ReturnType<typeof _getTransformHandles>;
|
|
|
|
const getTransformHandles = (pointerType: "mouse" | "touch" | "pen") => {
|
|
|
|
const rects = _getTransformHandles(
|
2020-08-28 10:15:29 +02:00
|
|
|
API.getSelectedElement(),
|
2020-04-14 12:30:58 +03:00
|
|
|
h.state.zoom,
|
|
|
|
pointerType,
|
|
|
|
) as {
|
|
|
|
[T in HandlerRectanglesRet]: [number, number, number, number];
|
|
|
|
};
|
2020-03-23 16:38:41 -07:00
|
|
|
|
|
|
|
const rv: { [K in keyof typeof rects]: [number, number] } = {} as any;
|
|
|
|
|
|
|
|
for (const handlePos in rects) {
|
|
|
|
const [x, y, width, height] = rects[handlePos as keyof typeof rects];
|
|
|
|
|
|
|
|
rv[handlePos as keyof typeof rects] = [x + width / 2, y + height / 2];
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
2020-05-20 16:21:37 +03:00
|
|
|
};
|
2020-03-23 16:38:41 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This is always called at the end of your test, so usually you don't need to call it.
|
|
|
|
* However, if you have a long test, you might want to call it during the test so it's easier
|
|
|
|
* to debug where a test failure came from.
|
|
|
|
*/
|
2020-05-20 16:21:37 +03:00
|
|
|
const checkpoint = (name: string) => {
|
2020-03-23 16:38:41 -07:00
|
|
|
expect(renderScene.mock.calls.length).toMatchSnapshot(
|
|
|
|
`[${name}] number of renders`,
|
|
|
|
);
|
|
|
|
expect(h.state).toMatchSnapshot(`[${name}] appState`);
|
|
|
|
expect(h.history.getSnapshotForTest()).toMatchSnapshot(`[${name}] history`);
|
|
|
|
expect(h.elements.length).toMatchSnapshot(`[${name}] number of elements`);
|
|
|
|
h.elements.forEach((element, i) =>
|
|
|
|
expect(element).toMatchSnapshot(`[${name}] element ${i}`),
|
|
|
|
);
|
2020-05-20 16:21:37 +03:00
|
|
|
};
|
2020-03-23 16:38:41 -07:00
|
|
|
|
2020-06-27 12:02:54 +01:00
|
|
|
beforeEach(async () => {
|
2020-03-23 16:38:41 -07:00
|
|
|
// Unmount ReactDOM from root
|
|
|
|
ReactDOM.unmountComponentAtNode(document.getElementById("root")!);
|
|
|
|
|
|
|
|
localStorage.clear();
|
|
|
|
renderScene.mockClear();
|
|
|
|
h.history.clear();
|
|
|
|
reseed(7);
|
|
|
|
setDateTimeForTests("201933152653");
|
2020-05-28 01:56:18 -07:00
|
|
|
|
|
|
|
mouse.reset();
|
|
|
|
finger1.reset();
|
|
|
|
finger2.reset();
|
2020-03-23 16:38:41 -07:00
|
|
|
|
2020-06-27 12:02:54 +01:00
|
|
|
await setLanguage("en.json");
|
2020-10-23 19:06:16 +02:00
|
|
|
render(<App offsetLeft={0} offsetTop={0} />);
|
2020-03-23 16:38:41 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
checkpoint("end of test");
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("regression tests", () => {
|
|
|
|
it("draw every type of shape", () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-08-08 21:04:15 -07:00
|
|
|
mouse.down(10, -10);
|
|
|
|
mouse.up(20, 10);
|
2020-03-23 16:38:41 -07:00
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("diamond");
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.down(10, -10);
|
2020-08-08 21:04:15 -07:00
|
|
|
mouse.up(20, 10);
|
2020-03-23 16:38:41 -07:00
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("ellipse");
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.down(10, -10);
|
2020-08-08 21:04:15 -07:00
|
|
|
mouse.up(20, 10);
|
2020-03-23 16:38:41 -07:00
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("arrow");
|
2020-08-08 21:04:15 -07:00
|
|
|
mouse.down(40, -10);
|
|
|
|
mouse.up(50, 10);
|
2020-03-23 16:38:41 -07:00
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("line");
|
2020-08-08 21:04:15 -07:00
|
|
|
mouse.down(40, -10);
|
|
|
|
mouse.up(50, 10);
|
2020-03-23 16:38:41 -07:00
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("arrow");
|
2020-08-08 21:04:15 -07:00
|
|
|
mouse.click(40, -10);
|
|
|
|
mouse.click(50, 10);
|
|
|
|
mouse.click(30, 10);
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.hotkeyPress("ENTER");
|
2020-03-23 16:38:41 -07:00
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("line");
|
2020-08-08 21:04:15 -07:00
|
|
|
mouse.click(40, -20);
|
|
|
|
mouse.click(50, 10);
|
|
|
|
mouse.click(30, 10);
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.hotkeyPress("ENTER");
|
2020-05-12 20:10:11 +01:00
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("draw");
|
2020-08-08 21:04:15 -07:00
|
|
|
mouse.down(40, -20);
|
|
|
|
mouse.up(50, 10);
|
2020-05-28 01:56:18 -07:00
|
|
|
|
|
|
|
expect(h.elements.map((element) => element.type)).toEqual([
|
|
|
|
"rectangle",
|
|
|
|
"diamond",
|
|
|
|
"ellipse",
|
|
|
|
"arrow",
|
|
|
|
"line",
|
|
|
|
"arrow",
|
|
|
|
"line",
|
|
|
|
"draw",
|
|
|
|
]);
|
2020-03-23 16:38:41 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
it("click to select a shape", () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(10, 10);
|
|
|
|
|
|
|
|
const firstRectPos = mouse.getPosition();
|
2020-03-23 16:38:41 -07:00
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.down(10, -10);
|
|
|
|
mouse.up(10, 10);
|
2020-03-23 16:38:41 -07:00
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
const prevSelectedId = API.getSelectedElement().id;
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.restorePosition(...firstRectPos);
|
|
|
|
mouse.click();
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElement().id).not.toEqual(prevSelectedId);
|
2020-03-23 16:38:41 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
for (const [keys, shape] of [
|
|
|
|
["2r", "rectangle"],
|
|
|
|
["3d", "diamond"],
|
|
|
|
["4e", "ellipse"],
|
|
|
|
["5a", "arrow"],
|
|
|
|
["6l", "line"],
|
2020-05-12 20:10:11 +01:00
|
|
|
["7x", "draw"],
|
2020-03-23 16:38:41 -07:00
|
|
|
] as [string, ExcalidrawElement["type"]][]) {
|
|
|
|
for (const key of keys) {
|
|
|
|
it(`hotkey ${key} selects ${shape} tool`, () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.keyPress(key);
|
2020-03-23 16:38:41 -07:00
|
|
|
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(10, 10);
|
2020-03-23 16:38:41 -07:00
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElement().type).toBe(shape);
|
2020-03-23 16:38:41 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
it("change the properties of a shape", () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(10, 10);
|
2020-03-23 16:38:41 -07:00
|
|
|
|
|
|
|
clickLabeledElement("Background");
|
|
|
|
clickLabeledElement("#fa5252");
|
|
|
|
clickLabeledElement("Stroke");
|
|
|
|
clickLabeledElement("#5f3dc4");
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElement().backgroundColor).toBe("#fa5252");
|
|
|
|
expect(API.getSelectedElement().strokeColor).toBe("#5f3dc4");
|
2020-03-23 16:38:41 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
it("resize an element, trying every resize handle", () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(10, 10);
|
2020-03-23 16:38:41 -07:00
|
|
|
|
2020-08-10 14:16:39 +02:00
|
|
|
const transformHandles = getTransformHandles("mouse");
|
|
|
|
delete transformHandles.rotation; // exclude rotation handle
|
|
|
|
for (const handlePos in transformHandles) {
|
|
|
|
const [x, y] = transformHandles[
|
|
|
|
handlePos as keyof typeof transformHandles
|
|
|
|
];
|
2020-08-28 10:15:29 +02:00
|
|
|
const { width: prevWidth, height: prevHeight } = API.getSelectedElement();
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.restorePosition(x, y);
|
|
|
|
mouse.down();
|
|
|
|
mouse.up(-5, -5);
|
|
|
|
|
2020-03-23 16:38:41 -07:00
|
|
|
const {
|
|
|
|
width: nextWidthNegative,
|
|
|
|
height: nextHeightNegative,
|
2020-08-28 10:15:29 +02:00
|
|
|
} = API.getSelectedElement();
|
2020-03-23 16:38:41 -07:00
|
|
|
expect(
|
|
|
|
prevWidth !== nextWidthNegative || prevHeight !== nextHeightNegative,
|
|
|
|
).toBeTruthy();
|
|
|
|
checkpoint(`resize handle ${handlePos} (-5, -5)`);
|
|
|
|
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.down();
|
|
|
|
mouse.up(5, 5);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
const { width, height } = API.getSelectedElement();
|
2020-03-23 16:38:41 -07:00
|
|
|
expect(width).toBe(prevWidth);
|
|
|
|
expect(height).toBe(prevHeight);
|
|
|
|
checkpoint(`unresize handle ${handlePos} (-5, -5)`);
|
|
|
|
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.restorePosition(x, y);
|
|
|
|
mouse.down();
|
|
|
|
mouse.up(5, 5);
|
|
|
|
|
2020-03-23 16:38:41 -07:00
|
|
|
const {
|
|
|
|
width: nextWidthPositive,
|
|
|
|
height: nextHeightPositive,
|
2020-08-28 10:15:29 +02:00
|
|
|
} = API.getSelectedElement();
|
2020-03-23 16:38:41 -07:00
|
|
|
expect(
|
|
|
|
prevWidth !== nextWidthPositive || prevHeight !== nextHeightPositive,
|
|
|
|
).toBeTruthy();
|
|
|
|
checkpoint(`resize handle ${handlePos} (+5, +5)`);
|
|
|
|
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.down();
|
|
|
|
mouse.up(-5, -5);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
const {
|
|
|
|
width: finalWidth,
|
|
|
|
height: finalHeight,
|
|
|
|
} = API.getSelectedElement();
|
2020-03-23 16:38:41 -07:00
|
|
|
expect(finalWidth).toBe(prevWidth);
|
|
|
|
expect(finalHeight).toBe(prevHeight);
|
|
|
|
|
|
|
|
checkpoint(`unresize handle ${handlePos} (+5, +5)`);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
it("click on an element and drag it", () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(10, 10);
|
2020-03-23 16:38:41 -07:00
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
const { x: prevX, y: prevY } = API.getSelectedElement();
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.down(-10, -10);
|
|
|
|
mouse.up(10, 10);
|
2020-03-23 16:38:41 -07:00
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
const { x: nextX, y: nextY } = API.getSelectedElement();
|
2020-03-23 16:38:41 -07:00
|
|
|
expect(nextX).toBeGreaterThan(prevX);
|
|
|
|
expect(nextY).toBeGreaterThan(prevY);
|
|
|
|
|
|
|
|
checkpoint("dragged");
|
|
|
|
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.down();
|
|
|
|
mouse.up(-10, -10);
|
2020-03-23 16:38:41 -07:00
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
const { x, y } = API.getSelectedElement();
|
2020-03-23 16:38:41 -07:00
|
|
|
expect(x).toBe(prevX);
|
|
|
|
expect(y).toBe(prevY);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("alt-drag duplicates an element", () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(10, 10);
|
2020-03-23 16:38:41 -07:00
|
|
|
|
|
|
|
expect(
|
|
|
|
h.elements.filter((element) => element.type === "rectangle").length,
|
|
|
|
).toBe(1);
|
2020-05-28 01:56:18 -07:00
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.withModifierKeys({ alt: true }, () => {
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.down(-10, -10);
|
|
|
|
mouse.up(10, 10);
|
|
|
|
});
|
|
|
|
|
2020-03-23 16:38:41 -07:00
|
|
|
expect(
|
|
|
|
h.elements.filter((element) => element.type === "rectangle").length,
|
|
|
|
).toBe(2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("click-drag to select a group", () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(10, 10);
|
2020-03-23 16:38:41 -07:00
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.down(10, -10);
|
|
|
|
mouse.up(10, 10);
|
|
|
|
|
|
|
|
const finalPosition = mouse.getPosition();
|
2020-03-23 16:38:41 -07:00
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.down(10, -10);
|
|
|
|
mouse.up(10, 10);
|
2020-03-23 16:38:41 -07:00
|
|
|
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.restorePosition(0, 0);
|
|
|
|
mouse.down();
|
|
|
|
mouse.restorePosition(...finalPosition);
|
|
|
|
mouse.up(5, 5);
|
2020-03-23 16:38:41 -07:00
|
|
|
|
|
|
|
expect(
|
|
|
|
h.elements.filter((element) => h.state.selectedElementIds[element.id])
|
|
|
|
.length,
|
|
|
|
).toBe(2);
|
|
|
|
});
|
|
|
|
|
2020-05-28 01:56:18 -07:00
|
|
|
it("shift-click to multiselect, then drag", () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(10, 10);
|
2020-03-23 16:38:41 -07:00
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.down(10, -10);
|
|
|
|
mouse.up(10, 10);
|
2020-03-23 16:38:41 -07:00
|
|
|
|
|
|
|
const prevRectsXY = h.elements
|
|
|
|
.filter((element) => element.type === "rectangle")
|
|
|
|
.map((element) => ({ x: element.x, y: element.y }));
|
2020-05-28 01:56:18 -07:00
|
|
|
|
|
|
|
mouse.reset();
|
|
|
|
mouse.click(10, 10);
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.withModifierKeys({ shift: true }, () => {
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.click(20, 0);
|
|
|
|
});
|
|
|
|
|
|
|
|
mouse.down();
|
|
|
|
mouse.up(10, 10);
|
|
|
|
|
2020-03-23 16:38:41 -07:00
|
|
|
h.elements
|
|
|
|
.filter((element) => element.type === "rectangle")
|
|
|
|
.forEach((element, i) => {
|
|
|
|
expect(element.x).toBeGreaterThan(prevRectsXY[i].x);
|
|
|
|
expect(element.y).toBeGreaterThan(prevRectsXY[i].y);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("pinch-to-zoom works", () => {
|
|
|
|
expect(h.state.zoom).toBe(1);
|
2020-05-28 01:56:18 -07:00
|
|
|
finger1.down(50, 50);
|
|
|
|
finger2.down(60, 50);
|
|
|
|
finger1.move(-10, 0);
|
2020-03-23 16:38:41 -07:00
|
|
|
expect(h.state.zoom).toBeGreaterThan(1);
|
|
|
|
const zoomed = h.state.zoom;
|
2020-05-28 01:56:18 -07:00
|
|
|
finger1.move(5, 0);
|
|
|
|
finger2.move(-5, 0);
|
2020-03-23 16:38:41 -07:00
|
|
|
expect(h.state.zoom).toBeLessThan(zoomed);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("two-finger scroll works", () => {
|
|
|
|
const startScrollY = h.state.scrollY;
|
2020-05-28 01:56:18 -07:00
|
|
|
finger1.down(50, 50);
|
|
|
|
finger2.down(60, 50);
|
|
|
|
|
|
|
|
finger1.up(0, -10);
|
|
|
|
finger2.up(0, -10);
|
2020-03-23 16:38:41 -07:00
|
|
|
expect(h.state.scrollY).toBeLessThan(startScrollY);
|
|
|
|
|
|
|
|
const startScrollX = h.state.scrollX;
|
2020-05-28 01:56:18 -07:00
|
|
|
|
|
|
|
finger1.restorePosition(50, 50);
|
|
|
|
finger2.restorePosition(50, 60);
|
|
|
|
finger1.down();
|
|
|
|
finger2.down();
|
|
|
|
finger1.up(10, 0);
|
|
|
|
finger2.up(10, 0);
|
2020-03-23 16:38:41 -07:00
|
|
|
expect(h.state.scrollX).toBeGreaterThan(startScrollX);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("spacebar + drag scrolls the canvas", () => {
|
|
|
|
const { scrollX: startScrollX, scrollY: startScrollY } = h.state;
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.hotkeyDown("SPACE");
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.down(50, 50);
|
|
|
|
mouse.up(60, 60);
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.hotkeyUp("SPACE");
|
2020-03-23 16:38:41 -07:00
|
|
|
const { scrollX, scrollY } = h.state;
|
|
|
|
expect(scrollX).not.toEqual(startScrollX);
|
|
|
|
expect(scrollY).not.toEqual(startScrollY);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("arrow keys", () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(10, 10);
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.hotkeyPress("ARROW_LEFT");
|
|
|
|
Keyboard.hotkeyPress("ARROW_LEFT");
|
|
|
|
Keyboard.hotkeyPress("ARROW_RIGHT");
|
|
|
|
Keyboard.hotkeyPress("ARROW_UP");
|
|
|
|
Keyboard.hotkeyPress("ARROW_UP");
|
|
|
|
Keyboard.hotkeyPress("ARROW_DOWN");
|
2020-05-28 01:56:18 -07:00
|
|
|
expect(h.elements[0].x).toBe(9);
|
|
|
|
expect(h.elements[0].y).toBe(9);
|
2020-03-23 16:38:41 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
it("undo/redo drawing an element", () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-08-08 21:04:15 -07:00
|
|
|
mouse.down(10, -10);
|
|
|
|
mouse.up(20, 10);
|
2020-03-23 16:38:41 -07:00
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-08-08 21:04:15 -07:00
|
|
|
mouse.down(10, 0);
|
|
|
|
mouse.up(30, 20);
|
2020-03-23 16:38:41 -07:00
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("arrow");
|
2020-08-08 21:04:15 -07:00
|
|
|
mouse.click(60, -10);
|
|
|
|
mouse.click(60, 10);
|
|
|
|
mouse.click(40, 10);
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.hotkeyPress("ENTER");
|
2020-03-23 16:38:41 -07:00
|
|
|
|
|
|
|
expect(h.elements.filter((element) => !element.isDeleted).length).toBe(3);
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.withModifierKeys({ ctrl: true }, () => {
|
|
|
|
Keyboard.keyPress("z");
|
|
|
|
Keyboard.keyPress("z");
|
2020-05-28 01:56:18 -07:00
|
|
|
});
|
2020-03-23 16:38:41 -07:00
|
|
|
expect(h.elements.filter((element) => !element.isDeleted).length).toBe(2);
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.withModifierKeys({ ctrl: true }, () => {
|
|
|
|
Keyboard.keyPress("z");
|
2020-05-28 01:56:18 -07:00
|
|
|
});
|
2020-03-23 16:38:41 -07:00
|
|
|
expect(h.elements.filter((element) => !element.isDeleted).length).toBe(1);
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.withModifierKeys({ ctrl: true, shift: true }, () => {
|
|
|
|
Keyboard.keyPress("z");
|
2020-05-28 01:56:18 -07:00
|
|
|
});
|
2020-03-23 16:38:41 -07:00
|
|
|
expect(h.elements.filter((element) => !element.isDeleted).length).toBe(2);
|
|
|
|
});
|
|
|
|
|
2020-05-23 07:26:59 +02:00
|
|
|
it("noop interaction after undo shouldn't create history entry", () => {
|
2020-09-09 21:08:06 +02:00
|
|
|
expect(API.getStateHistory().length).toBe(1);
|
2020-05-23 07:26:59 +02:00
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(10, 10);
|
|
|
|
|
|
|
|
const firstElementEndPoint = mouse.getPosition();
|
2020-05-23 07:26:59 +02:00
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.down(10, -10);
|
|
|
|
mouse.up(10, 10);
|
|
|
|
|
|
|
|
const secondElementEndPoint = mouse.getPosition();
|
2020-05-23 07:26:59 +02:00
|
|
|
|
2020-09-09 21:08:06 +02:00
|
|
|
expect(API.getStateHistory().length).toBe(3);
|
2020-05-23 07:26:59 +02:00
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.withModifierKeys({ ctrl: true }, () => {
|
|
|
|
Keyboard.keyPress("z");
|
2020-05-28 01:56:18 -07:00
|
|
|
});
|
|
|
|
|
2020-09-09 21:08:06 +02:00
|
|
|
expect(API.getStateHistory().length).toBe(2);
|
2020-05-23 07:26:59 +02:00
|
|
|
|
2020-05-28 01:56:18 -07:00
|
|
|
// clicking an element shouldn't add to history
|
|
|
|
mouse.restorePosition(...firstElementEndPoint);
|
|
|
|
mouse.click();
|
2020-09-09 21:08:06 +02:00
|
|
|
expect(API.getStateHistory().length).toBe(2);
|
2020-05-23 07:26:59 +02:00
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.withModifierKeys({ shift: true, ctrl: true }, () => {
|
|
|
|
Keyboard.keyPress("z");
|
2020-05-28 01:56:18 -07:00
|
|
|
});
|
|
|
|
|
2020-09-09 21:08:06 +02:00
|
|
|
expect(API.getStateHistory().length).toBe(3);
|
2020-05-23 07:26:59 +02:00
|
|
|
|
2020-05-28 01:56:18 -07:00
|
|
|
// clicking an element shouldn't add to history
|
|
|
|
mouse.click();
|
2020-09-09 21:08:06 +02:00
|
|
|
expect(API.getStateHistory().length).toBe(3);
|
2020-05-23 07:26:59 +02:00
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
const firstSelectedElementId = API.getSelectedElement().id;
|
2020-05-28 01:56:18 -07:00
|
|
|
|
2020-05-23 07:26:59 +02:00
|
|
|
// same for clicking the element just redo-ed
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.restorePosition(...secondElementEndPoint);
|
|
|
|
mouse.click();
|
2020-09-09 21:08:06 +02:00
|
|
|
expect(API.getStateHistory().length).toBe(3);
|
2020-05-28 01:56:18 -07:00
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElement().id).not.toEqual(firstSelectedElementId);
|
2020-05-23 07:26:59 +02:00
|
|
|
});
|
|
|
|
|
2020-03-23 16:38:41 -07:00
|
|
|
it("zoom hotkeys", () => {
|
|
|
|
expect(h.state.zoom).toBe(1);
|
|
|
|
fireEvent.keyDown(document, { code: "Equal", ctrlKey: true });
|
|
|
|
fireEvent.keyUp(document, { code: "Equal", ctrlKey: true });
|
|
|
|
expect(h.state.zoom).toBeGreaterThan(1);
|
|
|
|
fireEvent.keyDown(document, { code: "Minus", ctrlKey: true });
|
|
|
|
fireEvent.keyUp(document, { code: "Minus", ctrlKey: true });
|
|
|
|
expect(h.state.zoom).toBe(1);
|
|
|
|
});
|
2020-05-27 16:46:11 +02:00
|
|
|
|
2020-06-27 12:02:54 +01:00
|
|
|
it("rerenders UI on language change", async () => {
|
2020-05-27 16:46:11 +02:00
|
|
|
// select rectangle tool to show properties menu
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-05-27 16:46:11 +02:00
|
|
|
// english lang should display `hachure` label
|
|
|
|
expect(screen.queryByText(/hachure/i)).not.toBeNull();
|
|
|
|
fireEvent.change(document.querySelector(".dropdown-select__language")!, {
|
|
|
|
target: { value: "de-DE" },
|
|
|
|
});
|
|
|
|
// switching to german, `hachure` label should no longer exist
|
2020-06-27 12:02:54 +01:00
|
|
|
await waitFor(() => expect(screen.queryByText(/hachure/i)).toBeNull());
|
2020-06-05 01:09:16 +05:00
|
|
|
// reset language
|
|
|
|
fireEvent.change(document.querySelector(".dropdown-select__language")!, {
|
|
|
|
target: { value: "en" },
|
|
|
|
});
|
2020-06-27 12:02:54 +01:00
|
|
|
// switching back to English
|
|
|
|
await waitFor(() => expect(screen.queryByText(/hachure/i)).not.toBeNull());
|
2020-05-27 16:46:11 +02:00
|
|
|
});
|
2020-05-28 01:56:18 -07:00
|
|
|
|
|
|
|
it("make a group and duplicate it", () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(10, 10);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.down(10, -10);
|
|
|
|
mouse.up(10, 10);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.down(10, -10);
|
|
|
|
mouse.up(10, 10);
|
|
|
|
const end = mouse.getPosition();
|
|
|
|
|
|
|
|
mouse.reset();
|
|
|
|
mouse.down();
|
|
|
|
mouse.restorePosition(...end);
|
|
|
|
mouse.up();
|
|
|
|
|
|
|
|
expect(h.elements.length).toBe(3);
|
|
|
|
for (const element of h.elements) {
|
|
|
|
expect(element.groupIds.length).toBe(0);
|
|
|
|
expect(h.state.selectedElementIds[element.id]).toBe(true);
|
|
|
|
}
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.withModifierKeys({ ctrl: true }, () => {
|
|
|
|
Keyboard.keyPress("g");
|
2020-05-28 01:56:18 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
for (const element of h.elements) {
|
|
|
|
expect(element.groupIds.length).toBe(1);
|
|
|
|
}
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.withModifierKeys({ alt: true }, () => {
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.restorePosition(...end);
|
|
|
|
mouse.down();
|
|
|
|
mouse.up(10, 10);
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(h.elements.length).toBe(6);
|
|
|
|
const groups = new Set();
|
|
|
|
for (const element of h.elements) {
|
|
|
|
for (const groupId of element.groupIds) {
|
|
|
|
groups.add(groupId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(groups.size).toBe(2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("double click to edit a group", () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(10, 10);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.down(10, -10);
|
|
|
|
mouse.up(10, 10);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.down(10, -10);
|
|
|
|
mouse.up(10, 10);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.withModifierKeys({ ctrl: true }, () => {
|
|
|
|
Keyboard.keyPress("a");
|
|
|
|
Keyboard.keyPress("g");
|
2020-05-28 01:56:18 -07:00
|
|
|
});
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElements().length).toBe(3);
|
2020-05-28 01:56:18 -07:00
|
|
|
expect(h.state.editingGroupId).toBe(null);
|
|
|
|
mouse.doubleClick();
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElements().length).toBe(1);
|
2020-05-28 01:56:18 -07:00
|
|
|
expect(h.state.editingGroupId).not.toBe(null);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("adjusts z order when grouping", () => {
|
|
|
|
const positions = [];
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(10, 10);
|
|
|
|
positions.push(mouse.getPosition());
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.down(10, -10);
|
|
|
|
mouse.up(10, 10);
|
|
|
|
positions.push(mouse.getPosition());
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.down(10, -10);
|
|
|
|
mouse.up(10, 10);
|
|
|
|
positions.push(mouse.getPosition());
|
|
|
|
|
|
|
|
const ids = h.elements.map((element) => element.id);
|
|
|
|
|
|
|
|
mouse.restorePosition(...positions[0]);
|
|
|
|
mouse.click();
|
|
|
|
mouse.restorePosition(...positions[2]);
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.withModifierKeys({ shift: true }, () => {
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.click();
|
|
|
|
});
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.withModifierKeys({ ctrl: true }, () => {
|
|
|
|
Keyboard.keyPress("g");
|
2020-05-28 01:56:18 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(h.elements.map((element) => element.id)).toEqual([
|
|
|
|
ids[1],
|
|
|
|
ids[0],
|
|
|
|
ids[2],
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("supports nested groups", () => {
|
|
|
|
const positions: number[][] = [];
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(10, 10);
|
|
|
|
positions.push(mouse.getPosition());
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.down(10, -10);
|
|
|
|
mouse.up(10, 10);
|
|
|
|
positions.push(mouse.getPosition());
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.down(10, -10);
|
|
|
|
mouse.up(10, 10);
|
|
|
|
positions.push(mouse.getPosition());
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.withModifierKeys({ ctrl: true }, () => {
|
|
|
|
Keyboard.keyPress("a");
|
|
|
|
Keyboard.keyPress("g");
|
2020-05-28 01:56:18 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
mouse.doubleClick();
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.withModifierKeys({ shift: true }, () => {
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.restorePosition(...positions[0]);
|
|
|
|
mouse.click();
|
|
|
|
});
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.withModifierKeys({ ctrl: true }, () => {
|
|
|
|
Keyboard.keyPress("g");
|
2020-05-28 01:56:18 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
const groupIds = h.elements[2].groupIds;
|
|
|
|
expect(groupIds.length).toBe(2);
|
|
|
|
expect(h.elements[1].groupIds).toEqual(groupIds);
|
|
|
|
expect(h.elements[0].groupIds).toEqual(groupIds.slice(1));
|
|
|
|
|
|
|
|
mouse.click(50, 50);
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElements().length).toBe(0);
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.restorePosition(...positions[0]);
|
|
|
|
mouse.click();
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElements().length).toBe(3);
|
2020-05-28 01:56:18 -07:00
|
|
|
expect(h.state.editingGroupId).toBe(null);
|
|
|
|
|
|
|
|
mouse.doubleClick();
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElements().length).toBe(2);
|
2020-05-28 01:56:18 -07:00
|
|
|
expect(h.state.editingGroupId).toBe(groupIds[1]);
|
|
|
|
|
|
|
|
mouse.doubleClick();
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElements().length).toBe(1);
|
2020-05-28 01:56:18 -07:00
|
|
|
expect(h.state.editingGroupId).toBe(groupIds[0]);
|
|
|
|
|
|
|
|
// click out of the group
|
|
|
|
mouse.restorePosition(...positions[1]);
|
|
|
|
mouse.click();
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElements().length).toBe(0);
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.click();
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElements().length).toBe(3);
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.doubleClick();
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElements().length).toBe(1);
|
2020-05-28 01:56:18 -07:00
|
|
|
});
|
2020-05-29 21:59:39 +02:00
|
|
|
|
|
|
|
it("updates fontSize & fontFamily appState", () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("text");
|
2020-05-29 21:59:39 +02:00
|
|
|
expect(h.state.currentItemFontFamily).toEqual(1); // Virgil
|
|
|
|
fireEvent.click(screen.getByText(/code/i));
|
|
|
|
expect(h.state.currentItemFontFamily).toEqual(3); // Cascadia
|
|
|
|
});
|
2020-06-05 01:09:16 +05:00
|
|
|
|
|
|
|
it("shows context menu for canvas", () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
fireEvent.contextMenu(GlobalTestState.canvas, {
|
|
|
|
button: 2,
|
|
|
|
clientX: 1,
|
|
|
|
clientY: 1,
|
|
|
|
});
|
2020-06-05 01:09:16 +05:00
|
|
|
const contextMenu = document.querySelector(".context-menu");
|
|
|
|
const options = contextMenu?.querySelectorAll(".context-menu-option");
|
2020-06-24 00:24:52 +09:00
|
|
|
const expectedOptions = ["Select all", "Toggle grid mode"];
|
2020-06-05 01:09:16 +05:00
|
|
|
|
|
|
|
expect(contextMenu).not.toBeNull();
|
2020-06-24 00:24:52 +09:00
|
|
|
expect(options?.length).toBe(2);
|
2020-06-05 01:09:16 +05:00
|
|
|
expect(options?.item(0).textContent).toBe(expectedOptions[0]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("shows context menu for element", () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-06-05 01:09:16 +05:00
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(20, 20);
|
2020-07-26 16:29:44 +05:00
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
fireEvent.contextMenu(GlobalTestState.canvas, {
|
|
|
|
button: 2,
|
|
|
|
clientX: 1,
|
|
|
|
clientY: 1,
|
|
|
|
});
|
2020-07-09 22:32:27 +02:00
|
|
|
const contextMenu = document.querySelector(".context-menu");
|
|
|
|
const options = contextMenu?.querySelectorAll(".context-menu-option");
|
|
|
|
const expectedOptions = [
|
|
|
|
"Copy styles",
|
|
|
|
"Paste styles",
|
|
|
|
"Delete",
|
2020-07-10 02:20:23 -07:00
|
|
|
"Add to library",
|
2020-07-09 22:32:27 +02:00
|
|
|
"Send backward",
|
|
|
|
"Bring forward",
|
|
|
|
"Send to back",
|
|
|
|
"Bring to front",
|
|
|
|
"Duplicate",
|
|
|
|
];
|
|
|
|
|
|
|
|
expect(contextMenu).not.toBeNull();
|
2020-07-10 02:20:23 -07:00
|
|
|
expect(contextMenu?.children.length).toBe(9);
|
2020-07-09 22:32:27 +02:00
|
|
|
options?.forEach((opt, i) => {
|
|
|
|
expect(opt.textContent).toBe(expectedOptions[i]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("shows 'Group selection' in context menu for multiple selected elements", () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-07-09 22:32:27 +02:00
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(10, 10);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-07-09 22:32:27 +02:00
|
|
|
mouse.down(10, -10);
|
|
|
|
mouse.up(10, 10);
|
|
|
|
|
|
|
|
mouse.reset();
|
|
|
|
mouse.click(10, 10);
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.withModifierKeys({ shift: true }, () => {
|
2020-07-09 22:32:27 +02:00
|
|
|
mouse.click(20, 0);
|
|
|
|
});
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
fireEvent.contextMenu(GlobalTestState.canvas, {
|
|
|
|
button: 2,
|
|
|
|
clientX: 1,
|
|
|
|
clientY: 1,
|
|
|
|
});
|
2020-07-09 22:32:27 +02:00
|
|
|
|
|
|
|
const contextMenu = document.querySelector(".context-menu");
|
|
|
|
const options = contextMenu?.querySelectorAll(".context-menu-option");
|
|
|
|
const expectedOptions = [
|
|
|
|
"Copy styles",
|
|
|
|
"Paste styles",
|
|
|
|
"Delete",
|
|
|
|
"Group selection",
|
2020-07-10 02:20:23 -07:00
|
|
|
"Add to library",
|
2020-07-09 22:32:27 +02:00
|
|
|
"Send backward",
|
|
|
|
"Bring forward",
|
|
|
|
"Send to back",
|
|
|
|
"Bring to front",
|
|
|
|
"Duplicate",
|
|
|
|
];
|
|
|
|
|
|
|
|
expect(contextMenu).not.toBeNull();
|
2020-07-10 02:20:23 -07:00
|
|
|
expect(contextMenu?.children.length).toBe(10);
|
2020-07-09 22:32:27 +02:00
|
|
|
options?.forEach((opt, i) => {
|
|
|
|
expect(opt.textContent).toBe(expectedOptions[i]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("shows 'Ungroup selection' in context menu for group inside selected elements", () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-07-09 22:32:27 +02:00
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(10, 10);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-07-09 22:32:27 +02:00
|
|
|
mouse.down(10, -10);
|
|
|
|
mouse.up(10, 10);
|
|
|
|
|
|
|
|
mouse.reset();
|
|
|
|
mouse.click(10, 10);
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.withModifierKeys({ shift: true }, () => {
|
2020-07-09 22:32:27 +02:00
|
|
|
mouse.click(20, 0);
|
|
|
|
});
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.withModifierKeys({ ctrl: true }, () => {
|
|
|
|
Keyboard.keyPress("g");
|
2020-07-09 22:32:27 +02:00
|
|
|
});
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
fireEvent.contextMenu(GlobalTestState.canvas, {
|
|
|
|
button: 2,
|
|
|
|
clientX: 1,
|
|
|
|
clientY: 1,
|
|
|
|
});
|
2020-07-09 22:32:27 +02:00
|
|
|
|
2020-06-05 01:09:16 +05:00
|
|
|
const contextMenu = document.querySelector(".context-menu");
|
|
|
|
const options = contextMenu?.querySelectorAll(".context-menu-option");
|
|
|
|
const expectedOptions = [
|
|
|
|
"Copy styles",
|
|
|
|
"Paste styles",
|
|
|
|
"Delete",
|
|
|
|
"Ungroup selection",
|
2020-07-10 02:20:23 -07:00
|
|
|
"Add to library",
|
2020-06-05 01:09:16 +05:00
|
|
|
"Send backward",
|
|
|
|
"Bring forward",
|
|
|
|
"Send to back",
|
|
|
|
"Bring to front",
|
|
|
|
"Duplicate",
|
|
|
|
];
|
|
|
|
|
|
|
|
expect(contextMenu).not.toBeNull();
|
2020-07-26 00:42:06 +02:00
|
|
|
expect(contextMenu?.children.length).toBe(10);
|
2020-06-05 01:09:16 +05:00
|
|
|
options?.forEach((opt, i) => {
|
|
|
|
expect(opt.textContent).toBe(expectedOptions[i]);
|
|
|
|
});
|
|
|
|
});
|
2020-07-26 16:29:44 +05:00
|
|
|
|
|
|
|
it("selecting 'Copy styles' in context menu copies styles", () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-07-26 16:29:44 +05:00
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(20, 20);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
fireEvent.contextMenu(GlobalTestState.canvas, {
|
|
|
|
button: 2,
|
|
|
|
clientX: 1,
|
|
|
|
clientY: 1,
|
|
|
|
});
|
2020-07-26 16:29:44 +05:00
|
|
|
const contextMenu = document.querySelector(".context-menu");
|
|
|
|
expect(copiedStyles).toBe("{}");
|
|
|
|
fireEvent.click(queryByText(contextMenu as HTMLElement, "Copy styles")!);
|
|
|
|
expect(copiedStyles).not.toBe("{}");
|
|
|
|
const element = JSON.parse(copiedStyles);
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(element).toEqual(API.getSelectedElement());
|
2020-07-26 16:29:44 +05:00
|
|
|
});
|
|
|
|
|
|
|
|
it("selecting 'Paste styles' in context menu pastes styles", () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-07-26 16:29:44 +05:00
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(20, 20);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-07-26 16:29:44 +05:00
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(20, 20);
|
|
|
|
|
|
|
|
// Change some styles of second rectangle
|
|
|
|
clickLabeledElement("Stroke");
|
|
|
|
clickLabeledElement("#c92a2a");
|
|
|
|
clickLabeledElement("Background");
|
|
|
|
clickLabeledElement("#e64980");
|
|
|
|
// Fill style
|
|
|
|
fireEvent.click(screen.getByLabelText("Cross-hatch"));
|
|
|
|
// Stroke width
|
|
|
|
fireEvent.click(screen.getByLabelText("Bold"));
|
|
|
|
// Stroke style
|
|
|
|
fireEvent.click(screen.getByLabelText("Dotted"));
|
|
|
|
// Roughness
|
|
|
|
fireEvent.click(screen.getByLabelText("Cartoonist"));
|
|
|
|
// Opacity
|
|
|
|
fireEvent.change(screen.getByLabelText("Opacity"), {
|
|
|
|
target: { value: "60" },
|
|
|
|
});
|
|
|
|
|
|
|
|
mouse.reset();
|
|
|
|
// Copy styles of second rectangle
|
2020-08-28 10:15:29 +02:00
|
|
|
fireEvent.contextMenu(GlobalTestState.canvas, {
|
|
|
|
button: 2,
|
|
|
|
clientX: 40,
|
|
|
|
clientY: 40,
|
|
|
|
});
|
2020-07-26 16:29:44 +05:00
|
|
|
let contextMenu = document.querySelector(".context-menu");
|
|
|
|
fireEvent.click(queryByText(contextMenu as HTMLElement, "Copy styles")!);
|
|
|
|
const secondRect = JSON.parse(copiedStyles);
|
|
|
|
expect(secondRect.id).toBe(h.elements[1].id);
|
|
|
|
|
|
|
|
mouse.reset();
|
|
|
|
// Paste styles to first rectangle
|
2020-08-28 10:15:29 +02:00
|
|
|
fireEvent.contextMenu(GlobalTestState.canvas, {
|
|
|
|
button: 2,
|
|
|
|
clientX: 10,
|
|
|
|
clientY: 10,
|
|
|
|
});
|
2020-07-26 16:29:44 +05:00
|
|
|
contextMenu = document.querySelector(".context-menu");
|
|
|
|
fireEvent.click(queryByText(contextMenu as HTMLElement, "Paste styles")!);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
const firstRect = API.getSelectedElement();
|
2020-07-26 16:29:44 +05:00
|
|
|
expect(firstRect.id).toBe(h.elements[0].id);
|
|
|
|
expect(firstRect.strokeColor).toBe("#c92a2a");
|
|
|
|
expect(firstRect.backgroundColor).toBe("#e64980");
|
|
|
|
expect(firstRect.fillStyle).toBe("cross-hatch");
|
|
|
|
expect(firstRect.strokeWidth).toBe(2); // Bold: 2
|
|
|
|
expect(firstRect.strokeStyle).toBe("dotted");
|
|
|
|
expect(firstRect.roughness).toBe(2); // Cartoonist: 2
|
|
|
|
expect(firstRect.opacity).toBe(60);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("selecting 'Delete' in context menu deletes element", () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-07-26 16:29:44 +05:00
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(20, 20);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
fireEvent.contextMenu(GlobalTestState.canvas, {
|
|
|
|
button: 2,
|
|
|
|
clientX: 1,
|
|
|
|
clientY: 1,
|
|
|
|
});
|
2020-07-26 16:29:44 +05:00
|
|
|
const contextMenu = document.querySelector(".context-menu");
|
|
|
|
fireEvent.click(queryByText(contextMenu as HTMLElement, "Delete")!);
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElements()).toHaveLength(0);
|
2020-07-26 16:29:44 +05:00
|
|
|
expect(h.elements[0].isDeleted).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("selecting 'Add to library' in context menu adds element to library", async () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-07-26 16:29:44 +05:00
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(20, 20);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
fireEvent.contextMenu(GlobalTestState.canvas, {
|
|
|
|
button: 2,
|
|
|
|
clientX: 1,
|
|
|
|
clientY: 1,
|
|
|
|
});
|
2020-07-26 16:29:44 +05:00
|
|
|
const contextMenu = document.querySelector(".context-menu");
|
|
|
|
fireEvent.click(queryByText(contextMenu as HTMLElement, "Add to library")!);
|
|
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
const library = localStorage.getItem("excalidraw-library");
|
|
|
|
expect(library).not.toBeNull();
|
|
|
|
const addedElement = JSON.parse(library!)[0][0];
|
|
|
|
expect(addedElement).toEqual(h.elements[0]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("selecting 'Duplicate' in context menu duplicates element", () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-07-26 16:29:44 +05:00
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(20, 20);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
fireEvent.contextMenu(GlobalTestState.canvas, {
|
|
|
|
button: 2,
|
|
|
|
clientX: 1,
|
|
|
|
clientY: 1,
|
|
|
|
});
|
2020-07-26 16:29:44 +05:00
|
|
|
const contextMenu = document.querySelector(".context-menu");
|
|
|
|
fireEvent.click(queryByText(contextMenu as HTMLElement, "Duplicate")!);
|
|
|
|
expect(h.elements).toHaveLength(2);
|
|
|
|
const { id: _id0, seed: _seed0, x: _x0, y: _y0, ...rect1 } = h.elements[0];
|
|
|
|
const { id: _id1, seed: _seed1, x: _x1, y: _y1, ...rect2 } = h.elements[1];
|
|
|
|
expect(rect1).toEqual(rect2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("selecting 'Send backward' in context menu sends element backward", () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-07-26 16:29:44 +05:00
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(20, 20);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-07-26 16:29:44 +05:00
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(20, 20);
|
|
|
|
|
|
|
|
mouse.reset();
|
2020-08-28 10:15:29 +02:00
|
|
|
fireEvent.contextMenu(GlobalTestState.canvas, {
|
|
|
|
button: 2,
|
|
|
|
clientX: 40,
|
|
|
|
clientY: 40,
|
|
|
|
});
|
2020-07-26 16:29:44 +05:00
|
|
|
const contextMenu = document.querySelector(".context-menu");
|
|
|
|
const elementsBefore = h.elements;
|
|
|
|
fireEvent.click(queryByText(contextMenu as HTMLElement, "Send backward")!);
|
|
|
|
expect(elementsBefore[0].id).toEqual(h.elements[1].id);
|
|
|
|
expect(elementsBefore[1].id).toEqual(h.elements[0].id);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("selecting 'Bring forward' in context menu brings element forward", () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-07-26 16:29:44 +05:00
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(20, 20);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-07-26 16:29:44 +05:00
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(20, 20);
|
|
|
|
|
|
|
|
mouse.reset();
|
2020-08-28 10:15:29 +02:00
|
|
|
fireEvent.contextMenu(GlobalTestState.canvas, {
|
|
|
|
button: 2,
|
|
|
|
clientX: 10,
|
|
|
|
clientY: 10,
|
|
|
|
});
|
2020-07-26 16:29:44 +05:00
|
|
|
const contextMenu = document.querySelector(".context-menu");
|
|
|
|
const elementsBefore = h.elements;
|
|
|
|
fireEvent.click(queryByText(contextMenu as HTMLElement, "Bring forward")!);
|
|
|
|
expect(elementsBefore[0].id).toEqual(h.elements[1].id);
|
|
|
|
expect(elementsBefore[1].id).toEqual(h.elements[0].id);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("selecting 'Send to back' in context menu sends element to back", () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-07-26 16:29:44 +05:00
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(20, 20);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-07-26 16:29:44 +05:00
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(20, 20);
|
|
|
|
|
|
|
|
mouse.reset();
|
2020-08-28 10:15:29 +02:00
|
|
|
fireEvent.contextMenu(GlobalTestState.canvas, {
|
|
|
|
button: 2,
|
|
|
|
clientX: 40,
|
|
|
|
clientY: 40,
|
|
|
|
});
|
2020-07-26 16:29:44 +05:00
|
|
|
const contextMenu = document.querySelector(".context-menu");
|
|
|
|
const elementsBefore = h.elements;
|
|
|
|
fireEvent.click(queryByText(contextMenu as HTMLElement, "Send to back")!);
|
|
|
|
expect(elementsBefore[1].id).toEqual(h.elements[0].id);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("selecting 'Bring to front' in context menu brings element to front", () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-07-26 16:29:44 +05:00
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(20, 20);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-07-26 16:29:44 +05:00
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(20, 20);
|
|
|
|
|
|
|
|
mouse.reset();
|
2020-08-28 10:15:29 +02:00
|
|
|
fireEvent.contextMenu(GlobalTestState.canvas, {
|
|
|
|
button: 2,
|
|
|
|
clientX: 10,
|
|
|
|
clientY: 10,
|
|
|
|
});
|
2020-07-26 16:29:44 +05:00
|
|
|
const contextMenu = document.querySelector(".context-menu");
|
|
|
|
const elementsBefore = h.elements;
|
|
|
|
fireEvent.click(queryByText(contextMenu as HTMLElement, "Bring to front")!);
|
|
|
|
expect(elementsBefore[0].id).toEqual(h.elements[1].id);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("selecting 'Group selection' in context menu groups selected elements", () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-07-26 16:29:44 +05:00
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(20, 20);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-07-26 16:29:44 +05:00
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(20, 20);
|
|
|
|
|
|
|
|
mouse.reset();
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.withModifierKeys({ shift: true }, () => {
|
2020-07-26 16:29:44 +05:00
|
|
|
mouse.click(10, 10);
|
|
|
|
});
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
fireEvent.contextMenu(GlobalTestState.canvas, {
|
|
|
|
button: 2,
|
|
|
|
clientX: 1,
|
|
|
|
clientY: 1,
|
|
|
|
});
|
2020-07-26 16:29:44 +05:00
|
|
|
const contextMenu = document.querySelector(".context-menu");
|
|
|
|
fireEvent.click(
|
|
|
|
queryByText(contextMenu as HTMLElement, "Group selection")!,
|
|
|
|
);
|
|
|
|
const selectedGroupIds = Object.keys(h.state.selectedGroupIds);
|
|
|
|
expect(h.elements[0].groupIds).toEqual(selectedGroupIds);
|
|
|
|
expect(h.elements[1].groupIds).toEqual(selectedGroupIds);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("selecting 'Ungroup selection' in context menu ungroups selected group", () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-07-26 16:29:44 +05:00
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(20, 20);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-07-26 16:29:44 +05:00
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(20, 20);
|
|
|
|
|
|
|
|
mouse.reset();
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.withModifierKeys({ shift: true }, () => {
|
2020-07-26 16:29:44 +05:00
|
|
|
mouse.click(10, 10);
|
|
|
|
});
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.withModifierKeys({ ctrl: true }, () => {
|
|
|
|
Keyboard.keyPress("g");
|
2020-07-26 16:29:44 +05:00
|
|
|
});
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
fireEvent.contextMenu(GlobalTestState.canvas, {
|
|
|
|
button: 2,
|
|
|
|
clientX: 1,
|
|
|
|
clientY: 1,
|
|
|
|
});
|
2020-07-26 16:29:44 +05:00
|
|
|
const contextMenu = document.querySelector(".context-menu");
|
|
|
|
fireEvent.click(
|
|
|
|
queryByText(contextMenu as HTMLElement, "Ungroup selection")!,
|
|
|
|
);
|
|
|
|
|
|
|
|
const selectedGroupIds = Object.keys(h.state.selectedGroupIds);
|
|
|
|
expect(selectedGroupIds).toHaveLength(0);
|
|
|
|
expect(h.elements[0].groupIds).toHaveLength(0);
|
|
|
|
expect(h.elements[1].groupIds).toHaveLength(0);
|
|
|
|
});
|
2020-08-11 11:42:08 +01:00
|
|
|
|
2020-08-26 17:37:44 +01:00
|
|
|
it("deselects selected element, on pointer up, when click hits element bounding box but doesn't hit the element", () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("ellipse");
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.down();
|
2020-08-11 11:42:08 +01:00
|
|
|
mouse.up(100, 100);
|
|
|
|
|
2020-08-26 17:37:44 +01:00
|
|
|
// hits bounding box without hitting element
|
|
|
|
mouse.down();
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElements().length).toBe(1);
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.up();
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElements().length).toBe(0);
|
2020-08-26 17:37:44 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it("switches selected element on pointer down", () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.down();
|
|
|
|
mouse.up(10, 10);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("ellipse");
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(10, 10);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElement().type).toBe("ellipse");
|
2020-08-26 17:37:44 +01:00
|
|
|
|
|
|
|
// pointer down on rectangle
|
|
|
|
mouse.reset();
|
|
|
|
mouse.down();
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElement().type).toBe("rectangle");
|
2020-08-26 17:37:44 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it("can drag element that covers another element, while another elem is selected", () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.down(100, 100);
|
|
|
|
mouse.up(200, 200);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.reset();
|
|
|
|
mouse.down(100, 100);
|
|
|
|
mouse.up(200, 200);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("ellipse");
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.reset();
|
|
|
|
mouse.down(300, 300);
|
|
|
|
mouse.up(350, 350);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElement().type).toBe("ellipse");
|
2020-08-26 17:37:44 +01:00
|
|
|
|
|
|
|
// pointer down on rectangle
|
|
|
|
mouse.reset();
|
|
|
|
mouse.down(100, 100);
|
|
|
|
mouse.up(200, 200);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElement().type).toBe("rectangle");
|
2020-08-26 17:37:44 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it("deselects selected element on pointer down when pointer doesn't hit any element", () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.down();
|
|
|
|
mouse.up(10, 10);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElements().length).toBe(1);
|
2020-08-26 17:37:44 +01:00
|
|
|
|
|
|
|
// pointer down on space without elements
|
|
|
|
mouse.down(100, 100);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElements().length).toBe(0);
|
2020-08-26 17:37:44 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it("Drags selected element when hitting only bounding box and keeps element selected", () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("ellipse");
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.down();
|
|
|
|
mouse.up(10, 10);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
const { x: prevX, y: prevY } = API.getSelectedElement();
|
2020-08-26 17:37:44 +01:00
|
|
|
|
|
|
|
// drag element from point on bounding box that doesn't hit element
|
|
|
|
mouse.reset();
|
|
|
|
mouse.down();
|
|
|
|
mouse.up(25, 25);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElement().x).toEqual(prevX + 25);
|
|
|
|
expect(API.getSelectedElement().y).toEqual(prevY + 25);
|
2020-08-26 17:37:44 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it(
|
|
|
|
"given selected element A with lower z-index than unselected element B and given B is partially over A " +
|
|
|
|
"when clicking intersection between A and B " +
|
|
|
|
"B should be selected on pointer up",
|
|
|
|
() => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-08-26 17:37:44 +01:00
|
|
|
// change background color since default is transparent
|
|
|
|
// and transparent elements can't be selected by clicking inside of them
|
|
|
|
clickLabeledElement("Background");
|
|
|
|
clickLabeledElement("#fa5252");
|
|
|
|
mouse.down();
|
|
|
|
mouse.up(1000, 1000);
|
|
|
|
|
|
|
|
// draw ellipse partially over rectangle.
|
|
|
|
// since ellipse was created after rectangle it has an higher z-index.
|
|
|
|
// we don't need to change background color again since change above
|
|
|
|
// affects next drawn elements.
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("ellipse");
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.reset();
|
|
|
|
mouse.down(500, 500);
|
|
|
|
mouse.up(1000, 1000);
|
|
|
|
|
|
|
|
// select rectangle
|
|
|
|
mouse.reset();
|
|
|
|
mouse.click();
|
|
|
|
|
|
|
|
// pointer down on intersection between ellipse and rectangle
|
|
|
|
mouse.down(900, 900);
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElement().type).toBe("rectangle");
|
2020-08-26 17:37:44 +01:00
|
|
|
|
|
|
|
mouse.up();
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElement().type).toBe("ellipse");
|
2020-08-26 17:37:44 +01:00
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
it(
|
|
|
|
"given selected element A with lower z-index than unselected element B and given B is partially over A " +
|
|
|
|
"when dragging on intersection between A and B " +
|
|
|
|
"A should be dragged and keep being selected",
|
|
|
|
() => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-08-26 17:37:44 +01:00
|
|
|
// change background color since default is transparent
|
|
|
|
// and transparent elements can't be selected by clicking inside of them
|
|
|
|
clickLabeledElement("Background");
|
|
|
|
clickLabeledElement("#fa5252");
|
|
|
|
mouse.down();
|
|
|
|
mouse.up(1000, 1000);
|
|
|
|
|
|
|
|
// draw ellipse partially over rectangle.
|
|
|
|
// since ellipse was created after rectangle it has an higher z-index.
|
|
|
|
// we don't need to change background color again since change above
|
|
|
|
// affects next drawn elements.
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("ellipse");
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.reset();
|
|
|
|
mouse.down(500, 500);
|
|
|
|
mouse.up(1000, 1000);
|
|
|
|
|
|
|
|
// select rectangle
|
|
|
|
mouse.reset();
|
|
|
|
mouse.click();
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
const { x: prevX, y: prevY } = API.getSelectedElement();
|
2020-08-26 17:37:44 +01:00
|
|
|
|
|
|
|
// pointer down on intersection between ellipse and rectangle
|
|
|
|
mouse.down(900, 900);
|
|
|
|
mouse.up(100, 100);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElement().type).toBe("rectangle");
|
|
|
|
expect(API.getSelectedElement().x).toEqual(prevX + 100);
|
|
|
|
expect(API.getSelectedElement().y).toEqual(prevY + 100);
|
2020-08-26 17:37:44 +01:00
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
it("deselects group of selected elements on pointer down when pointer doesn't hit any element", () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.down();
|
|
|
|
mouse.up(10, 10);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("ellipse");
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.down(100, 100);
|
|
|
|
mouse.up(10, 10);
|
|
|
|
|
|
|
|
// Selects first element without deselecting the second element
|
|
|
|
// Second element is already selected because creating it was our last action
|
|
|
|
mouse.reset();
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.withModifierKeys({ shift: true }, () => {
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.click(5, 5);
|
|
|
|
});
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElements().length).toBe(2);
|
2020-08-26 17:37:44 +01:00
|
|
|
|
|
|
|
// pointer down on space without elements
|
|
|
|
mouse.reset();
|
|
|
|
mouse.down(500, 500);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElements().length).toBe(0);
|
2020-08-26 17:37:44 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it("switches from group of selected elements to another element on pointer down", () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.down();
|
|
|
|
mouse.up(10, 10);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("ellipse");
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.down(100, 100);
|
|
|
|
mouse.up(100, 100);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("diamond");
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.down(100, 100);
|
|
|
|
mouse.up(100, 100);
|
|
|
|
|
|
|
|
// Selects ellipse without deselecting the diamond
|
|
|
|
// Diamond is already selected because creating it was our last action
|
|
|
|
mouse.reset();
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.withModifierKeys({ shift: true }, () => {
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.click(110, 160);
|
|
|
|
});
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElements().length).toBe(2);
|
2020-08-26 17:37:44 +01:00
|
|
|
|
|
|
|
// select rectangle
|
|
|
|
mouse.reset();
|
|
|
|
mouse.down();
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElement().type).toBe("rectangle");
|
2020-08-26 17:37:44 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it("deselects group of selected elements on pointer up when pointer hits common bounding box without hitting any element", () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.down();
|
|
|
|
mouse.up(10, 10);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("ellipse");
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.down(100, 100);
|
|
|
|
mouse.up(10, 10);
|
|
|
|
|
|
|
|
// Selects first element without deselecting the second element
|
|
|
|
// Second element is already selected because creating it was our last action
|
|
|
|
mouse.reset();
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.withModifierKeys({ shift: true }, () => {
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.click(5, 5);
|
|
|
|
});
|
|
|
|
|
|
|
|
// pointer down on common bounding box without hitting any of the elements
|
|
|
|
mouse.reset();
|
|
|
|
mouse.down(50, 50);
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElements().length).toBe(2);
|
2020-08-26 17:37:44 +01:00
|
|
|
|
|
|
|
mouse.up();
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElements().length).toBe(0);
|
2020-08-26 17:37:44 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it(
|
|
|
|
"drags selected elements from point inside common bounding box that doesn't hit any element " +
|
|
|
|
"and keeps elements selected after dragging",
|
|
|
|
() => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.down();
|
|
|
|
mouse.up(10, 10);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("ellipse");
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.down(100, 100);
|
|
|
|
mouse.up(10, 10);
|
|
|
|
|
|
|
|
// Selects first element without deselecting the second element
|
|
|
|
// Second element is already selected because creating it was our last action
|
|
|
|
mouse.reset();
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.withModifierKeys({ shift: true }, () => {
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.click(5, 5);
|
|
|
|
});
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElements().length).toBe(2);
|
2020-08-26 17:37:44 +01:00
|
|
|
|
|
|
|
const {
|
|
|
|
x: firstElementPrevX,
|
|
|
|
y: firstElementPrevY,
|
2020-08-28 10:15:29 +02:00
|
|
|
} = API.getSelectedElements()[0];
|
2020-08-26 17:37:44 +01:00
|
|
|
const {
|
|
|
|
x: secondElementPrevX,
|
|
|
|
y: secondElementPrevY,
|
2020-08-28 10:15:29 +02:00
|
|
|
} = API.getSelectedElements()[1];
|
2020-08-26 17:37:44 +01:00
|
|
|
|
|
|
|
// drag elements from point on common bounding box that doesn't hit any of the elements
|
|
|
|
mouse.reset();
|
|
|
|
mouse.down(50, 50);
|
|
|
|
mouse.up(25, 25);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElements()[0].x).toEqual(firstElementPrevX + 25);
|
|
|
|
expect(API.getSelectedElements()[0].y).toEqual(firstElementPrevY + 25);
|
2020-08-26 17:37:44 +01:00
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElements()[1].x).toEqual(secondElementPrevX + 25);
|
|
|
|
expect(API.getSelectedElements()[1].y).toEqual(secondElementPrevY + 25);
|
2020-08-26 17:37:44 +01:00
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElements().length).toBe(2);
|
2020-08-26 17:37:44 +01:00
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
it(
|
|
|
|
"given a group of selected elements with an element that is not selected inside the group common bounding box " +
|
|
|
|
"when element that is not selected is clicked " +
|
|
|
|
"should switch selection to not selected element on pointer up",
|
|
|
|
() => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.down();
|
|
|
|
mouse.up(10, 10);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("ellipse");
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.down(100, 100);
|
|
|
|
mouse.up(100, 100);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("diamond");
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.down(100, 100);
|
|
|
|
mouse.up(100, 100);
|
|
|
|
|
|
|
|
// Selects rectangle without deselecting the diamond
|
|
|
|
// Diamond is already selected because creating it was our last action
|
|
|
|
mouse.reset();
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.withModifierKeys({ shift: true }, () => {
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.click();
|
|
|
|
});
|
|
|
|
|
|
|
|
// pointer down on ellipse
|
|
|
|
mouse.down(110, 160);
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElements().length).toBe(2);
|
2020-08-26 17:37:44 +01:00
|
|
|
|
|
|
|
mouse.up();
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElement().type).toBe("ellipse");
|
2020-08-26 17:37:44 +01:00
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
it(
|
|
|
|
"given a selected element A and a not selected element B with higher z-index than A " +
|
|
|
|
"and given B partialy overlaps A " +
|
|
|
|
"when there's a shift-click on the overlapped section B is added to the selection",
|
|
|
|
() => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-08-26 17:37:44 +01:00
|
|
|
// change background color since default is transparent
|
|
|
|
// and transparent elements can't be selected by clicking inside of them
|
|
|
|
clickLabeledElement("Background");
|
|
|
|
clickLabeledElement("#fa5252");
|
|
|
|
mouse.down();
|
|
|
|
mouse.up(1000, 1000);
|
|
|
|
|
|
|
|
// draw ellipse partially over rectangle.
|
|
|
|
// since ellipse was created after rectangle it has an higher z-index.
|
|
|
|
// we don't need to change background color again since change above
|
|
|
|
// affects next drawn elements.
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("ellipse");
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.reset();
|
|
|
|
mouse.down(500, 500);
|
|
|
|
mouse.up(1000, 1000);
|
|
|
|
|
|
|
|
// select rectangle
|
|
|
|
mouse.reset();
|
|
|
|
mouse.click();
|
|
|
|
|
|
|
|
// click on intersection between ellipse and rectangle
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.withModifierKeys({ shift: true }, () => {
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.click(900, 900);
|
|
|
|
});
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElements().length).toBe(2);
|
2020-08-26 17:37:44 +01:00
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
it("shift click on selected element should deselect it on pointer up", () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.down();
|
|
|
|
mouse.up(10, 10);
|
|
|
|
|
|
|
|
// Rectangle is already selected since creating
|
|
|
|
// it was our last action
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.withModifierKeys({ shift: true }, () => {
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.down();
|
|
|
|
});
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElements().length).toBe(1);
|
2020-08-26 17:37:44 +01:00
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.withModifierKeys({ shift: true }, () => {
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.up();
|
|
|
|
});
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElements().length).toBe(0);
|
2020-08-11 11:42:08 +01:00
|
|
|
});
|
2020-08-27 20:32:10 +02:00
|
|
|
|
|
|
|
it("single-clicking on a subgroup of a selected group should not alter selection", () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
const rect1 = UI.createElement("rectangle", { x: 10 });
|
|
|
|
const rect2 = UI.createElement("rectangle", { x: 50 });
|
|
|
|
UI.group([rect1, rect2]);
|
2020-08-27 20:32:10 +02:00
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
const rect3 = UI.createElement("rectangle", { x: 10, y: 50 });
|
|
|
|
const rect4 = UI.createElement("rectangle", { x: 50, y: 50 });
|
|
|
|
UI.group([rect3, rect4]);
|
2020-08-27 20:32:10 +02:00
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.withModifierKeys({ ctrl: true }, () => {
|
|
|
|
Keyboard.keyPress("a");
|
|
|
|
Keyboard.keyPress("g");
|
2020-08-27 20:32:10 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
const selectedGroupIds_prev = h.state.selectedGroupIds;
|
2020-08-28 10:15:29 +02:00
|
|
|
const selectedElements_prev = API.getSelectedElements();
|
2020-08-27 20:32:10 +02:00
|
|
|
mouse.clickOn(rect3);
|
|
|
|
expect(h.state.selectedGroupIds).toEqual(selectedGroupIds_prev);
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElements()).toEqual(selectedElements_prev);
|
2020-08-27 20:32:10 +02:00
|
|
|
});
|
2020-08-27 20:59:46 +02:00
|
|
|
|
|
|
|
it("Cmd/Ctrl-click exclusively select element under pointer", () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
const rect1 = UI.createElement("rectangle", { x: 0 });
|
|
|
|
const rect2 = UI.createElement("rectangle", { x: 30 });
|
2020-08-27 20:59:46 +02:00
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.group([rect1, rect2]);
|
2020-08-27 20:59:46 +02:00
|
|
|
assertSelectedElements(rect1, rect2);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.withModifierKeys({ ctrl: true }, () => {
|
2020-08-27 20:59:46 +02:00
|
|
|
mouse.clickOn(rect1);
|
|
|
|
});
|
|
|
|
assertSelectedElements(rect1);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
API.clearSelection();
|
|
|
|
Keyboard.withModifierKeys({ ctrl: true }, () => {
|
2020-08-27 20:59:46 +02:00
|
|
|
mouse.clickOn(rect1);
|
|
|
|
});
|
|
|
|
assertSelectedElements(rect1);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
const rect3 = UI.createElement("rectangle", { x: 60 });
|
|
|
|
UI.group([rect1, rect3]);
|
2020-08-27 20:59:46 +02:00
|
|
|
assertSelectedElements(rect1, rect2, rect3);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.withModifierKeys({ ctrl: true }, () => {
|
2020-08-27 20:59:46 +02:00
|
|
|
mouse.clickOn(rect1);
|
|
|
|
});
|
|
|
|
assertSelectedElements(rect1);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
API.clearSelection();
|
|
|
|
Keyboard.withModifierKeys({ ctrl: true }, () => {
|
2020-08-27 20:59:46 +02:00
|
|
|
mouse.clickOn(rect3);
|
|
|
|
});
|
|
|
|
assertSelectedElements(rect3);
|
|
|
|
});
|
2020-03-23 16:38:41 -07:00
|
|
|
});
|
2020-08-26 17:37:44 +01:00
|
|
|
|
|
|
|
it(
|
|
|
|
"given element A and group of elements B and given both are selected " +
|
|
|
|
"when user clicks on B, on pointer up " +
|
|
|
|
"only elements from B should be selected",
|
|
|
|
() => {
|
2020-08-28 10:15:29 +02:00
|
|
|
const rect1 = UI.createElement("rectangle", { y: 0 });
|
|
|
|
const rect2 = UI.createElement("rectangle", { y: 30 });
|
|
|
|
const rect3 = UI.createElement("rectangle", { y: 60 });
|
2020-08-26 17:37:44 +01:00
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.group([rect1, rect3]);
|
2020-08-26 17:37:44 +01:00
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElements().length).toBe(2);
|
2020-08-27 20:32:10 +02:00
|
|
|
expect(Object.keys(h.state.selectedGroupIds).length).toBe(1);
|
2020-08-26 17:37:44 +01:00
|
|
|
|
|
|
|
// Select second rectangle without deselecting group
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.withModifierKeys({ shift: true }, () => {
|
2020-08-27 20:32:10 +02:00
|
|
|
mouse.clickOn(rect2);
|
2020-08-26 17:37:44 +01:00
|
|
|
});
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElements().length).toBe(3);
|
2020-08-26 17:37:44 +01:00
|
|
|
|
2020-08-27 20:32:10 +02:00
|
|
|
// clicking on first rectangle that is part of the group should select
|
|
|
|
// that group (exclusively)
|
|
|
|
mouse.clickOn(rect1);
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElements().length).toBe(2);
|
2020-08-27 20:32:10 +02:00
|
|
|
expect(Object.keys(h.state.selectedGroupIds).length).toBe(1);
|
2020-08-26 17:37:44 +01:00
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
it(
|
|
|
|
"given element A and group of elements B and given both are selected " +
|
|
|
|
"when user shift-clicks on B, on pointer up " +
|
|
|
|
"only element A should be selected",
|
|
|
|
() => {
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.down();
|
|
|
|
mouse.up(100, 100);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(100, 100);
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
UI.clickTool("rectangle");
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(100, 100);
|
|
|
|
|
|
|
|
// Select first rectangle while keeping third one selected.
|
|
|
|
// Third rectangle is selected because it was the last element
|
|
|
|
// to be created.
|
|
|
|
mouse.reset();
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.withModifierKeys({ shift: true }, () => {
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.click();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Create group with first and third rectangle
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.withModifierKeys({ ctrl: true }, () => {
|
|
|
|
Keyboard.keyPress("g");
|
2020-08-26 17:37:44 +01:00
|
|
|
});
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElements().length).toBe(2);
|
2020-08-26 17:37:44 +01:00
|
|
|
const selectedGroupIds = Object.keys(h.state.selectedGroupIds);
|
|
|
|
expect(selectedGroupIds.length).toBe(1);
|
|
|
|
|
|
|
|
// Select second rectangle without deselecting group
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.withModifierKeys({ shift: true }, () => {
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.click(110, 110);
|
|
|
|
});
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElements().length).toBe(3);
|
2020-08-26 17:37:44 +01:00
|
|
|
|
|
|
|
// pointer down o first rectangle that is
|
|
|
|
// part of the group
|
|
|
|
mouse.reset();
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.withModifierKeys({ shift: true }, () => {
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.down();
|
|
|
|
});
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElements().length).toBe(3);
|
|
|
|
Keyboard.withModifierKeys({ shift: true }, () => {
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.up();
|
|
|
|
});
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElements().length).toBe(1);
|
2020-08-26 17:37:44 +01:00
|
|
|
},
|
|
|
|
);
|