2020-10-31 11:40:06 +01:00
|
|
|
import ReactDOM from "react-dom";
|
|
|
|
import { render } from "./test-utils";
|
2020-12-05 20:00:53 +05:30
|
|
|
import ExcalidrawApp from "../excalidraw-app";
|
2021-01-04 02:21:52 +05:30
|
|
|
import { defaultLang, setLanguage } from "../i18n";
|
2020-10-31 11:40:06 +01:00
|
|
|
import { UI, Pointer, Keyboard } from "./helpers/ui";
|
|
|
|
import { API } from "./helpers/api";
|
|
|
|
import { KEYS } from "../keys";
|
|
|
|
import {
|
|
|
|
actionAlignVerticallyCentered,
|
|
|
|
actionAlignHorizontallyCentered,
|
|
|
|
actionGroup,
|
|
|
|
actionAlignTop,
|
|
|
|
actionAlignBottom,
|
|
|
|
actionAlignLeft,
|
|
|
|
actionAlignRight,
|
|
|
|
} from "../actions";
|
|
|
|
|
|
|
|
const { h } = window;
|
|
|
|
|
|
|
|
const mouse = new Pointer("mouse");
|
|
|
|
|
2020-11-06 22:06:39 +02:00
|
|
|
const createAndSelectTwoRectangles = () => {
|
2020-10-31 11:40:06 +01:00
|
|
|
UI.clickTool("rectangle");
|
|
|
|
mouse.down();
|
|
|
|
mouse.up(100, 100);
|
|
|
|
|
|
|
|
UI.clickTool("rectangle");
|
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(100, 100);
|
|
|
|
|
|
|
|
// Select the first element.
|
|
|
|
// The second rectangle is already reselected because it was the last element created
|
|
|
|
mouse.reset();
|
|
|
|
Keyboard.withModifierKeys({ shift: true }, () => {
|
|
|
|
mouse.click();
|
|
|
|
});
|
2020-11-06 22:06:39 +02:00
|
|
|
};
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-11-06 22:06:39 +02:00
|
|
|
const createAndSelectTwoRectanglesWithDifferentSizes = () => {
|
2020-10-31 11:40:06 +01:00
|
|
|
UI.clickTool("rectangle");
|
|
|
|
mouse.down();
|
|
|
|
mouse.up(100, 100);
|
|
|
|
|
|
|
|
UI.clickTool("rectangle");
|
|
|
|
mouse.down(10, 10);
|
|
|
|
mouse.up(110, 110);
|
|
|
|
|
|
|
|
// Select the first element.
|
|
|
|
// The second rectangle is already reselected because it was the last element created
|
|
|
|
mouse.reset();
|
|
|
|
Keyboard.withModifierKeys({ shift: true }, () => {
|
|
|
|
mouse.click();
|
|
|
|
});
|
2020-11-06 22:06:39 +02:00
|
|
|
};
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
describe("aligning", () => {
|
|
|
|
beforeEach(async () => {
|
|
|
|
// Unmount ReactDOM from root
|
|
|
|
ReactDOM.unmountComponentAtNode(document.getElementById("root")!);
|
|
|
|
mouse.reset();
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2021-01-04 02:21:52 +05:30
|
|
|
await setLanguage(defaultLang);
|
2020-12-05 20:00:53 +05:30
|
|
|
await render(<ExcalidrawApp />);
|
2020-10-31 11:40:06 +01:00
|
|
|
});
|
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
it("aligns two objects correctly to the top", () => {
|
|
|
|
createAndSelectTwoRectangles();
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].x).toEqual(110);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].y).toEqual(110);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
Keyboard.withModifierKeys({ ctrl: true, shift: true }, () => {
|
|
|
|
Keyboard.keyPress(KEYS.ARROW_UP);
|
|
|
|
});
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
// Check if x position did not change
|
|
|
|
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].x).toEqual(110);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].y).toEqual(0);
|
2020-10-31 11:40:06 +01:00
|
|
|
});
|
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
it("aligns two objects correctly to the bottom", () => {
|
|
|
|
createAndSelectTwoRectangles();
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].x).toEqual(110);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].y).toEqual(110);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
Keyboard.withModifierKeys({ ctrl: true, shift: true }, () => {
|
|
|
|
Keyboard.keyPress(KEYS.ARROW_DOWN);
|
|
|
|
});
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
// Check if x position did not change
|
|
|
|
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].x).toEqual(110);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].y).toEqual(110);
|
|
|
|
expect(API.getSelectedElements()[1].y).toEqual(110);
|
2020-10-31 11:40:06 +01:00
|
|
|
});
|
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
it("aligns two objects correctly to the left", () => {
|
|
|
|
createAndSelectTwoRectangles();
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].x).toEqual(110);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].y).toEqual(110);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
Keyboard.withModifierKeys({ ctrl: true, shift: true }, () => {
|
|
|
|
Keyboard.keyPress(KEYS.ARROW_LEFT);
|
|
|
|
});
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].x).toEqual(0);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
// Check if y position did not change
|
|
|
|
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].y).toEqual(110);
|
2020-10-31 11:40:06 +01:00
|
|
|
});
|
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
it("aligns two objects correctly to the right", () => {
|
|
|
|
createAndSelectTwoRectangles();
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].x).toEqual(110);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].y).toEqual(110);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
Keyboard.withModifierKeys({ ctrl: true, shift: true }, () => {
|
|
|
|
Keyboard.keyPress(KEYS.ARROW_RIGHT);
|
|
|
|
});
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].x).toEqual(110);
|
|
|
|
expect(API.getSelectedElements()[1].x).toEqual(110);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
// Check if y position did not change
|
|
|
|
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].y).toEqual(110);
|
|
|
|
});
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
it("centers two objects with different sizes correctly vertically", () => {
|
|
|
|
createAndSelectTwoRectanglesWithDifferentSizes();
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].x).toEqual(110);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].y).toEqual(110);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
h.app.actionManager.executeAction(actionAlignVerticallyCentered);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
// Check if x position did not change
|
|
|
|
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].x).toEqual(110);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].y).toEqual(60);
|
|
|
|
expect(API.getSelectedElements()[1].y).toEqual(55);
|
|
|
|
});
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
it("centers two objects with different sizes correctly horizontally", () => {
|
|
|
|
createAndSelectTwoRectanglesWithDifferentSizes();
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].x).toEqual(110);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].y).toEqual(110);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
h.app.actionManager.executeAction(actionAlignHorizontallyCentered);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].x).toEqual(60);
|
|
|
|
expect(API.getSelectedElements()[1].x).toEqual(55);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
// Check if y position did not change
|
|
|
|
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].y).toEqual(110);
|
2020-10-31 11:40:06 +01:00
|
|
|
});
|
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
const createAndSelectGroupAndRectangle = () => {
|
|
|
|
UI.clickTool("rectangle");
|
|
|
|
mouse.down();
|
|
|
|
mouse.up(100, 100);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
UI.clickTool("rectangle");
|
|
|
|
mouse.down(0, 0);
|
|
|
|
mouse.up(100, 100);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
// Select the first element.
|
|
|
|
// The second rectangle is already reselected because it was the last element created
|
|
|
|
mouse.reset();
|
|
|
|
Keyboard.withModifierKeys({ shift: true }, () => {
|
|
|
|
mouse.click();
|
|
|
|
});
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
h.app.actionManager.executeAction(actionGroup);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
mouse.reset();
|
|
|
|
UI.clickTool("rectangle");
|
|
|
|
mouse.down(200, 200);
|
|
|
|
mouse.up(100, 100);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
// Add the created group to the current selection
|
|
|
|
mouse.restorePosition(0, 0);
|
|
|
|
Keyboard.withModifierKeys({ shift: true }, () => {
|
|
|
|
mouse.click();
|
|
|
|
});
|
|
|
|
};
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
it("aligns a group with another element correctly to the top", () => {
|
|
|
|
createAndSelectGroupAndRectangle();
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].y).toEqual(100);
|
|
|
|
expect(API.getSelectedElements()[2].y).toEqual(200);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
h.app.actionManager.executeAction(actionAlignTop);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].y).toEqual(100);
|
|
|
|
expect(API.getSelectedElements()[2].y).toEqual(0);
|
|
|
|
});
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
it("aligns a group with another element correctly to the bottom", () => {
|
|
|
|
createAndSelectGroupAndRectangle();
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].y).toEqual(100);
|
|
|
|
expect(API.getSelectedElements()[2].y).toEqual(200);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
h.app.actionManager.executeAction(actionAlignBottom);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].y).toEqual(100);
|
|
|
|
expect(API.getSelectedElements()[1].y).toEqual(200);
|
|
|
|
expect(API.getSelectedElements()[2].y).toEqual(200);
|
|
|
|
});
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
it("aligns a group with another element correctly to the left", () => {
|
|
|
|
createAndSelectGroupAndRectangle();
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].x).toEqual(100);
|
|
|
|
expect(API.getSelectedElements()[2].x).toEqual(200);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
h.app.actionManager.executeAction(actionAlignLeft);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].x).toEqual(100);
|
|
|
|
expect(API.getSelectedElements()[2].x).toEqual(0);
|
|
|
|
});
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
it("aligns a group with another element correctly to the right", () => {
|
|
|
|
createAndSelectGroupAndRectangle();
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].x).toEqual(100);
|
|
|
|
expect(API.getSelectedElements()[2].x).toEqual(200);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
h.app.actionManager.executeAction(actionAlignRight);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].x).toEqual(100);
|
|
|
|
expect(API.getSelectedElements()[1].x).toEqual(200);
|
|
|
|
expect(API.getSelectedElements()[2].x).toEqual(200);
|
|
|
|
});
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
it("centers a group with another element correctly vertically", () => {
|
|
|
|
createAndSelectGroupAndRectangle();
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].y).toEqual(100);
|
|
|
|
expect(API.getSelectedElements()[2].y).toEqual(200);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
h.app.actionManager.executeAction(actionAlignVerticallyCentered);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].y).toEqual(50);
|
|
|
|
expect(API.getSelectedElements()[1].y).toEqual(150);
|
|
|
|
expect(API.getSelectedElements()[2].y).toEqual(100);
|
2020-10-31 11:40:06 +01:00
|
|
|
});
|
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
it("centers a group with another element correctly horizontally", () => {
|
|
|
|
createAndSelectGroupAndRectangle();
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].x).toEqual(100);
|
|
|
|
expect(API.getSelectedElements()[2].x).toEqual(200);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
h.app.actionManager.executeAction(actionAlignHorizontallyCentered);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].x).toEqual(50);
|
|
|
|
expect(API.getSelectedElements()[1].x).toEqual(150);
|
|
|
|
expect(API.getSelectedElements()[2].x).toEqual(100);
|
2020-10-31 11:40:06 +01:00
|
|
|
});
|
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
const createAndSelectTwoGroups = () => {
|
|
|
|
UI.clickTool("rectangle");
|
|
|
|
mouse.down();
|
|
|
|
mouse.up(100, 100);
|
|
|
|
|
|
|
|
UI.clickTool("rectangle");
|
|
|
|
mouse.down(0, 0);
|
|
|
|
mouse.up(100, 100);
|
|
|
|
|
|
|
|
// Select the first element.
|
|
|
|
// The second rectangle is already selected because it was the last element created
|
|
|
|
mouse.reset();
|
|
|
|
Keyboard.withModifierKeys({ shift: true }, () => {
|
|
|
|
mouse.click();
|
|
|
|
});
|
|
|
|
|
|
|
|
h.app.actionManager.executeAction(actionGroup);
|
|
|
|
|
|
|
|
mouse.reset();
|
|
|
|
UI.clickTool("rectangle");
|
|
|
|
mouse.down(200, 200);
|
|
|
|
mouse.up(100, 100);
|
|
|
|
|
|
|
|
UI.clickTool("rectangle");
|
|
|
|
mouse.down();
|
|
|
|
mouse.up(100, 100);
|
|
|
|
|
|
|
|
mouse.restorePosition(200, 200);
|
|
|
|
Keyboard.withModifierKeys({ shift: true }, () => {
|
|
|
|
mouse.click();
|
|
|
|
});
|
|
|
|
|
|
|
|
h.app.actionManager.executeAction(actionGroup);
|
|
|
|
|
|
|
|
// Select the first group.
|
|
|
|
// The second group is already selected because it was the last group created
|
|
|
|
mouse.reset();
|
|
|
|
Keyboard.withModifierKeys({ shift: true }, () => {
|
|
|
|
mouse.click();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
it("aligns two groups correctly to the top", () => {
|
|
|
|
createAndSelectTwoGroups();
|
|
|
|
|
|
|
|
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].y).toEqual(100);
|
|
|
|
expect(API.getSelectedElements()[2].y).toEqual(200);
|
|
|
|
expect(API.getSelectedElements()[3].y).toEqual(300);
|
|
|
|
|
|
|
|
h.app.actionManager.executeAction(actionAlignTop);
|
|
|
|
|
|
|
|
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].y).toEqual(100);
|
|
|
|
expect(API.getSelectedElements()[2].y).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[3].y).toEqual(100);
|
2020-10-31 11:40:06 +01:00
|
|
|
});
|
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
it("aligns two groups correctly to the bottom", () => {
|
|
|
|
createAndSelectTwoGroups();
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].y).toEqual(100);
|
|
|
|
expect(API.getSelectedElements()[2].y).toEqual(200);
|
|
|
|
expect(API.getSelectedElements()[3].y).toEqual(300);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
h.app.actionManager.executeAction(actionAlignBottom);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].y).toEqual(200);
|
|
|
|
expect(API.getSelectedElements()[1].y).toEqual(300);
|
|
|
|
expect(API.getSelectedElements()[2].y).toEqual(200);
|
|
|
|
expect(API.getSelectedElements()[3].y).toEqual(300);
|
|
|
|
});
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
it("aligns two groups correctly to the left", () => {
|
|
|
|
createAndSelectTwoGroups();
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].x).toEqual(100);
|
|
|
|
expect(API.getSelectedElements()[2].x).toEqual(200);
|
|
|
|
expect(API.getSelectedElements()[3].x).toEqual(300);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
h.app.actionManager.executeAction(actionAlignLeft);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].x).toEqual(100);
|
|
|
|
expect(API.getSelectedElements()[2].x).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[3].x).toEqual(100);
|
|
|
|
});
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
it("aligns two groups correctly to the right", () => {
|
|
|
|
createAndSelectTwoGroups();
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].x).toEqual(100);
|
|
|
|
expect(API.getSelectedElements()[2].x).toEqual(200);
|
|
|
|
expect(API.getSelectedElements()[3].x).toEqual(300);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
h.app.actionManager.executeAction(actionAlignRight);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].x).toEqual(200);
|
|
|
|
expect(API.getSelectedElements()[1].x).toEqual(300);
|
|
|
|
expect(API.getSelectedElements()[2].x).toEqual(200);
|
|
|
|
expect(API.getSelectedElements()[3].x).toEqual(300);
|
|
|
|
});
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
it("centers two groups correctly vertically", () => {
|
|
|
|
createAndSelectTwoGroups();
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].y).toEqual(100);
|
|
|
|
expect(API.getSelectedElements()[2].y).toEqual(200);
|
|
|
|
expect(API.getSelectedElements()[3].y).toEqual(300);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
h.app.actionManager.executeAction(actionAlignVerticallyCentered);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].y).toEqual(100);
|
|
|
|
expect(API.getSelectedElements()[1].y).toEqual(200);
|
|
|
|
expect(API.getSelectedElements()[2].y).toEqual(100);
|
|
|
|
expect(API.getSelectedElements()[3].y).toEqual(200);
|
2020-10-31 11:40:06 +01:00
|
|
|
});
|
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
it("centers two groups correctly horizontally", () => {
|
|
|
|
createAndSelectTwoGroups();
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].x).toEqual(100);
|
|
|
|
expect(API.getSelectedElements()[2].x).toEqual(200);
|
|
|
|
expect(API.getSelectedElements()[3].x).toEqual(300);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
h.app.actionManager.executeAction(actionAlignHorizontallyCentered);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].x).toEqual(100);
|
|
|
|
expect(API.getSelectedElements()[1].x).toEqual(200);
|
|
|
|
expect(API.getSelectedElements()[2].x).toEqual(100);
|
|
|
|
expect(API.getSelectedElements()[3].x).toEqual(200);
|
2020-10-31 11:40:06 +01:00
|
|
|
});
|
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
const createAndSelectNestedGroupAndRectangle = () => {
|
|
|
|
UI.clickTool("rectangle");
|
|
|
|
mouse.down();
|
|
|
|
mouse.up(100, 100);
|
|
|
|
|
|
|
|
UI.clickTool("rectangle");
|
|
|
|
mouse.down(0, 0);
|
|
|
|
mouse.up(100, 100);
|
|
|
|
|
|
|
|
// Select the first element.
|
|
|
|
// The second rectangle is already reselected because it was the last element created
|
|
|
|
mouse.reset();
|
|
|
|
Keyboard.withModifierKeys({ shift: true }, () => {
|
|
|
|
mouse.click();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Create first group of rectangles
|
|
|
|
h.app.actionManager.executeAction(actionGroup);
|
|
|
|
|
|
|
|
mouse.reset();
|
|
|
|
UI.clickTool("rectangle");
|
|
|
|
mouse.down(200, 200);
|
|
|
|
mouse.up(100, 100);
|
|
|
|
|
|
|
|
// Add group to current selection
|
|
|
|
mouse.restorePosition(0, 0);
|
|
|
|
Keyboard.withModifierKeys({ shift: true }, () => {
|
|
|
|
mouse.click();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Create the nested group
|
|
|
|
h.app.actionManager.executeAction(actionGroup);
|
|
|
|
|
|
|
|
mouse.reset();
|
|
|
|
UI.clickTool("rectangle");
|
|
|
|
mouse.down(300, 300);
|
|
|
|
mouse.up(100, 100);
|
|
|
|
|
|
|
|
// Select the nested group, the rectangle is already selected
|
|
|
|
mouse.reset();
|
|
|
|
Keyboard.withModifierKeys({ shift: true }, () => {
|
|
|
|
mouse.click();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
it("aligns nested group and other element correctly to the top", () => {
|
|
|
|
createAndSelectNestedGroupAndRectangle();
|
|
|
|
|
|
|
|
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].y).toEqual(100);
|
|
|
|
expect(API.getSelectedElements()[2].y).toEqual(200);
|
|
|
|
expect(API.getSelectedElements()[3].y).toEqual(300);
|
|
|
|
|
|
|
|
h.app.actionManager.executeAction(actionAlignTop);
|
|
|
|
|
|
|
|
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].y).toEqual(100);
|
|
|
|
expect(API.getSelectedElements()[2].y).toEqual(200);
|
|
|
|
expect(API.getSelectedElements()[3].y).toEqual(0);
|
|
|
|
});
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
it("aligns nested group and other element correctly to the bottom", () => {
|
|
|
|
createAndSelectNestedGroupAndRectangle();
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].y).toEqual(100);
|
|
|
|
expect(API.getSelectedElements()[2].y).toEqual(200);
|
|
|
|
expect(API.getSelectedElements()[3].y).toEqual(300);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
h.app.actionManager.executeAction(actionAlignBottom);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].y).toEqual(100);
|
|
|
|
expect(API.getSelectedElements()[1].y).toEqual(200);
|
|
|
|
expect(API.getSelectedElements()[2].y).toEqual(300);
|
|
|
|
expect(API.getSelectedElements()[3].y).toEqual(300);
|
|
|
|
});
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
it("aligns nested group and other element correctly to the left", () => {
|
|
|
|
createAndSelectNestedGroupAndRectangle();
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].x).toEqual(100);
|
|
|
|
expect(API.getSelectedElements()[2].x).toEqual(200);
|
|
|
|
expect(API.getSelectedElements()[3].x).toEqual(300);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
h.app.actionManager.executeAction(actionAlignLeft);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].x).toEqual(100);
|
|
|
|
expect(API.getSelectedElements()[2].x).toEqual(200);
|
|
|
|
expect(API.getSelectedElements()[3].x).toEqual(0);
|
|
|
|
});
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
it("aligns nested group and other element correctly to the right", () => {
|
|
|
|
createAndSelectNestedGroupAndRectangle();
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].x).toEqual(100);
|
|
|
|
expect(API.getSelectedElements()[2].x).toEqual(200);
|
|
|
|
expect(API.getSelectedElements()[3].x).toEqual(300);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
h.app.actionManager.executeAction(actionAlignRight);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].x).toEqual(100);
|
|
|
|
expect(API.getSelectedElements()[1].x).toEqual(200);
|
|
|
|
expect(API.getSelectedElements()[2].x).toEqual(300);
|
|
|
|
expect(API.getSelectedElements()[3].x).toEqual(300);
|
|
|
|
});
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
it("centers nested group and other element correctly vertically", () => {
|
|
|
|
createAndSelectNestedGroupAndRectangle();
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].y).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].y).toEqual(100);
|
|
|
|
expect(API.getSelectedElements()[2].y).toEqual(200);
|
|
|
|
expect(API.getSelectedElements()[3].y).toEqual(300);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
h.app.actionManager.executeAction(actionAlignVerticallyCentered);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].y).toEqual(50);
|
|
|
|
expect(API.getSelectedElements()[1].y).toEqual(150);
|
|
|
|
expect(API.getSelectedElements()[2].y).toEqual(250);
|
|
|
|
expect(API.getSelectedElements()[3].y).toEqual(150);
|
|
|
|
});
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
it("centers nested group and other element correctly horizontally", () => {
|
|
|
|
createAndSelectNestedGroupAndRectangle();
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].x).toEqual(0);
|
|
|
|
expect(API.getSelectedElements()[1].x).toEqual(100);
|
|
|
|
expect(API.getSelectedElements()[2].x).toEqual(200);
|
|
|
|
expect(API.getSelectedElements()[3].x).toEqual(300);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
h.app.actionManager.executeAction(actionAlignHorizontallyCentered);
|
2020-10-31 11:40:06 +01:00
|
|
|
|
2020-12-05 20:00:53 +05:30
|
|
|
expect(API.getSelectedElements()[0].x).toEqual(50);
|
|
|
|
expect(API.getSelectedElements()[1].x).toEqual(150);
|
|
|
|
expect(API.getSelectedElements()[2].x).toEqual(250);
|
|
|
|
expect(API.getSelectedElements()[3].x).toEqual(150);
|
|
|
|
});
|
2020-10-31 11:40:06 +01:00
|
|
|
});
|