2020-03-23 16:38:41 -07:00
|
|
|
import ReactDOM from "react-dom";
|
2020-12-07 18:35:16 +02:00
|
|
|
import { ExcalidrawElement } from "../element/types";
|
|
|
|
import { CODES, KEYS } from "../keys";
|
2021-01-04 02:21:52 +05:30
|
|
|
import ExcalidrawApp from "../excalidraw-app";
|
2020-12-07 18:35:16 +02:00
|
|
|
import { reseed } from "../random";
|
2020-03-23 16:38:41 -07:00
|
|
|
import * as Renderer from "../renderer/renderScene";
|
2020-12-07 18:35:16 +02:00
|
|
|
import { setDateTimeForTests } from "../utils";
|
|
|
|
import { API } from "./helpers/api";
|
|
|
|
import { Keyboard, Pointer, UI } from "./helpers/ui";
|
2021-05-29 21:35:03 +02:00
|
|
|
import {
|
|
|
|
assertSelectedElements,
|
|
|
|
fireEvent,
|
|
|
|
render,
|
|
|
|
screen,
|
|
|
|
waitFor,
|
|
|
|
} from "./test-utils";
|
2021-01-04 02:21:52 +05:30
|
|
|
import { defaultLang } from "../i18n";
|
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-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
|
|
|
|
|
|
|
/**
|
|
|
|
* 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();
|
|
|
|
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
|
|
|
|
2021-01-04 02:21:52 +05:30
|
|
|
await render(<ExcalidrawApp />);
|
2021-04-04 15:05:16 +05:30
|
|
|
h.setState({ height: 768, width: 1024 });
|
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-12-01 23:36:06 +02:00
|
|
|
Keyboard.keyPress(KEYS.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-12-01 23:36:06 +02:00
|
|
|
Keyboard.keyPress(KEYS.ENTER);
|
2020-05-12 20:10:11 +01:00
|
|
|
|
2021-05-09 16:42:10 +01:00
|
|
|
UI.clickTool("freedraw");
|
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",
|
2021-05-09 16:42:10 +01:00
|
|
|
"freedraw",
|
2020-05-28 01:56:18 -07:00
|
|
|
]);
|
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
|
|
|
});
|
|
|
|
|
2021-01-05 18:34:06 +05:30
|
|
|
for (const [keys, shape, shouldSelect] of [
|
|
|
|
[`2${KEYS.R}`, "rectangle", true],
|
|
|
|
[`3${KEYS.D}`, "diamond", true],
|
|
|
|
[`4${KEYS.E}`, "ellipse", true],
|
|
|
|
[`5${KEYS.A}`, "arrow", true],
|
|
|
|
[`6${KEYS.L}`, "line", true],
|
2021-05-09 16:42:10 +01:00
|
|
|
[`7${KEYS.X}`, "freedraw", false],
|
2021-01-05 18:34:06 +05:30
|
|
|
] as [string, ExcalidrawElement["type"], boolean][]) {
|
2020-03-23 16:38:41 -07:00
|
|
|
for (const key of keys) {
|
2020-12-01 23:36:06 +02:00
|
|
|
it(`key ${key} selects ${shape} tool`, () => {
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.keyPress(key);
|
2020-03-23 16:38:41 -07:00
|
|
|
|
2021-01-05 18:34:06 +05:30
|
|
|
expect(h.state.elementType).toBe(shape);
|
|
|
|
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(10, 10);
|
2020-03-23 16:38:41 -07:00
|
|
|
|
2021-01-05 18:34:06 +05:30
|
|
|
if (shouldSelect) {
|
|
|
|
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("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", () => {
|
2020-11-04 17:49:15 +00:00
|
|
|
expect(h.state.zoom.value).toBe(1);
|
2020-05-28 01:56:18 -07:00
|
|
|
finger1.down(50, 50);
|
|
|
|
finger2.down(60, 50);
|
|
|
|
finger1.move(-10, 0);
|
2020-11-04 17:49:15 +00:00
|
|
|
expect(h.state.zoom.value).toBeGreaterThan(1);
|
|
|
|
const zoomed = h.state.zoom.value;
|
2020-05-28 01:56:18 -07:00
|
|
|
finger1.move(5, 0);
|
|
|
|
finger2.move(-5, 0);
|
2020-11-04 17:49:15 +00:00
|
|
|
expect(h.state.zoom.value).toBeLessThan(zoomed);
|
2020-03-23 16:38:41 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
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-12-01 23:36:06 +02:00
|
|
|
Keyboard.keyDown(KEYS.SPACE);
|
2020-05-28 01:56:18 -07:00
|
|
|
mouse.down(50, 50);
|
|
|
|
mouse.up(60, 60);
|
2020-12-01 23:36:06 +02:00
|
|
|
Keyboard.keyUp(KEYS.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-12-01 23:36:06 +02:00
|
|
|
Keyboard.keyPress(KEYS.ARROW_LEFT);
|
|
|
|
Keyboard.keyPress(KEYS.ARROW_LEFT);
|
|
|
|
Keyboard.keyPress(KEYS.ARROW_RIGHT);
|
|
|
|
Keyboard.keyPress(KEYS.ARROW_UP);
|
|
|
|
Keyboard.keyPress(KEYS.ARROW_UP);
|
|
|
|
Keyboard.keyPress(KEYS.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-12-01 23:36:06 +02:00
|
|
|
Keyboard.keyPress(KEYS.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 }, () => {
|
2020-12-01 23:36:06 +02:00
|
|
|
Keyboard.keyPress(KEYS.Z);
|
|
|
|
Keyboard.keyPress(KEYS.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 }, () => {
|
2020-12-01 23:36:06 +02:00
|
|
|
Keyboard.keyPress(KEYS.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 }, () => {
|
2020-12-01 23:36:06 +02:00
|
|
|
Keyboard.keyPress(KEYS.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 }, () => {
|
2020-12-01 23:36:06 +02:00
|
|
|
Keyboard.keyPress(KEYS.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 }, () => {
|
2020-12-01 23:36:06 +02:00
|
|
|
Keyboard.keyPress(KEYS.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", () => {
|
2020-11-04 17:49:15 +00:00
|
|
|
expect(h.state.zoom.value).toBe(1);
|
2021-04-13 01:29:25 +05:30
|
|
|
fireEvent.keyDown(document, {
|
|
|
|
code: CODES.EQUAL,
|
|
|
|
ctrlKey: true,
|
|
|
|
});
|
|
|
|
fireEvent.keyUp(document, {
|
|
|
|
code: CODES.EQUAL,
|
|
|
|
ctrlKey: true,
|
|
|
|
});
|
2020-11-04 17:49:15 +00:00
|
|
|
expect(h.state.zoom.value).toBeGreaterThan(1);
|
2021-04-13 01:29:25 +05:30
|
|
|
fireEvent.keyDown(document, {
|
|
|
|
code: CODES.MINUS,
|
|
|
|
ctrlKey: true,
|
|
|
|
});
|
|
|
|
fireEvent.keyUp(document, {
|
|
|
|
code: CODES.MINUS,
|
|
|
|
ctrlKey: true,
|
|
|
|
});
|
2020-11-04 17:49:15 +00:00
|
|
|
expect(h.state.zoom.value).toBe(1);
|
2020-03-23 16:38:41 -07:00
|
|
|
});
|
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-11-27 02:13:38 +05:30
|
|
|
// english lang should display `thin` label
|
|
|
|
expect(screen.queryByTitle(/thin/i)).not.toBeNull();
|
2020-05-27 16:46:11 +02:00
|
|
|
fireEvent.change(document.querySelector(".dropdown-select__language")!, {
|
|
|
|
target: { value: "de-DE" },
|
|
|
|
});
|
2020-11-27 02:13:38 +05:30
|
|
|
// switching to german, `thin` label should no longer exist
|
|
|
|
await waitFor(() => expect(screen.queryByTitle(/thin/i)).toBeNull());
|
2020-06-05 01:09:16 +05:00
|
|
|
// reset language
|
|
|
|
fireEvent.change(document.querySelector(".dropdown-select__language")!, {
|
2021-01-04 02:21:52 +05:30
|
|
|
target: { value: defaultLang.code },
|
2020-06-05 01:09:16 +05:00
|
|
|
});
|
2020-06-27 12:02:54 +01:00
|
|
|
// switching back to English
|
2020-11-27 02:13:38 +05:30
|
|
|
await waitFor(() => expect(screen.queryByTitle(/thin/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 }, () => {
|
2020-12-01 23:36:06 +02:00
|
|
|
Keyboard.codePress(CODES.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 }, () => {
|
2020-12-01 23:36:06 +02:00
|
|
|
Keyboard.keyPress(KEYS.A);
|
|
|
|
Keyboard.codePress(CODES.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 }, () => {
|
2020-12-01 23:36:06 +02:00
|
|
|
Keyboard.codePress(CODES.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", () => {
|
2020-12-26 02:34:47 +08:00
|
|
|
const rectA = UI.createElement("rectangle", { position: 0, size: 50 });
|
|
|
|
const rectB = UI.createElement("rectangle", { position: 100, size: 50 });
|
|
|
|
const rectC = UI.createElement("rectangle", { position: 200, size: 50 });
|
2020-05-28 01:56:18 -07:00
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.withModifierKeys({ ctrl: true }, () => {
|
2020-12-01 23:36:06 +02:00
|
|
|
Keyboard.keyPress(KEYS.A);
|
|
|
|
Keyboard.codePress(CODES.G);
|
2020-05-28 01:56:18 -07:00
|
|
|
});
|
|
|
|
|
2020-12-26 02:34:47 +08:00
|
|
|
mouse.doubleClickOn(rectC);
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.withModifierKeys({ shift: true }, () => {
|
2020-12-26 02:34:47 +08:00
|
|
|
mouse.clickOn(rectA);
|
2020-05-28 01:56:18 -07:00
|
|
|
});
|
2020-08-28 10:15:29 +02:00
|
|
|
Keyboard.withModifierKeys({ ctrl: true }, () => {
|
2020-12-01 23:36:06 +02:00
|
|
|
Keyboard.codePress(CODES.G);
|
2020-05-28 01:56:18 -07:00
|
|
|
});
|
|
|
|
|
2020-12-26 02:34:47 +08:00
|
|
|
expect(rectC.groupIds.length).toBe(2);
|
|
|
|
expect(rectA.groupIds).toEqual(rectC.groupIds);
|
|
|
|
expect(rectB.groupIds).toEqual(rectA.groupIds.slice(1));
|
2020-05-28 01:56:18 -07:00
|
|
|
|
2020-12-26 02:34:47 +08:00
|
|
|
mouse.click(0, 100);
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElements().length).toBe(0);
|
2020-12-26 02:34:47 +08:00
|
|
|
|
|
|
|
mouse.clickOn(rectA);
|
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);
|
|
|
|
|
2020-12-26 02:34:47 +08:00
|
|
|
mouse.doubleClickOn(rectA);
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElements().length).toBe(2);
|
2020-12-26 02:34:47 +08:00
|
|
|
expect(h.state.editingGroupId).toBe(rectA.groupIds[1]);
|
2020-05-28 01:56:18 -07:00
|
|
|
|
2020-12-26 02:34:47 +08:00
|
|
|
mouse.doubleClickOn(rectA);
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElements().length).toBe(1);
|
2020-12-26 02:34:47 +08:00
|
|
|
expect(h.state.editingGroupId).toBe(rectA.groupIds[0]);
|
2020-05-28 01:56:18 -07:00
|
|
|
|
2020-12-26 02:34:47 +08:00
|
|
|
// click outside current (sub)group
|
|
|
|
mouse.clickOn(rectB);
|
2020-08-28 10:15:29 +02:00
|
|
|
expect(API.getSelectedElements().length).toBe(3);
|
2020-12-26 02:34:47 +08:00
|
|
|
mouse.doubleClickOn(rectB);
|
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
|
2021-03-22 18:56:35 +05:30
|
|
|
fireEvent.click(screen.getByTitle(/code/i));
|
2020-05-29 21:59:39 +02:00
|
|
|
expect(h.state.currentItemFontFamily).toEqual(3); // Cascadia
|
|
|
|
});
|
2020-06-05 01:09:16 +05: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",
|
|
|
|
() => {
|
2021-05-28 17:22:42 +05:30
|
|
|
// set background color since default is transparent
|
2020-08-26 17:37:44 +01:00
|
|
|
// and transparent elements can't be selected by clicking inside of them
|
2021-05-28 17:22:42 +05:30
|
|
|
const rect1 = API.createElement({
|
|
|
|
type: "rectangle",
|
|
|
|
backgroundColor: "red",
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
width: 1000,
|
|
|
|
height: 1000,
|
|
|
|
});
|
|
|
|
const rect2 = API.createElement({
|
|
|
|
type: "rectangle",
|
|
|
|
backgroundColor: "red",
|
|
|
|
x: 500,
|
|
|
|
y: 500,
|
|
|
|
width: 500,
|
|
|
|
height: 500,
|
|
|
|
});
|
|
|
|
h.elements = [rect1, rect2];
|
2020-08-26 17:37:44 +01:00
|
|
|
|
2021-05-28 17:22:42 +05:30
|
|
|
mouse.select(rect1);
|
|
|
|
|
|
|
|
// pointerdown on rect2 covering rect1 while rect1 is selected should
|
|
|
|
// retain rect1 selection
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.down(900, 900);
|
2021-05-28 17:22:42 +05:30
|
|
|
expect(API.getSelectedElement().id).toBe(rect1.id);
|
2020-08-26 17:37:44 +01:00
|
|
|
|
2021-05-28 17:22:42 +05:30
|
|
|
// pointerup should select rect2
|
2020-08-26 17:37:44 +01:00
|
|
|
mouse.up();
|
2021-05-28 17:22:42 +05:30
|
|
|
expect(API.getSelectedElement().id).toBe(rect2.id);
|
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",
|
|
|
|
() => {
|
2021-05-28 17:22:42 +05:30
|
|
|
const rect1 = API.createElement({
|
|
|
|
type: "rectangle",
|
|
|
|
backgroundColor: "red",
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
width: 1000,
|
|
|
|
height: 1000,
|
|
|
|
});
|
|
|
|
const rect2 = API.createElement({
|
|
|
|
type: "rectangle",
|
|
|
|
backgroundColor: "red",
|
|
|
|
x: 500,
|
|
|
|
y: 500,
|
|
|
|
width: 500,
|
|
|
|
height: 500,
|
|
|
|
});
|
|
|
|
h.elements = [rect1, rect2];
|
|
|
|
|
|
|
|
mouse.select(rect1);
|
|
|
|
|
|
|
|
expect(API.getSelectedElement().id).toBe(rect1.id);
|
2020-08-26 17:37:44 +01:00
|
|
|
|
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);
|
|
|
|
|
2021-05-28 17:22:42 +05:30
|
|
|
expect(API.getSelectedElement().id).toBe(rect1.id);
|
2020-08-28 10:15:29 +02:00
|
|
|
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 }, () => {
|
2020-12-01 23:36:06 +02:00
|
|
|
Keyboard.keyPress(KEYS.A);
|
|
|
|
Keyboard.codePress(CODES.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-11-27 02:13:38 +05:30
|
|
|
|
|
|
|
it("should show fill icons when element has non transparent background", () => {
|
|
|
|
UI.clickTool("rectangle");
|
|
|
|
expect(screen.queryByText(/fill/i)).not.toBeNull();
|
|
|
|
mouse.down();
|
|
|
|
mouse.up(10, 10);
|
|
|
|
expect(screen.queryByText(/fill/i)).toBeNull();
|
|
|
|
|
|
|
|
clickLabeledElement("Background");
|
|
|
|
clickLabeledElement("#fa5252");
|
|
|
|
// select rectangle
|
|
|
|
mouse.reset();
|
|
|
|
mouse.click();
|
|
|
|
expect(screen.queryByText(/fill/i)).not.toBeNull();
|
|
|
|
});
|
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
|
2020-11-05 19:06:18 +02:00
|
|
|
// that group (exclusively)
|
2020-08-27 20:32:10 +02:00
|
|
|
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.
|
2020-11-05 19:06:18 +02:00
|
|
|
// Third rectangle is selected because it was the last element to be created.
|
2020-08-26 17:37:44 +01:00
|
|
|
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 }, () => {
|
2020-12-01 23:36:06 +02:00
|
|
|
Keyboard.codePress(CODES.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
|
|
|
|
2020-11-05 19:06:18 +02:00
|
|
|
// Pointer down o first rectangle that is part of the group
|
2020-08-26 17:37:44 +01:00
|
|
|
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
|
|
|
},
|
|
|
|
);
|