123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615 |
- import React from "react";
- import ReactDOM from "react-dom";
- import { render } from "./test-utils";
- import App from "../components/App";
- import { defaultLang, setLanguage } from "../i18n";
- import { UI, Pointer } from "./helpers/ui";
- import { API } from "./helpers/api";
- import { actionFlipHorizontal, actionFlipVertical } from "../actions";
- const { h } = window;
- const mouse = new Pointer("mouse");
- beforeEach(async () => {
- // Unmount ReactDOM from root
- ReactDOM.unmountComponentAtNode(document.getElementById("root")!);
- mouse.reset();
- await setLanguage(defaultLang);
- await render(<App />);
- });
- const createAndSelectOneRectangle = (angle: number = 0) => {
- UI.createElement("rectangle", {
- x: 0,
- y: 0,
- width: 100,
- height: 50,
- angle,
- });
- };
- const createAndSelectOneDiamond = (angle: number = 0) => {
- UI.createElement("diamond", {
- x: 0,
- y: 0,
- width: 100,
- height: 50,
- angle,
- });
- };
- const createAndSelectOneEllipse = (angle: number = 0) => {
- UI.createElement("ellipse", {
- x: 0,
- y: 0,
- width: 100,
- height: 50,
- angle,
- });
- };
- const createAndSelectOneArrow = (angle: number = 0) => {
- UI.createElement("arrow", {
- x: 0,
- y: 0,
- width: 100,
- height: 50,
- angle,
- });
- };
- const createAndSelectOneLine = (angle: number = 0) => {
- UI.createElement("line", {
- x: 0,
- y: 0,
- width: 100,
- height: 50,
- angle,
- });
- };
- const createAndReturnOneDraw = (angle: number = 0) => {
- return UI.createElement("freedraw", {
- x: 0,
- y: 0,
- width: 50,
- height: 100,
- angle,
- });
- };
- // Rectangle element
- it("flips an unrotated rectangle horizontally correctly", () => {
- createAndSelectOneRectangle();
- expect(API.getSelectedElements()[0].x).toEqual(0);
- expect(API.getSelectedElements()[0].y).toEqual(0);
- const originalWidth = API.getSelectedElements()[0].width;
- const originalHeight = API.getSelectedElements()[0].height;
- h.app.actionManager.executeAction(actionFlipHorizontal);
- // Check if x position did not change
- expect(API.getSelectedElements()[0].x).toEqual(0);
- expect(API.getSelectedElements()[0].y).toEqual(0);
- // Check if width and height did not change
- expect(API.getSelectedElements()[0].width).toEqual(originalWidth);
- expect(API.getSelectedElements()[0].height).toEqual(originalHeight);
- });
- it("flips an unrotated rectangle vertically correctly", () => {
- createAndSelectOneRectangle();
- expect(API.getSelectedElements()[0].x).toEqual(0);
- expect(API.getSelectedElements()[0].y).toEqual(0);
- const originalWidth = API.getSelectedElements()[0].width;
- const originalHeight = API.getSelectedElements()[0].height;
- h.app.actionManager.executeAction(actionFlipVertical);
- // Check if x position did not change
- expect(API.getSelectedElements()[0].x).toEqual(0);
- expect(API.getSelectedElements()[0].y).toEqual(0);
- // Check if width and height did not change
- expect(API.getSelectedElements()[0].width).toEqual(originalWidth);
- expect(API.getSelectedElements()[0].height).toEqual(originalHeight);
- });
- it("flips a rotated rectangle horizontally correctly", () => {
- const originalAngle = (3 * Math.PI) / 4;
- const expectedAngle = (5 * Math.PI) / 4;
- createAndSelectOneRectangle(originalAngle);
- expect(API.getSelectedElements()[0].x).toEqual(0);
- expect(API.getSelectedElements()[0].y).toEqual(0);
- const originalWidth = API.getSelectedElements()[0].width;
- const originalHeight = API.getSelectedElements()[0].height;
- h.app.actionManager.executeAction(actionFlipHorizontal);
- // Check if x position did not change
- expect(API.getSelectedElements()[0].x).toEqual(0);
- expect(API.getSelectedElements()[0].y).toEqual(0);
- // Check if width and height did not change
- expect(API.getSelectedElements()[0].width).toEqual(originalWidth);
- expect(API.getSelectedElements()[0].height).toEqual(originalHeight);
- // Check angle
- expect(API.getSelectedElements()[0].angle).toBeCloseTo(expectedAngle);
- });
- it("flips a rotated rectangle vertically correctly", () => {
- const originalAngle = (3 * Math.PI) / 4;
- const expectedAgnle = Math.PI / 4;
- createAndSelectOneRectangle(originalAngle);
- expect(API.getSelectedElements()[0].x).toEqual(0);
- expect(API.getSelectedElements()[0].y).toEqual(0);
- const originalWidth = API.getSelectedElements()[0].width;
- const originalHeight = API.getSelectedElements()[0].height;
- h.app.actionManager.executeAction(actionFlipVertical);
- // Check if x position did not change
- expect(API.getSelectedElements()[0].x).toEqual(0);
- expect(API.getSelectedElements()[0].y).toEqual(0);
- // Check if width and height did not change
- expect(API.getSelectedElements()[0].width).toEqual(originalWidth);
- expect(API.getSelectedElements()[0].height).toEqual(originalHeight);
- // Check angle
- expect(API.getSelectedElements()[0].angle).toBeCloseTo(expectedAgnle);
- });
- // Diamond element
- it("flips an unrotated diamond horizontally correctly", () => {
- createAndSelectOneDiamond();
- expect(API.getSelectedElements()[0].x).toEqual(0);
- expect(API.getSelectedElements()[0].y).toEqual(0);
- const originalWidth = API.getSelectedElements()[0].width;
- const originalHeight = API.getSelectedElements()[0].height;
- h.app.actionManager.executeAction(actionFlipHorizontal);
- // Check if x position did not change
- expect(API.getSelectedElements()[0].x).toEqual(0);
- expect(API.getSelectedElements()[0].y).toEqual(0);
- // Check if width and height did not change
- expect(API.getSelectedElements()[0].width).toEqual(originalWidth);
- expect(API.getSelectedElements()[0].height).toEqual(originalHeight);
- });
- it("flips an unrotated diamond vertically correctly", () => {
- createAndSelectOneDiamond();
- expect(API.getSelectedElements()[0].x).toEqual(0);
- expect(API.getSelectedElements()[0].y).toEqual(0);
- const originalWidth = API.getSelectedElements()[0].width;
- const originalHeight = API.getSelectedElements()[0].height;
- h.app.actionManager.executeAction(actionFlipVertical);
- // Check if x position did not change
- expect(API.getSelectedElements()[0].x).toEqual(0);
- expect(API.getSelectedElements()[0].y).toEqual(0);
- // Check if width and height did not change
- expect(API.getSelectedElements()[0].width).toEqual(originalWidth);
- expect(API.getSelectedElements()[0].height).toEqual(originalHeight);
- });
- it("flips a rotated diamond horizontally correctly", () => {
- const originalAngle = (5 * Math.PI) / 4;
- const expectedAngle = (3 * Math.PI) / 4;
- createAndSelectOneDiamond(originalAngle);
- expect(API.getSelectedElements()[0].x).toEqual(0);
- expect(API.getSelectedElements()[0].y).toEqual(0);
- const originalWidth = API.getSelectedElements()[0].width;
- const originalHeight = API.getSelectedElements()[0].height;
- h.app.actionManager.executeAction(actionFlipHorizontal);
- // Check if x position did not change
- expect(API.getSelectedElements()[0].x).toEqual(0);
- expect(API.getSelectedElements()[0].y).toEqual(0);
- // Check if width and height did not change
- expect(API.getSelectedElements()[0].width).toEqual(originalWidth);
- expect(API.getSelectedElements()[0].height).toEqual(originalHeight);
- // Check angle
- expect(API.getSelectedElements()[0].angle).toBeCloseTo(expectedAngle);
- });
- it("flips a rotated diamond vertically correctly", () => {
- const originalAngle = (5 * Math.PI) / 4;
- const expectedAngle = (7 * Math.PI) / 4;
- createAndSelectOneDiamond(originalAngle);
- expect(API.getSelectedElements()[0].x).toEqual(0);
- expect(API.getSelectedElements()[0].y).toEqual(0);
- const originalWidth = API.getSelectedElements()[0].width;
- const originalHeight = API.getSelectedElements()[0].height;
- h.app.actionManager.executeAction(actionFlipVertical);
- // Check if x position did not change
- expect(API.getSelectedElements()[0].x).toEqual(0);
- expect(API.getSelectedElements()[0].y).toEqual(0);
- // Check if width and height did not change
- expect(API.getSelectedElements()[0].width).toEqual(originalWidth);
- expect(API.getSelectedElements()[0].height).toEqual(originalHeight);
- // Check angle
- expect(API.getSelectedElements()[0].angle).toBeCloseTo(expectedAngle);
- });
- // Ellipse element
- it("flips an unrotated ellipse horizontally correctly", () => {
- createAndSelectOneEllipse();
- expect(API.getSelectedElements()[0].x).toEqual(0);
- expect(API.getSelectedElements()[0].y).toEqual(0);
- const originalWidth = API.getSelectedElements()[0].width;
- const originalHeight = API.getSelectedElements()[0].height;
- h.app.actionManager.executeAction(actionFlipHorizontal);
- // Check if x position did not change
- expect(API.getSelectedElements()[0].x).toEqual(0);
- expect(API.getSelectedElements()[0].y).toEqual(0);
- // Check if width and height did not change
- expect(API.getSelectedElements()[0].width).toEqual(originalWidth);
- expect(API.getSelectedElements()[0].height).toEqual(originalHeight);
- });
- it("flips an unrotated ellipse vertically correctly", () => {
- createAndSelectOneEllipse();
- expect(API.getSelectedElements()[0].x).toEqual(0);
- expect(API.getSelectedElements()[0].y).toEqual(0);
- const originalWidth = API.getSelectedElements()[0].width;
- const originalHeight = API.getSelectedElements()[0].height;
- h.app.actionManager.executeAction(actionFlipVertical);
- // Check if x position did not change
- expect(API.getSelectedElements()[0].x).toEqual(0);
- expect(API.getSelectedElements()[0].y).toEqual(0);
- // Check if width and height did not change
- expect(API.getSelectedElements()[0].width).toEqual(originalWidth);
- expect(API.getSelectedElements()[0].height).toEqual(originalHeight);
- });
- it("flips a rotated ellipse horizontally correctly", () => {
- const originalAngle = (7 * Math.PI) / 4;
- const expectedAngle = Math.PI / 4;
- createAndSelectOneEllipse(originalAngle);
- expect(API.getSelectedElements()[0].x).toEqual(0);
- expect(API.getSelectedElements()[0].y).toEqual(0);
- const originalWidth = API.getSelectedElements()[0].width;
- const originalHeight = API.getSelectedElements()[0].height;
- h.app.actionManager.executeAction(actionFlipHorizontal);
- // Check if x position did not change
- expect(API.getSelectedElements()[0].x).toEqual(0);
- expect(API.getSelectedElements()[0].y).toEqual(0);
- // Check if width and height did not change
- expect(API.getSelectedElements()[0].width).toEqual(originalWidth);
- expect(API.getSelectedElements()[0].height).toEqual(originalHeight);
- // Check angle
- expect(API.getSelectedElements()[0].angle).toBeCloseTo(expectedAngle);
- });
- it("flips a rotated ellipse vertically correctly", () => {
- const originalAngle = (7 * Math.PI) / 4;
- const expectedAngle = (5 * Math.PI) / 4;
- createAndSelectOneEllipse(originalAngle);
- expect(API.getSelectedElements()[0].x).toEqual(0);
- expect(API.getSelectedElements()[0].y).toEqual(0);
- const originalWidth = API.getSelectedElements()[0].width;
- const originalHeight = API.getSelectedElements()[0].height;
- h.app.actionManager.executeAction(actionFlipVertical);
- // Check if x position did not change
- expect(API.getSelectedElements()[0].x).toEqual(0);
- expect(API.getSelectedElements()[0].y).toEqual(0);
- // Check if width and height did not change
- expect(API.getSelectedElements()[0].width).toEqual(originalWidth);
- expect(API.getSelectedElements()[0].height).toEqual(originalHeight);
- // Check angle
- expect(API.getSelectedElements()[0].angle).toBeCloseTo(expectedAngle);
- });
- // Arrow element
- it("flips an unrotated arrow horizontally correctly", () => {
- createAndSelectOneArrow();
- const originalWidth = API.getSelectedElements()[0].width;
- const originalHeight = API.getSelectedElements()[0].height;
- h.app.actionManager.executeAction(actionFlipHorizontal);
- // Check if width and height did not change
- expect(API.getSelectedElements()[0].width).toEqual(originalWidth);
- expect(API.getSelectedElements()[0].height).toEqual(originalHeight);
- });
- it("flips an unrotated arrow vertically correctly", () => {
- createAndSelectOneArrow();
- const originalWidth = API.getSelectedElements()[0].width;
- const originalHeight = API.getSelectedElements()[0].height;
- h.app.actionManager.executeAction(actionFlipVertical);
- // Check if width and height did not change
- expect(API.getSelectedElements()[0].width).toEqual(originalWidth);
- expect(API.getSelectedElements()[0].height).toEqual(originalHeight);
- });
- it("flips a rotated arrow horizontally correctly", () => {
- const originalAngle = Math.PI / 4;
- const expectedAngle = (7 * Math.PI) / 4;
- createAndSelectOneArrow(originalAngle);
- const originalWidth = API.getSelectedElements()[0].width;
- const originalHeight = API.getSelectedElements()[0].height;
- h.app.actionManager.executeAction(actionFlipHorizontal);
- // Check if width and height did not change
- expect(API.getSelectedElements()[0].width).toEqual(originalWidth);
- expect(API.getSelectedElements()[0].height).toEqual(originalHeight);
- // Check angle
- expect(API.getSelectedElements()[0].angle).toBeCloseTo(expectedAngle);
- });
- it("flips a rotated arrow vertically correctly", () => {
- const originalAngle = Math.PI / 4;
- const expectedAngle = (3 * Math.PI) / 4;
- createAndSelectOneArrow(originalAngle);
- const originalWidth = API.getSelectedElements()[0].width;
- const originalHeight = API.getSelectedElements()[0].height;
- h.app.actionManager.executeAction(actionFlipVertical);
- // Check if width and height did not change
- expect(API.getSelectedElements()[0].width).toEqual(originalWidth);
- expect(API.getSelectedElements()[0].height).toEqual(originalHeight);
- // Check angle
- expect(API.getSelectedElements()[0].angle).toBeCloseTo(expectedAngle);
- });
- // Line element
- it("flips an unrotated line horizontally correctly", () => {
- createAndSelectOneLine();
- const originalWidth = API.getSelectedElements()[0].width;
- const originalHeight = API.getSelectedElements()[0].height;
- h.app.actionManager.executeAction(actionFlipHorizontal);
- // Check if width and height did not change
- expect(API.getSelectedElements()[0].width).toEqual(originalWidth);
- expect(API.getSelectedElements()[0].height).toEqual(originalHeight);
- });
- it("flips an unrotated line vertically correctly", () => {
- createAndSelectOneLine();
- const originalWidth = API.getSelectedElements()[0].width;
- const originalHeight = API.getSelectedElements()[0].height;
- h.app.actionManager.executeAction(actionFlipVertical);
- // Check if width and height did not change
- expect(API.getSelectedElements()[0].width).toEqual(originalWidth);
- expect(API.getSelectedElements()[0].height).toEqual(originalHeight);
- });
- it("flips a rotated line horizontally correctly", () => {
- const originalAngle = Math.PI / 4;
- const expectedAngle = (7 * Math.PI) / 4;
- createAndSelectOneLine(originalAngle);
- const originalWidth = API.getSelectedElements()[0].width;
- const originalHeight = API.getSelectedElements()[0].height;
- h.app.actionManager.executeAction(actionFlipHorizontal);
- // Check if width and height did not change
- expect(API.getSelectedElements()[0].width).toEqual(originalWidth);
- expect(API.getSelectedElements()[0].height).toEqual(originalHeight);
- // Check angle
- expect(API.getSelectedElements()[0].angle).toBeCloseTo(expectedAngle);
- });
- it("flips a rotated line vertically correctly", () => {
- const originalAngle = Math.PI / 4;
- const expectedAngle = (3 * Math.PI) / 4;
- createAndSelectOneLine(originalAngle);
- const originalWidth = API.getSelectedElements()[0].width;
- const originalHeight = API.getSelectedElements()[0].height;
- h.app.actionManager.executeAction(actionFlipVertical);
- // Check if width and height did not change
- expect(API.getSelectedElements()[0].width).toEqual(originalWidth);
- expect(API.getSelectedElements()[0].height).toEqual(originalHeight);
- // Check angle
- expect(API.getSelectedElements()[0].angle).toBeCloseTo(expectedAngle);
- });
- // Draw element
- it("flips an unrotated drawing horizontally correctly", () => {
- const draw = createAndReturnOneDraw();
- // select draw, since not done automatically
- h.state.selectedElementIds[draw.id] = true;
- const originalWidth = draw.width;
- const originalHeight = draw.height;
- h.app.actionManager.executeAction(actionFlipHorizontal);
- // Check if width and height did not change
- expect(draw.width).toEqual(originalWidth);
- expect(draw.height).toEqual(originalHeight);
- });
- it("flips an unrotated drawing vertically correctly", () => {
- const draw = createAndReturnOneDraw();
- // select draw, since not done automatically
- h.state.selectedElementIds[draw.id] = true;
- const originalWidth = draw.width;
- const originalHeight = draw.height;
- h.app.actionManager.executeAction(actionFlipVertical);
- // Check if width and height did not change
- expect(draw.width).toEqual(originalWidth);
- expect(draw.height).toEqual(originalHeight);
- });
- it("flips a rotated drawing horizontally correctly", () => {
- const originalAngle = Math.PI / 4;
- const expectedAngle = (7 * Math.PI) / 4;
- const draw = createAndReturnOneDraw(originalAngle);
- // select draw, since not done automatically
- h.state.selectedElementIds[draw.id] = true;
- const originalWidth = draw.width;
- const originalHeight = draw.height;
- h.app.actionManager.executeAction(actionFlipHorizontal);
- // Check if width and height did not change
- expect(draw.width).toEqual(originalWidth);
- expect(draw.height).toEqual(originalHeight);
- // Check angle
- expect(draw.angle).toBeCloseTo(expectedAngle);
- });
- it("flips a rotated drawing vertically correctly", () => {
- const originalAngle = Math.PI / 4;
- const expectedAngle = (3 * Math.PI) / 4;
- const draw = createAndReturnOneDraw(originalAngle);
- // select draw, since not done automatically
- h.state.selectedElementIds[draw.id] = true;
- const originalWidth = draw.width;
- const originalHeight = draw.height;
- h.app.actionManager.executeAction(actionFlipVertical);
- // Check if width and height did not change
- expect(API.getSelectedElement().width).toEqual(originalWidth);
- expect(API.getSelectedElement().height).toEqual(originalHeight);
- // Check angle
- expect(API.getSelectedElement().angle).toBeCloseTo(expectedAngle);
- });
|