excalidraw/src/tests/regressionTests.test.tsx

1185 lines
33 KiB
TypeScript
Raw Normal View History

2020-03-23 23:38:41 +00:00
import ReactDOM from "react-dom";
import { ExcalidrawElement } from "../element/types";
import { CODES, KEYS } from "../keys";
import ExcalidrawApp from "../excalidraw-app";
import { reseed } from "../random";
2020-03-23 23:38:41 +00:00
import * as Renderer from "../renderer/renderScene";
import { setDateTimeForTests } from "../utils";
import { API } from "./helpers/api";
import { Keyboard, Pointer, UI } from "./helpers/ui";
import {
assertSelectedElements,
fireEvent,
render,
screen,
togglePopover,
waitFor,
} from "./test-utils";
import { defaultLang } from "../i18n";
import { FONT_FAMILY } from "../constants";
2020-03-23 23:38:41 +00:00
const { h } = window;
const renderScene = jest.spyOn(Renderer, "renderScene");
2020-08-27 18:32:10 +00:00
const mouse = new Pointer("mouse");
const finger1 = new Pointer("touch", 1);
const finger2 = new Pointer("touch", 2);
2020-03-23 23:38:41 +00: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.
*/
const checkpoint = (name: string) => {
2020-03-23 23:38:41 +00: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}`),
);
};
beforeEach(async () => {
2020-03-23 23:38:41 +00:00
// Unmount ReactDOM from root
ReactDOM.unmountComponentAtNode(document.getElementById("root")!);
localStorage.clear();
renderScene.mockClear();
reseed(7);
setDateTimeForTests("201933152653");
mouse.reset();
finger1.reset();
finger2.reset();
2020-03-23 23:38:41 +00:00
await render(<ExcalidrawApp />);
h.setState({ height: 768, width: 1024 });
2020-03-23 23:38:41 +00:00
});
afterEach(() => {
checkpoint("end of test");
});
describe("regression tests", () => {
it("draw every type of shape", () => {
2020-08-28 08:15:29 +00:00
UI.clickTool("rectangle");
Allow binding linear elements to other elements (#1899) * Refactor: simplify linear element type * Refactor: dedupe scrollbar handling * First step towards binding - establish relationship and basic test for dragged lines * Refactor: use zoom from appstate * Refactor: generalize getElementAtPosition * Only consider bindable elements in hit test * Refactor: pull out pieces of hit test for reuse later * Refactor: pull out diamond from hit test for reuse later * Refactor: pull out text from hit test for reuse later * Suggest binding when hovering * Give shapes in regression test real size * Give shapes in undo/redo test real size * Keep bound element highlighted * Show binding suggestion for multi-point elements * Move binding to its on module with functions so that I can use it from actions, add support for binding end of multi-point elements * Use Id instead of ID * Improve boundary offset for non-squarish elements * Fix localStorage for binding on linear elements * Simplify dragging code and fix elements bound twice to the same shape * Fix binding for rectangles * Bind both ends at the end of the linear element creation, needed for focus points * wip * Refactor: Renames and reshapes for next commit * Calculate and store focus points and gaps, but dont use them yet * Focus points for rectangles * Dont blow up when canceling linear element * Stop suggesting binding when a non-compatible tool is selected * Clean up collision code * Using Geometric Algebra for hit tests * Correct binding for all shapes * Constant gap around polygon corners * Fix rotation handling * Generalize update and fix hit test for rotated elements * Handle rotation realtime * Handle scaling * Remove vibration when moving bound and binding element together * Handle simultenous scaling * Allow binding and unbinding when editing linear elements * Dont delete binding when the end point wasnt touched * Bind on enter/escape when editing * Support multiple suggested bindable elements in preparation for supporting linear elements dragging * Update binding when moving linear elements * Update binding when resizing linear elements * Dont re-render UI on binding hints * Update both ends when one is moved * Use distance instead of focus point for binding * Complicated approach for posterity, ignore this commit * Revert the complicated approach * Better focus point strategy, working for all shapes * Update snapshots * Dont break binding gap when mirroring shape * Dont break binding gap when grid mode pushes it inside * Dont bind draw elements * Support alt duplication * Fix alt duplication to * Support cmd+D duplication * All copy mechanisms are supported * Allow binding shapes to arrows, having arrows created first * Prevent arrows from disappearing for ellipses * Better binding suggestion highlight for shapes * Dont suggest second binding for simple elements when editing or moving them * Dont steal already bound linear elements when moving shapes * Fix highlighting diamonds and more precisely highlight other shapes * Highlight linear element edges for binding * Highlight text binding too * Handle deletion * Dont suggest second binding for simple linear elements when creating them * Dont highlight bound element during creation * Fix binding for rotated linear elements * Fix collision check for ellipses * Dont show suggested bindings for selected pairs * Bind multi-point linear elements when the tool is switched - important for mobile * Handle unbinding one of two bound edges correctly * Rename boundElement in state to startBoundElement * Dont double account for zoom when rendering binding highlight * Fix rendering of edited linear element point handles * Suggest binding when adding new point to a linear element * Bind when adding a new point to a linear element and dont unbind when moving middle elements * Handle deleting points * Add cmd modifier key to disable binding * Use state for enabling binding, fix not binding for linear elements during creation * Drop support for binding lines, only arrows are bindable * Reset binding mode on blur * Fix not binding lines
2020-08-09 04:04:15 +00:00
mouse.down(10, -10);
mouse.up(20, 10);
2020-03-23 23:38:41 +00:00
2020-08-28 08:15:29 +00:00
UI.clickTool("diamond");
mouse.down(10, -10);
Allow binding linear elements to other elements (#1899) * Refactor: simplify linear element type * Refactor: dedupe scrollbar handling * First step towards binding - establish relationship and basic test for dragged lines * Refactor: use zoom from appstate * Refactor: generalize getElementAtPosition * Only consider bindable elements in hit test * Refactor: pull out pieces of hit test for reuse later * Refactor: pull out diamond from hit test for reuse later * Refactor: pull out text from hit test for reuse later * Suggest binding when hovering * Give shapes in regression test real size * Give shapes in undo/redo test real size * Keep bound element highlighted * Show binding suggestion for multi-point elements * Move binding to its on module with functions so that I can use it from actions, add support for binding end of multi-point elements * Use Id instead of ID * Improve boundary offset for non-squarish elements * Fix localStorage for binding on linear elements * Simplify dragging code and fix elements bound twice to the same shape * Fix binding for rectangles * Bind both ends at the end of the linear element creation, needed for focus points * wip * Refactor: Renames and reshapes for next commit * Calculate and store focus points and gaps, but dont use them yet * Focus points for rectangles * Dont blow up when canceling linear element * Stop suggesting binding when a non-compatible tool is selected * Clean up collision code * Using Geometric Algebra for hit tests * Correct binding for all shapes * Constant gap around polygon corners * Fix rotation handling * Generalize update and fix hit test for rotated elements * Handle rotation realtime * Handle scaling * Remove vibration when moving bound and binding element together * Handle simultenous scaling * Allow binding and unbinding when editing linear elements * Dont delete binding when the end point wasnt touched * Bind on enter/escape when editing * Support multiple suggested bindable elements in preparation for supporting linear elements dragging * Update binding when moving linear elements * Update binding when resizing linear elements * Dont re-render UI on binding hints * Update both ends when one is moved * Use distance instead of focus point for binding * Complicated approach for posterity, ignore this commit * Revert the complicated approach * Better focus point strategy, working for all shapes * Update snapshots * Dont break binding gap when mirroring shape * Dont break binding gap when grid mode pushes it inside * Dont bind draw elements * Support alt duplication * Fix alt duplication to * Support cmd+D duplication * All copy mechanisms are supported * Allow binding shapes to arrows, having arrows created first * Prevent arrows from disappearing for ellipses * Better binding suggestion highlight for shapes * Dont suggest second binding for simple elements when editing or moving them * Dont steal already bound linear elements when moving shapes * Fix highlighting diamonds and more precisely highlight other shapes * Highlight linear element edges for binding * Highlight text binding too * Handle deletion * Dont suggest second binding for simple linear elements when creating them * Dont highlight bound element during creation * Fix binding for rotated linear elements * Fix collision check for ellipses * Dont show suggested bindings for selected pairs * Bind multi-point linear elements when the tool is switched - important for mobile * Handle unbinding one of two bound edges correctly * Rename boundElement in state to startBoundElement * Dont double account for zoom when rendering binding highlight * Fix rendering of edited linear element point handles * Suggest binding when adding new point to a linear element * Bind when adding a new point to a linear element and dont unbind when moving middle elements * Handle deleting points * Add cmd modifier key to disable binding * Use state for enabling binding, fix not binding for linear elements during creation * Drop support for binding lines, only arrows are bindable * Reset binding mode on blur * Fix not binding lines
2020-08-09 04:04:15 +00:00
mouse.up(20, 10);
2020-03-23 23:38:41 +00:00
2020-08-28 08:15:29 +00:00
UI.clickTool("ellipse");
mouse.down(10, -10);
Allow binding linear elements to other elements (#1899) * Refactor: simplify linear element type * Refactor: dedupe scrollbar handling * First step towards binding - establish relationship and basic test for dragged lines * Refactor: use zoom from appstate * Refactor: generalize getElementAtPosition * Only consider bindable elements in hit test * Refactor: pull out pieces of hit test for reuse later * Refactor: pull out diamond from hit test for reuse later * Refactor: pull out text from hit test for reuse later * Suggest binding when hovering * Give shapes in regression test real size * Give shapes in undo/redo test real size * Keep bound element highlighted * Show binding suggestion for multi-point elements * Move binding to its on module with functions so that I can use it from actions, add support for binding end of multi-point elements * Use Id instead of ID * Improve boundary offset for non-squarish elements * Fix localStorage for binding on linear elements * Simplify dragging code and fix elements bound twice to the same shape * Fix binding for rectangles * Bind both ends at the end of the linear element creation, needed for focus points * wip * Refactor: Renames and reshapes for next commit * Calculate and store focus points and gaps, but dont use them yet * Focus points for rectangles * Dont blow up when canceling linear element * Stop suggesting binding when a non-compatible tool is selected * Clean up collision code * Using Geometric Algebra for hit tests * Correct binding for all shapes * Constant gap around polygon corners * Fix rotation handling * Generalize update and fix hit test for rotated elements * Handle rotation realtime * Handle scaling * Remove vibration when moving bound and binding element together * Handle simultenous scaling * Allow binding and unbinding when editing linear elements * Dont delete binding when the end point wasnt touched * Bind on enter/escape when editing * Support multiple suggested bindable elements in preparation for supporting linear elements dragging * Update binding when moving linear elements * Update binding when resizing linear elements * Dont re-render UI on binding hints * Update both ends when one is moved * Use distance instead of focus point for binding * Complicated approach for posterity, ignore this commit * Revert the complicated approach * Better focus point strategy, working for all shapes * Update snapshots * Dont break binding gap when mirroring shape * Dont break binding gap when grid mode pushes it inside * Dont bind draw elements * Support alt duplication * Fix alt duplication to * Support cmd+D duplication * All copy mechanisms are supported * Allow binding shapes to arrows, having arrows created first * Prevent arrows from disappearing for ellipses * Better binding suggestion highlight for shapes * Dont suggest second binding for simple elements when editing or moving them * Dont steal already bound linear elements when moving shapes * Fix highlighting diamonds and more precisely highlight other shapes * Highlight linear element edges for binding * Highlight text binding too * Handle deletion * Dont suggest second binding for simple linear elements when creating them * Dont highlight bound element during creation * Fix binding for rotated linear elements * Fix collision check for ellipses * Dont show suggested bindings for selected pairs * Bind multi-point linear elements when the tool is switched - important for mobile * Handle unbinding one of two bound edges correctly * Rename boundElement in state to startBoundElement * Dont double account for zoom when rendering binding highlight * Fix rendering of edited linear element point handles * Suggest binding when adding new point to a linear element * Bind when adding a new point to a linear element and dont unbind when moving middle elements * Handle deleting points * Add cmd modifier key to disable binding * Use state for enabling binding, fix not binding for linear elements during creation * Drop support for binding lines, only arrows are bindable * Reset binding mode on blur * Fix not binding lines
2020-08-09 04:04:15 +00:00
mouse.up(20, 10);
2020-03-23 23:38:41 +00:00
2020-08-28 08:15:29 +00:00
UI.clickTool("arrow");
Allow binding linear elements to other elements (#1899) * Refactor: simplify linear element type * Refactor: dedupe scrollbar handling * First step towards binding - establish relationship and basic test for dragged lines * Refactor: use zoom from appstate * Refactor: generalize getElementAtPosition * Only consider bindable elements in hit test * Refactor: pull out pieces of hit test for reuse later * Refactor: pull out diamond from hit test for reuse later * Refactor: pull out text from hit test for reuse later * Suggest binding when hovering * Give shapes in regression test real size * Give shapes in undo/redo test real size * Keep bound element highlighted * Show binding suggestion for multi-point elements * Move binding to its on module with functions so that I can use it from actions, add support for binding end of multi-point elements * Use Id instead of ID * Improve boundary offset for non-squarish elements * Fix localStorage for binding on linear elements * Simplify dragging code and fix elements bound twice to the same shape * Fix binding for rectangles * Bind both ends at the end of the linear element creation, needed for focus points * wip * Refactor: Renames and reshapes for next commit * Calculate and store focus points and gaps, but dont use them yet * Focus points for rectangles * Dont blow up when canceling linear element * Stop suggesting binding when a non-compatible tool is selected * Clean up collision code * Using Geometric Algebra for hit tests * Correct binding for all shapes * Constant gap around polygon corners * Fix rotation handling * Generalize update and fix hit test for rotated elements * Handle rotation realtime * Handle scaling * Remove vibration when moving bound and binding element together * Handle simultenous scaling * Allow binding and unbinding when editing linear elements * Dont delete binding when the end point wasnt touched * Bind on enter/escape when editing * Support multiple suggested bindable elements in preparation for supporting linear elements dragging * Update binding when moving linear elements * Update binding when resizing linear elements * Dont re-render UI on binding hints * Update both ends when one is moved * Use distance instead of focus point for binding * Complicated approach for posterity, ignore this commit * Revert the complicated approach * Better focus point strategy, working for all shapes * Update snapshots * Dont break binding gap when mirroring shape * Dont break binding gap when grid mode pushes it inside * Dont bind draw elements * Support alt duplication * Fix alt duplication to * Support cmd+D duplication * All copy mechanisms are supported * Allow binding shapes to arrows, having arrows created first * Prevent arrows from disappearing for ellipses * Better binding suggestion highlight for shapes * Dont suggest second binding for simple elements when editing or moving them * Dont steal already bound linear elements when moving shapes * Fix highlighting diamonds and more precisely highlight other shapes * Highlight linear element edges for binding * Highlight text binding too * Handle deletion * Dont suggest second binding for simple linear elements when creating them * Dont highlight bound element during creation * Fix binding for rotated linear elements * Fix collision check for ellipses * Dont show suggested bindings for selected pairs * Bind multi-point linear elements when the tool is switched - important for mobile * Handle unbinding one of two bound edges correctly * Rename boundElement in state to startBoundElement * Dont double account for zoom when rendering binding highlight * Fix rendering of edited linear element point handles * Suggest binding when adding new point to a linear element * Bind when adding a new point to a linear element and dont unbind when moving middle elements * Handle deleting points * Add cmd modifier key to disable binding * Use state for enabling binding, fix not binding for linear elements during creation * Drop support for binding lines, only arrows are bindable * Reset binding mode on blur * Fix not binding lines
2020-08-09 04:04:15 +00:00
mouse.down(40, -10);
mouse.up(50, 10);
2020-03-23 23:38:41 +00:00
2020-08-28 08:15:29 +00:00
UI.clickTool("line");
Allow binding linear elements to other elements (#1899) * Refactor: simplify linear element type * Refactor: dedupe scrollbar handling * First step towards binding - establish relationship and basic test for dragged lines * Refactor: use zoom from appstate * Refactor: generalize getElementAtPosition * Only consider bindable elements in hit test * Refactor: pull out pieces of hit test for reuse later * Refactor: pull out diamond from hit test for reuse later * Refactor: pull out text from hit test for reuse later * Suggest binding when hovering * Give shapes in regression test real size * Give shapes in undo/redo test real size * Keep bound element highlighted * Show binding suggestion for multi-point elements * Move binding to its on module with functions so that I can use it from actions, add support for binding end of multi-point elements * Use Id instead of ID * Improve boundary offset for non-squarish elements * Fix localStorage for binding on linear elements * Simplify dragging code and fix elements bound twice to the same shape * Fix binding for rectangles * Bind both ends at the end of the linear element creation, needed for focus points * wip * Refactor: Renames and reshapes for next commit * Calculate and store focus points and gaps, but dont use them yet * Focus points for rectangles * Dont blow up when canceling linear element * Stop suggesting binding when a non-compatible tool is selected * Clean up collision code * Using Geometric Algebra for hit tests * Correct binding for all shapes * Constant gap around polygon corners * Fix rotation handling * Generalize update and fix hit test for rotated elements * Handle rotation realtime * Handle scaling * Remove vibration when moving bound and binding element together * Handle simultenous scaling * Allow binding and unbinding when editing linear elements * Dont delete binding when the end point wasnt touched * Bind on enter/escape when editing * Support multiple suggested bindable elements in preparation for supporting linear elements dragging * Update binding when moving linear elements * Update binding when resizing linear elements * Dont re-render UI on binding hints * Update both ends when one is moved * Use distance instead of focus point for binding * Complicated approach for posterity, ignore this commit * Revert the complicated approach * Better focus point strategy, working for all shapes * Update snapshots * Dont break binding gap when mirroring shape * Dont break binding gap when grid mode pushes it inside * Dont bind draw elements * Support alt duplication * Fix alt duplication to * Support cmd+D duplication * All copy mechanisms are supported * Allow binding shapes to arrows, having arrows created first * Prevent arrows from disappearing for ellipses * Better binding suggestion highlight for shapes * Dont suggest second binding for simple elements when editing or moving them * Dont steal already bound linear elements when moving shapes * Fix highlighting diamonds and more precisely highlight other shapes * Highlight linear element edges for binding * Highlight text binding too * Handle deletion * Dont suggest second binding for simple linear elements when creating them * Dont highlight bound element during creation * Fix binding for rotated linear elements * Fix collision check for ellipses * Dont show suggested bindings for selected pairs * Bind multi-point linear elements when the tool is switched - important for mobile * Handle unbinding one of two bound edges correctly * Rename boundElement in state to startBoundElement * Dont double account for zoom when rendering binding highlight * Fix rendering of edited linear element point handles * Suggest binding when adding new point to a linear element * Bind when adding a new point to a linear element and dont unbind when moving middle elements * Handle deleting points * Add cmd modifier key to disable binding * Use state for enabling binding, fix not binding for linear elements during creation * Drop support for binding lines, only arrows are bindable * Reset binding mode on blur * Fix not binding lines
2020-08-09 04:04:15 +00:00
mouse.down(40, -10);
mouse.up(50, 10);
2020-03-23 23:38:41 +00:00
2020-08-28 08:15:29 +00:00
UI.clickTool("arrow");
Allow binding linear elements to other elements (#1899) * Refactor: simplify linear element type * Refactor: dedupe scrollbar handling * First step towards binding - establish relationship and basic test for dragged lines * Refactor: use zoom from appstate * Refactor: generalize getElementAtPosition * Only consider bindable elements in hit test * Refactor: pull out pieces of hit test for reuse later * Refactor: pull out diamond from hit test for reuse later * Refactor: pull out text from hit test for reuse later * Suggest binding when hovering * Give shapes in regression test real size * Give shapes in undo/redo test real size * Keep bound element highlighted * Show binding suggestion for multi-point elements * Move binding to its on module with functions so that I can use it from actions, add support for binding end of multi-point elements * Use Id instead of ID * Improve boundary offset for non-squarish elements * Fix localStorage for binding on linear elements * Simplify dragging code and fix elements bound twice to the same shape * Fix binding for rectangles * Bind both ends at the end of the linear element creation, needed for focus points * wip * Refactor: Renames and reshapes for next commit * Calculate and store focus points and gaps, but dont use them yet * Focus points for rectangles * Dont blow up when canceling linear element * Stop suggesting binding when a non-compatible tool is selected * Clean up collision code * Using Geometric Algebra for hit tests * Correct binding for all shapes * Constant gap around polygon corners * Fix rotation handling * Generalize update and fix hit test for rotated elements * Handle rotation realtime * Handle scaling * Remove vibration when moving bound and binding element together * Handle simultenous scaling * Allow binding and unbinding when editing linear elements * Dont delete binding when the end point wasnt touched * Bind on enter/escape when editing * Support multiple suggested bindable elements in preparation for supporting linear elements dragging * Update binding when moving linear elements * Update binding when resizing linear elements * Dont re-render UI on binding hints * Update both ends when one is moved * Use distance instead of focus point for binding * Complicated approach for posterity, ignore this commit * Revert the complicated approach * Better focus point strategy, working for all shapes * Update snapshots * Dont break binding gap when mirroring shape * Dont break binding gap when grid mode pushes it inside * Dont bind draw elements * Support alt duplication * Fix alt duplication to * Support cmd+D duplication * All copy mechanisms are supported * Allow binding shapes to arrows, having arrows created first * Prevent arrows from disappearing for ellipses * Better binding suggestion highlight for shapes * Dont suggest second binding for simple elements when editing or moving them * Dont steal already bound linear elements when moving shapes * Fix highlighting diamonds and more precisely highlight other shapes * Highlight linear element edges for binding * Highlight text binding too * Handle deletion * Dont suggest second binding for simple linear elements when creating them * Dont highlight bound element during creation * Fix binding for rotated linear elements * Fix collision check for ellipses * Dont show suggested bindings for selected pairs * Bind multi-point linear elements when the tool is switched - important for mobile * Handle unbinding one of two bound edges correctly * Rename boundElement in state to startBoundElement * Dont double account for zoom when rendering binding highlight * Fix rendering of edited linear element point handles * Suggest binding when adding new point to a linear element * Bind when adding a new point to a linear element and dont unbind when moving middle elements * Handle deleting points * Add cmd modifier key to disable binding * Use state for enabling binding, fix not binding for linear elements during creation * Drop support for binding lines, only arrows are bindable * Reset binding mode on blur * Fix not binding lines
2020-08-09 04:04:15 +00:00
mouse.click(40, -10);
mouse.click(50, 10);
mouse.click(30, 10);
Keyboard.keyPress(KEYS.ENTER);
2020-03-23 23:38:41 +00:00
2020-08-28 08:15:29 +00:00
UI.clickTool("line");
Allow binding linear elements to other elements (#1899) * Refactor: simplify linear element type * Refactor: dedupe scrollbar handling * First step towards binding - establish relationship and basic test for dragged lines * Refactor: use zoom from appstate * Refactor: generalize getElementAtPosition * Only consider bindable elements in hit test * Refactor: pull out pieces of hit test for reuse later * Refactor: pull out diamond from hit test for reuse later * Refactor: pull out text from hit test for reuse later * Suggest binding when hovering * Give shapes in regression test real size * Give shapes in undo/redo test real size * Keep bound element highlighted * Show binding suggestion for multi-point elements * Move binding to its on module with functions so that I can use it from actions, add support for binding end of multi-point elements * Use Id instead of ID * Improve boundary offset for non-squarish elements * Fix localStorage for binding on linear elements * Simplify dragging code and fix elements bound twice to the same shape * Fix binding for rectangles * Bind both ends at the end of the linear element creation, needed for focus points * wip * Refactor: Renames and reshapes for next commit * Calculate and store focus points and gaps, but dont use them yet * Focus points for rectangles * Dont blow up when canceling linear element * Stop suggesting binding when a non-compatible tool is selected * Clean up collision code * Using Geometric Algebra for hit tests * Correct binding for all shapes * Constant gap around polygon corners * Fix rotation handling * Generalize update and fix hit test for rotated elements * Handle rotation realtime * Handle scaling * Remove vibration when moving bound and binding element together * Handle simultenous scaling * Allow binding and unbinding when editing linear elements * Dont delete binding when the end point wasnt touched * Bind on enter/escape when editing * Support multiple suggested bindable elements in preparation for supporting linear elements dragging * Update binding when moving linear elements * Update binding when resizing linear elements * Dont re-render UI on binding hints * Update both ends when one is moved * Use distance instead of focus point for binding * Complicated approach for posterity, ignore this commit * Revert the complicated approach * Better focus point strategy, working for all shapes * Update snapshots * Dont break binding gap when mirroring shape * Dont break binding gap when grid mode pushes it inside * Dont bind draw elements * Support alt duplication * Fix alt duplication to * Support cmd+D duplication * All copy mechanisms are supported * Allow binding shapes to arrows, having arrows created first * Prevent arrows from disappearing for ellipses * Better binding suggestion highlight for shapes * Dont suggest second binding for simple elements when editing or moving them * Dont steal already bound linear elements when moving shapes * Fix highlighting diamonds and more precisely highlight other shapes * Highlight linear element edges for binding * Highlight text binding too * Handle deletion * Dont suggest second binding for simple linear elements when creating them * Dont highlight bound element during creation * Fix binding for rotated linear elements * Fix collision check for ellipses * Dont show suggested bindings for selected pairs * Bind multi-point linear elements when the tool is switched - important for mobile * Handle unbinding one of two bound edges correctly * Rename boundElement in state to startBoundElement * Dont double account for zoom when rendering binding highlight * Fix rendering of edited linear element point handles * Suggest binding when adding new point to a linear element * Bind when adding a new point to a linear element and dont unbind when moving middle elements * Handle deleting points * Add cmd modifier key to disable binding * Use state for enabling binding, fix not binding for linear elements during creation * Drop support for binding lines, only arrows are bindable * Reset binding mode on blur * Fix not binding lines
2020-08-09 04:04:15 +00:00
mouse.click(40, -20);
mouse.click(50, 10);
mouse.click(30, 10);
Keyboard.keyPress(KEYS.ENTER);
2020-05-12 19:10:11 +00:00
UI.clickTool("freedraw");
Allow binding linear elements to other elements (#1899) * Refactor: simplify linear element type * Refactor: dedupe scrollbar handling * First step towards binding - establish relationship and basic test for dragged lines * Refactor: use zoom from appstate * Refactor: generalize getElementAtPosition * Only consider bindable elements in hit test * Refactor: pull out pieces of hit test for reuse later * Refactor: pull out diamond from hit test for reuse later * Refactor: pull out text from hit test for reuse later * Suggest binding when hovering * Give shapes in regression test real size * Give shapes in undo/redo test real size * Keep bound element highlighted * Show binding suggestion for multi-point elements * Move binding to its on module with functions so that I can use it from actions, add support for binding end of multi-point elements * Use Id instead of ID * Improve boundary offset for non-squarish elements * Fix localStorage for binding on linear elements * Simplify dragging code and fix elements bound twice to the same shape * Fix binding for rectangles * Bind both ends at the end of the linear element creation, needed for focus points * wip * Refactor: Renames and reshapes for next commit * Calculate and store focus points and gaps, but dont use them yet * Focus points for rectangles * Dont blow up when canceling linear element * Stop suggesting binding when a non-compatible tool is selected * Clean up collision code * Using Geometric Algebra for hit tests * Correct binding for all shapes * Constant gap around polygon corners * Fix rotation handling * Generalize update and fix hit test for rotated elements * Handle rotation realtime * Handle scaling * Remove vibration when moving bound and binding element together * Handle simultenous scaling * Allow binding and unbinding when editing linear elements * Dont delete binding when the end point wasnt touched * Bind on enter/escape when editing * Support multiple suggested bindable elements in preparation for supporting linear elements dragging * Update binding when moving linear elements * Update binding when resizing linear elements * Dont re-render UI on binding hints * Update both ends when one is moved * Use distance instead of focus point for binding * Complicated approach for posterity, ignore this commit * Revert the complicated approach * Better focus point strategy, working for all shapes * Update snapshots * Dont break binding gap when mirroring shape * Dont break binding gap when grid mode pushes it inside * Dont bind draw elements * Support alt duplication * Fix alt duplication to * Support cmd+D duplication * All copy mechanisms are supported * Allow binding shapes to arrows, having arrows created first * Prevent arrows from disappearing for ellipses * Better binding suggestion highlight for shapes * Dont suggest second binding for simple elements when editing or moving them * Dont steal already bound linear elements when moving shapes * Fix highlighting diamonds and more precisely highlight other shapes * Highlight linear element edges for binding * Highlight text binding too * Handle deletion * Dont suggest second binding for simple linear elements when creating them * Dont highlight bound element during creation * Fix binding for rotated linear elements * Fix collision check for ellipses * Dont show suggested bindings for selected pairs * Bind multi-point linear elements when the tool is switched - important for mobile * Handle unbinding one of two bound edges correctly * Rename boundElement in state to startBoundElement * Dont double account for zoom when rendering binding highlight * Fix rendering of edited linear element point handles * Suggest binding when adding new point to a linear element * Bind when adding a new point to a linear element and dont unbind when moving middle elements * Handle deleting points * Add cmd modifier key to disable binding * Use state for enabling binding, fix not binding for linear elements during creation * Drop support for binding lines, only arrows are bindable * Reset binding mode on blur * Fix not binding lines
2020-08-09 04:04:15 +00:00
mouse.down(40, -20);
mouse.up(50, 10);
expect(h.elements.map((element) => element.type)).toEqual([
"rectangle",
"diamond",
"ellipse",
"arrow",
"line",
"arrow",
"line",
"freedraw",
]);
2020-03-23 23:38:41 +00:00
});
it("click to select a shape", () => {
2020-08-28 08:15:29 +00:00
UI.clickTool("rectangle");
mouse.down(10, 10);
mouse.up(10, 10);
const firstRectPos = mouse.getPosition();
2020-03-23 23:38:41 +00:00
2020-08-28 08:15:29 +00:00
UI.clickTool("rectangle");
mouse.down(10, -10);
mouse.up(10, 10);
2020-03-23 23:38:41 +00:00
2020-08-28 08:15:29 +00:00
const prevSelectedId = API.getSelectedElement().id;
mouse.restorePosition(...firstRectPos);
mouse.click();
2020-08-28 08:15:29 +00:00
expect(API.getSelectedElement().id).not.toEqual(prevSelectedId);
2020-03-23 23:38:41 +00:00
});
for (const [keys, shape, shouldSelect] of [
[`2${KEYS.R}`, "rectangle", true],
[`3${KEYS.D}`, "diamond", true],
[`4${KEYS.O}`, "ellipse", true],
[`5${KEYS.A}`, "arrow", true],
[`6${KEYS.L}`, "line", true],
[`7${KEYS.P}`, "freedraw", false],
] as [string, ExcalidrawElement["type"], boolean][]) {
2020-03-23 23:38:41 +00:00
for (const key of keys) {
it(`key ${key} selects ${shape} tool`, () => {
2020-08-28 08:15:29 +00:00
Keyboard.keyPress(key);
2020-03-23 23:38:41 +00:00
expect(h.state.activeTool.type).toBe(shape);
mouse.down(10, 10);
mouse.up(10, 10);
2020-03-23 23:38:41 +00:00
if (shouldSelect) {
expect(API.getSelectedElement().type).toBe(shape);
}
2020-03-23 23:38:41 +00:00
});
}
}
it("change the properties of a shape", () => {
2020-08-28 08:15:29 +00:00
UI.clickTool("rectangle");
mouse.down(10, 10);
mouse.up(10, 10);
togglePopover("Background");
UI.clickOnTestId("color-yellow");
UI.clickOnTestId("color-red");
togglePopover("Stroke");
UI.clickOnTestId("color-blue");
expect(API.getSelectedElement().backgroundColor).toBe("#ffc9c9");
expect(API.getSelectedElement().strokeColor).toBe("#1971c2");
2020-03-23 23:38:41 +00:00
});
it("click on an element and drag it", () => {
2020-08-28 08:15:29 +00:00
UI.clickTool("rectangle");
mouse.down(10, 10);
mouse.up(10, 10);
2020-03-23 23:38:41 +00:00
2020-08-28 08:15:29 +00:00
const { x: prevX, y: prevY } = API.getSelectedElement();
mouse.down(-8, -8);
mouse.up(10, 10);
2020-03-23 23:38:41 +00:00
2020-08-28 08:15:29 +00:00
const { x: nextX, y: nextY } = API.getSelectedElement();
2020-03-23 23:38:41 +00:00
expect(nextX).toBeGreaterThan(prevX);
expect(nextY).toBeGreaterThan(prevY);
checkpoint("dragged");
mouse.down();
mouse.up(-10, -10);
2020-03-23 23:38:41 +00:00
2020-08-28 08:15:29 +00:00
const { x, y } = API.getSelectedElement();
2020-03-23 23:38:41 +00:00
expect(x).toBe(prevX);
expect(y).toBe(prevY);
});
it("alt-drag duplicates an element", () => {
2020-08-28 08:15:29 +00:00
UI.clickTool("rectangle");
mouse.down(10, 10);
mouse.up(10, 10);
2020-03-23 23:38:41 +00:00
expect(
h.elements.filter((element) => element.type === "rectangle").length,
).toBe(1);
2020-08-28 08:15:29 +00:00
Keyboard.withModifierKeys({ alt: true }, () => {
mouse.down(-8, -8);
mouse.up(10, 10);
});
2020-03-23 23:38:41 +00:00
expect(
h.elements.filter((element) => element.type === "rectangle").length,
).toBe(2);
});
it("click-drag to select a group", () => {
2020-08-28 08:15:29 +00:00
UI.clickTool("rectangle");
mouse.down(10, 10);
mouse.up(10, 10);
2020-03-23 23:38:41 +00:00
2020-08-28 08:15:29 +00:00
UI.clickTool("rectangle");
mouse.down(10, -10);
mouse.up(10, 10);
const finalPosition = mouse.getPosition();
2020-03-23 23:38:41 +00:00
2020-08-28 08:15:29 +00:00
UI.clickTool("rectangle");
mouse.down(10, -10);
mouse.up(10, 10);
2020-03-23 23:38:41 +00:00
mouse.restorePosition(0, 0);
mouse.down();
mouse.restorePosition(...finalPosition);
mouse.up(5, 5);
2020-03-23 23:38:41 +00:00
expect(
h.elements.filter((element) => h.state.selectedElementIds[element.id])
.length,
).toBe(2);
});
it("shift-click to multiselect, then drag", () => {
2020-08-28 08:15:29 +00:00
UI.clickTool("rectangle");
mouse.down(10, 10);
mouse.up(10, 10);
2020-03-23 23:38:41 +00:00
2020-08-28 08:15:29 +00:00
UI.clickTool("rectangle");
mouse.down(10, -10);
mouse.up(10, 10);
2020-03-23 23:38:41 +00:00
const prevRectsXY = h.elements
.filter((element) => element.type === "rectangle")
.map((element) => ({ x: element.x, y: element.y }));
mouse.reset();
mouse.click(10, 10);
2020-08-28 08:15:29 +00:00
Keyboard.withModifierKeys({ shift: true }, () => {
mouse.click(20, 0);
});
mouse.down();
mouse.up(10, 10);
2020-03-23 23:38:41 +00: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);
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;
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 23:38:41 +00:00
});
it("two-finger scroll works", () => {
// scroll horizontally vertically
2020-03-23 23:38:41 +00:00
const startScrollY = h.state.scrollY;
finger1.downAt(0, 0);
finger2.downAt(10, 0);
finger1.clientY -= 10;
finger2.clientY -= 10;
finger1.moveTo();
finger2.moveTo();
finger1.upAt();
finger2.upAt();
2020-03-23 23:38:41 +00:00
expect(h.state.scrollY).toBeLessThan(startScrollY);
// scroll horizontally
2020-03-23 23:38:41 +00:00
const startScrollX = h.state.scrollX;
finger1.downAt();
finger2.downAt();
finger1.clientX += 10;
finger2.clientX += 10;
finger1.moveTo();
finger2.moveTo();
finger1.upAt();
finger2.upAt();
2020-03-23 23:38:41 +00:00
expect(h.state.scrollX).toBeGreaterThan(startScrollX);
});
it("spacebar + drag scrolls the canvas", () => {
const { scrollX: startScrollX, scrollY: startScrollY } = h.state;
Keyboard.keyDown(KEYS.SPACE);
mouse.down(50, 50);
mouse.up(60, 60);
Keyboard.keyUp(KEYS.SPACE);
2020-03-23 23:38:41 +00:00
const { scrollX, scrollY } = h.state;
expect(scrollX).not.toEqual(startScrollX);
expect(scrollY).not.toEqual(startScrollY);
});
it("arrow keys", () => {
2020-08-28 08:15:29 +00:00
UI.clickTool("rectangle");
mouse.down(10, 10);
mouse.up(10, 10);
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);
expect(h.elements[0].x).toBe(9);
expect(h.elements[0].y).toBe(9);
2020-03-23 23:38:41 +00:00
});
it("undo/redo drawing an element", () => {
2020-08-28 08:15:29 +00:00
UI.clickTool("rectangle");
Allow binding linear elements to other elements (#1899) * Refactor: simplify linear element type * Refactor: dedupe scrollbar handling * First step towards binding - establish relationship and basic test for dragged lines * Refactor: use zoom from appstate * Refactor: generalize getElementAtPosition * Only consider bindable elements in hit test * Refactor: pull out pieces of hit test for reuse later * Refactor: pull out diamond from hit test for reuse later * Refactor: pull out text from hit test for reuse later * Suggest binding when hovering * Give shapes in regression test real size * Give shapes in undo/redo test real size * Keep bound element highlighted * Show binding suggestion for multi-point elements * Move binding to its on module with functions so that I can use it from actions, add support for binding end of multi-point elements * Use Id instead of ID * Improve boundary offset for non-squarish elements * Fix localStorage for binding on linear elements * Simplify dragging code and fix elements bound twice to the same shape * Fix binding for rectangles * Bind both ends at the end of the linear element creation, needed for focus points * wip * Refactor: Renames and reshapes for next commit * Calculate and store focus points and gaps, but dont use them yet * Focus points for rectangles * Dont blow up when canceling linear element * Stop suggesting binding when a non-compatible tool is selected * Clean up collision code * Using Geometric Algebra for hit tests * Correct binding for all shapes * Constant gap around polygon corners * Fix rotation handling * Generalize update and fix hit test for rotated elements * Handle rotation realtime * Handle scaling * Remove vibration when moving bound and binding element together * Handle simultenous scaling * Allow binding and unbinding when editing linear elements * Dont delete binding when the end point wasnt touched * Bind on enter/escape when editing * Support multiple suggested bindable elements in preparation for supporting linear elements dragging * Update binding when moving linear elements * Update binding when resizing linear elements * Dont re-render UI on binding hints * Update both ends when one is moved * Use distance instead of focus point for binding * Complicated approach for posterity, ignore this commit * Revert the complicated approach * Better focus point strategy, working for all shapes * Update snapshots * Dont break binding gap when mirroring shape * Dont break binding gap when grid mode pushes it inside * Dont bind draw elements * Support alt duplication * Fix alt duplication to * Support cmd+D duplication * All copy mechanisms are supported * Allow binding shapes to arrows, having arrows created first * Prevent arrows from disappearing for ellipses * Better binding suggestion highlight for shapes * Dont suggest second binding for simple elements when editing or moving them * Dont steal already bound linear elements when moving shapes * Fix highlighting diamonds and more precisely highlight other shapes * Highlight linear element edges for binding * Highlight text binding too * Handle deletion * Dont suggest second binding for simple linear elements when creating them * Dont highlight bound element during creation * Fix binding for rotated linear elements * Fix collision check for ellipses * Dont show suggested bindings for selected pairs * Bind multi-point linear elements when the tool is switched - important for mobile * Handle unbinding one of two bound edges correctly * Rename boundElement in state to startBoundElement * Dont double account for zoom when rendering binding highlight * Fix rendering of edited linear element point handles * Suggest binding when adding new point to a linear element * Bind when adding a new point to a linear element and dont unbind when moving middle elements * Handle deleting points * Add cmd modifier key to disable binding * Use state for enabling binding, fix not binding for linear elements during creation * Drop support for binding lines, only arrows are bindable * Reset binding mode on blur * Fix not binding lines
2020-08-09 04:04:15 +00:00
mouse.down(10, -10);
mouse.up(20, 10);
2020-03-23 23:38:41 +00:00
2020-08-28 08:15:29 +00:00
UI.clickTool("rectangle");
Allow binding linear elements to other elements (#1899) * Refactor: simplify linear element type * Refactor: dedupe scrollbar handling * First step towards binding - establish relationship and basic test for dragged lines * Refactor: use zoom from appstate * Refactor: generalize getElementAtPosition * Only consider bindable elements in hit test * Refactor: pull out pieces of hit test for reuse later * Refactor: pull out diamond from hit test for reuse later * Refactor: pull out text from hit test for reuse later * Suggest binding when hovering * Give shapes in regression test real size * Give shapes in undo/redo test real size * Keep bound element highlighted * Show binding suggestion for multi-point elements * Move binding to its on module with functions so that I can use it from actions, add support for binding end of multi-point elements * Use Id instead of ID * Improve boundary offset for non-squarish elements * Fix localStorage for binding on linear elements * Simplify dragging code and fix elements bound twice to the same shape * Fix binding for rectangles * Bind both ends at the end of the linear element creation, needed for focus points * wip * Refactor: Renames and reshapes for next commit * Calculate and store focus points and gaps, but dont use them yet * Focus points for rectangles * Dont blow up when canceling linear element * Stop suggesting binding when a non-compatible tool is selected * Clean up collision code * Using Geometric Algebra for hit tests * Correct binding for all shapes * Constant gap around polygon corners * Fix rotation handling * Generalize update and fix hit test for rotated elements * Handle rotation realtime * Handle scaling * Remove vibration when moving bound and binding element together * Handle simultenous scaling * Allow binding and unbinding when editing linear elements * Dont delete binding when the end point wasnt touched * Bind on enter/escape when editing * Support multiple suggested bindable elements in preparation for supporting linear elements dragging * Update binding when moving linear elements * Update binding when resizing linear elements * Dont re-render UI on binding hints * Update both ends when one is moved * Use distance instead of focus point for binding * Complicated approach for posterity, ignore this commit * Revert the complicated approach * Better focus point strategy, working for all shapes * Update snapshots * Dont break binding gap when mirroring shape * Dont break binding gap when grid mode pushes it inside * Dont bind draw elements * Support alt duplication * Fix alt duplication to * Support cmd+D duplication * All copy mechanisms are supported * Allow binding shapes to arrows, having arrows created first * Prevent arrows from disappearing for ellipses * Better binding suggestion highlight for shapes * Dont suggest second binding for simple elements when editing or moving them * Dont steal already bound linear elements when moving shapes * Fix highlighting diamonds and more precisely highlight other shapes * Highlight linear element edges for binding * Highlight text binding too * Handle deletion * Dont suggest second binding for simple linear elements when creating them * Dont highlight bound element during creation * Fix binding for rotated linear elements * Fix collision check for ellipses * Dont show suggested bindings for selected pairs * Bind multi-point linear elements when the tool is switched - important for mobile * Handle unbinding one of two bound edges correctly * Rename boundElement in state to startBoundElement * Dont double account for zoom when rendering binding highlight * Fix rendering of edited linear element point handles * Suggest binding when adding new point to a linear element * Bind when adding a new point to a linear element and dont unbind when moving middle elements * Handle deleting points * Add cmd modifier key to disable binding * Use state for enabling binding, fix not binding for linear elements during creation * Drop support for binding lines, only arrows are bindable * Reset binding mode on blur * Fix not binding lines
2020-08-09 04:04:15 +00:00
mouse.down(10, 0);
mouse.up(30, 20);
2020-03-23 23:38:41 +00:00
2020-08-28 08:15:29 +00:00
UI.clickTool("arrow");
Allow binding linear elements to other elements (#1899) * Refactor: simplify linear element type * Refactor: dedupe scrollbar handling * First step towards binding - establish relationship and basic test for dragged lines * Refactor: use zoom from appstate * Refactor: generalize getElementAtPosition * Only consider bindable elements in hit test * Refactor: pull out pieces of hit test for reuse later * Refactor: pull out diamond from hit test for reuse later * Refactor: pull out text from hit test for reuse later * Suggest binding when hovering * Give shapes in regression test real size * Give shapes in undo/redo test real size * Keep bound element highlighted * Show binding suggestion for multi-point elements * Move binding to its on module with functions so that I can use it from actions, add support for binding end of multi-point elements * Use Id instead of ID * Improve boundary offset for non-squarish elements * Fix localStorage for binding on linear elements * Simplify dragging code and fix elements bound twice to the same shape * Fix binding for rectangles * Bind both ends at the end of the linear element creation, needed for focus points * wip * Refactor: Renames and reshapes for next commit * Calculate and store focus points and gaps, but dont use them yet * Focus points for rectangles * Dont blow up when canceling linear element * Stop suggesting binding when a non-compatible tool is selected * Clean up collision code * Using Geometric Algebra for hit tests * Correct binding for all shapes * Constant gap around polygon corners * Fix rotation handling * Generalize update and fix hit test for rotated elements * Handle rotation realtime * Handle scaling * Remove vibration when moving bound and binding element together * Handle simultenous scaling * Allow binding and unbinding when editing linear elements * Dont delete binding when the end point wasnt touched * Bind on enter/escape when editing * Support multiple suggested bindable elements in preparation for supporting linear elements dragging * Update binding when moving linear elements * Update binding when resizing linear elements * Dont re-render UI on binding hints * Update both ends when one is moved * Use distance instead of focus point for binding * Complicated approach for posterity, ignore this commit * Revert the complicated approach * Better focus point strategy, working for all shapes * Update snapshots * Dont break binding gap when mirroring shape * Dont break binding gap when grid mode pushes it inside * Dont bind draw elements * Support alt duplication * Fix alt duplication to * Support cmd+D duplication * All copy mechanisms are supported * Allow binding shapes to arrows, having arrows created first * Prevent arrows from disappearing for ellipses * Better binding suggestion highlight for shapes * Dont suggest second binding for simple elements when editing or moving them * Dont steal already bound linear elements when moving shapes * Fix highlighting diamonds and more precisely highlight other shapes * Highlight linear element edges for binding * Highlight text binding too * Handle deletion * Dont suggest second binding for simple linear elements when creating them * Dont highlight bound element during creation * Fix binding for rotated linear elements * Fix collision check for ellipses * Dont show suggested bindings for selected pairs * Bind multi-point linear elements when the tool is switched - important for mobile * Handle unbinding one of two bound edges correctly * Rename boundElement in state to startBoundElement * Dont double account for zoom when rendering binding highlight * Fix rendering of edited linear element point handles * Suggest binding when adding new point to a linear element * Bind when adding a new point to a linear element and dont unbind when moving middle elements * Handle deleting points * Add cmd modifier key to disable binding * Use state for enabling binding, fix not binding for linear elements during creation * Drop support for binding lines, only arrows are bindable * Reset binding mode on blur * Fix not binding lines
2020-08-09 04:04:15 +00:00
mouse.click(60, -10);
mouse.click(60, 10);
mouse.click(40, 10);
Keyboard.keyPress(KEYS.ENTER);
2020-03-23 23:38:41 +00:00
expect(h.elements.filter((element) => !element.isDeleted).length).toBe(3);
2020-08-28 08:15:29 +00:00
Keyboard.withModifierKeys({ ctrl: true }, () => {
Keyboard.keyPress(KEYS.Z);
Keyboard.keyPress(KEYS.Z);
});
2020-03-23 23:38:41 +00:00
expect(h.elements.filter((element) => !element.isDeleted).length).toBe(2);
2020-08-28 08:15:29 +00:00
Keyboard.withModifierKeys({ ctrl: true }, () => {
Keyboard.keyPress(KEYS.Z);
});
2020-03-23 23:38:41 +00:00
expect(h.elements.filter((element) => !element.isDeleted).length).toBe(1);
2020-08-28 08:15:29 +00:00
Keyboard.withModifierKeys({ ctrl: true, shift: true }, () => {
Keyboard.keyPress(KEYS.Z);
});
2020-03-23 23:38:41 +00:00
expect(h.elements.filter((element) => !element.isDeleted).length).toBe(2);
});
it("noop interaction after undo shouldn't create history entry", () => {
2020-09-09 19:08:06 +00:00
expect(API.getStateHistory().length).toBe(1);
2020-08-28 08:15:29 +00:00
UI.clickTool("rectangle");
mouse.down(10, 10);
mouse.up(10, 10);
const firstElementEndPoint = mouse.getPosition();
2020-08-28 08:15:29 +00:00
UI.clickTool("rectangle");
mouse.down(10, -10);
mouse.up(10, 10);
const secondElementEndPoint = mouse.getPosition();
2020-09-09 19:08:06 +00:00
expect(API.getStateHistory().length).toBe(3);
2020-08-28 08:15:29 +00:00
Keyboard.withModifierKeys({ ctrl: true }, () => {
Keyboard.keyPress(KEYS.Z);
});
2020-09-09 19:08:06 +00:00
expect(API.getStateHistory().length).toBe(2);
// clicking an element shouldn't add to history
mouse.restorePosition(...firstElementEndPoint);
mouse.click();
2020-09-09 19:08:06 +00:00
expect(API.getStateHistory().length).toBe(2);
2020-08-28 08:15:29 +00:00
Keyboard.withModifierKeys({ shift: true, ctrl: true }, () => {
Keyboard.keyPress(KEYS.Z);
});
2020-09-09 19:08:06 +00:00
expect(API.getStateHistory().length).toBe(3);
// clicking an element shouldn't add to history
mouse.click();
2020-09-09 19:08:06 +00:00
expect(API.getStateHistory().length).toBe(3);
2020-08-28 08:15:29 +00:00
const firstSelectedElementId = API.getSelectedElement().id;
// same for clicking the element just redo-ed
mouse.restorePosition(...secondElementEndPoint);
mouse.click();
2020-09-09 19:08:06 +00:00
expect(API.getStateHistory().length).toBe(3);
2020-08-28 08:15:29 +00:00
expect(API.getSelectedElement().id).not.toEqual(firstSelectedElementId);
});
2020-03-23 23:38:41 +00:00
it("zoom hotkeys", () => {
2020-11-04 17:49:15 +00:00
expect(h.state.zoom.value).toBe(1);
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);
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 23:38:41 +00:00
});
it("rerenders UI on language change", async () => {
// select rectangle tool to show properties menu
2020-08-28 08:15:29 +00:00
UI.clickTool("rectangle");
// english lang should display `thin` label
expect(screen.queryByTitle(/thin/i)).not.toBeNull();
feat: new Menu Component API (#6034) * feat: new Menu Component API * allow valid children types * introduce menu group to group items * Add lang footer * use display name * displayName * define types inside * fix default menu * add json export to menu * fix * simplify expression * put open menu into own compo to optimize perf So that we don't rerun `useOutsideClickHook` (and rebind event listeners all the time) * naming tweaks * rename MenuComponents->MenuDefaultItems and export default items from Menu.Items * import Menu.scss in Menu.tsx * move menu scss to excal app * Don't filter children inside menu group * move E+ out of socials * support style prop for MenuItem and MenuGroup * Support header in menu group and add Excalidraw links header for default items in social section * rename header to title * fix padding for lang * render menu in mobile * review fixes * tweaks * Export collaborators and show in mobile menu * revert .env * lint :p * again lint * show correct actions in view mode for mobile * Whitelist Collaborators Comp * mobile styling * padding * don't show nerds when menu open in mobile * lint :( * hide shortcuts * refactor userlist to support mobile and keep a wrapper comp for excal app * use only UserList * render only on mobile for default items * remove unused hooks * Show collab button in menu when onCollabButtonClick present and hide export when UIOptions.canvasActions.export is false * fix tests * lint * inject userlist inside menu on mobile * revert userlist * move menu socials to default menu * fix collab * use meny in library * Make Menu generic and create hamburgemenu for public excal menu and use menu in library as well * use appState.openMenu for mobile * fix tests * styling fixes and support style and class name in menu content * fix test * rename MenuDefaultItems->DefaultItems * move footer css to its own comp * rename HamburgerMenu -> MainMenu * rename menu -> dropdownMenu and update classes, onClick->onToggle * close main menu when dialog closes * by bye filtering * update docs * fix lint * update example, docs for useDevice and footer in mobile, rename menu ->DropDownMenu everywhere * spec * remove isMenuOpenAtom and set openMenu as canvas for main menu, render decreases in specs :) * [temp] remove cyclic depenedency to fix build * hack- update appstate to sync lang change * Add more specs * wip: rewrite MainMenu footer * fix margin * fix snaps * not needed as lang list no more imported * simplify custom footer rendering * Add DropdownMenuItemLink and DropdownMenuItemCustom and update API, docs * fix `MainMenu.ItemCustom` * naming * use onSelect and base class for custom items * fix lint * fix snap * use custom item for lang * update docs * fix * properly use `MainMenu.ItemCustom` for `LanguageList` * add margin top to custom items * flex Co-authored-by: dwelle <luzar.david@gmail.com>
2023-01-05 16:34:23 +00:00
fireEvent.click(document.querySelector(".dropdown-menu-button")!);
fireEvent.change(document.querySelector(".dropdown-select__language")!, {
target: { value: "de-DE" },
});
// switching to german, `thin` label should no longer exist
await waitFor(() => expect(screen.queryByTitle(/thin/i)).toBeNull());
// reset language
fireEvent.change(document.querySelector(".dropdown-select__language")!, {
target: { value: defaultLang.code },
});
// switching back to English
await waitFor(() => expect(screen.queryByTitle(/thin/i)).not.toBeNull());
});
it("make a group and duplicate it", () => {
2020-08-28 08:15:29 +00:00
UI.clickTool("rectangle");
mouse.down(10, 10);
mouse.up(10, 10);
2020-08-28 08:15:29 +00:00
UI.clickTool("rectangle");
mouse.down(10, -10);
mouse.up(10, 10);
2020-08-28 08:15:29 +00:00
UI.clickTool("rectangle");
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 08:15:29 +00:00
Keyboard.withModifierKeys({ ctrl: true }, () => {
Keyboard.keyPress(KEYS.G);
});
for (const element of h.elements) {
expect(element.groupIds.length).toBe(1);
}
2020-08-28 08:15:29 +00:00
Keyboard.withModifierKeys({ alt: true }, () => {
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("should group elements and ungroup them", () => {
UI.clickTool("rectangle");
mouse.down(10, 10);
mouse.up(10, 10);
UI.clickTool("rectangle");
mouse.down(10, -10);
mouse.up(10, 10);
UI.clickTool("rectangle");
mouse.down(10, -10);
mouse.up(10, 10);
const end = mouse.getPosition();
mouse.reset();
mouse.down();
mouse.restorePosition(...end);
mouse.up();
for (const element of h.elements) {
expect(element.groupIds.length).toBe(0);
}
Keyboard.withModifierKeys({ ctrl: true }, () => {
Keyboard.keyPress(KEYS.G);
});
for (const element of h.elements) {
expect(element.groupIds.length).toBe(1);
}
mouse.reset();
mouse.down();
mouse.restorePosition(...end);
mouse.up();
Keyboard.withModifierKeys({ ctrl: true, shift: true }, () => {
Keyboard.keyPress(KEYS.G);
});
for (const element of h.elements) {
expect(element.groupIds.length).toBe(0);
}
});
it("double click to edit a group", () => {
2020-08-28 08:15:29 +00:00
UI.clickTool("rectangle");
mouse.down(10, 10);
mouse.up(10, 10);
2020-08-28 08:15:29 +00:00
UI.clickTool("rectangle");
mouse.down(10, -10);
mouse.up(10, 10);
2020-08-28 08:15:29 +00:00
UI.clickTool("rectangle");
mouse.down(10, -10);
mouse.up(10, 10);
2020-08-28 08:15:29 +00:00
Keyboard.withModifierKeys({ ctrl: true }, () => {
Keyboard.keyPress(KEYS.A);
Keyboard.keyPress(KEYS.G);
});
2020-08-28 08:15:29 +00:00
expect(API.getSelectedElements().length).toBe(3);
expect(h.state.editingGroupId).toBe(null);
mouse.doubleClick();
2020-08-28 08:15:29 +00:00
expect(API.getSelectedElements().length).toBe(1);
expect(h.state.editingGroupId).not.toBe(null);
});
it("adjusts z order when grouping", () => {
const positions = [];
2020-08-28 08:15:29 +00:00
UI.clickTool("rectangle");
mouse.down(10, 10);
mouse.up(10, 10);
positions.push(mouse.getPosition());
2020-08-28 08:15:29 +00:00
UI.clickTool("rectangle");
mouse.down(10, -10);
mouse.up(10, 10);
positions.push(mouse.getPosition());
2020-08-28 08:15:29 +00:00
UI.clickTool("rectangle");
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 08:15:29 +00:00
Keyboard.withModifierKeys({ shift: true }, () => {
mouse.click();
});
2020-08-28 08:15:29 +00:00
Keyboard.withModifierKeys({ ctrl: true }, () => {
Keyboard.keyPress(KEYS.G);
});
expect(h.elements.map((element) => element.id)).toEqual([
ids[1],
ids[0],
ids[2],
]);
});
it("supports nested groups", () => {
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-08-28 08:15:29 +00:00
Keyboard.withModifierKeys({ ctrl: true }, () => {
Keyboard.keyPress(KEYS.A);
Keyboard.keyPress(KEYS.G);
});
mouse.doubleClickOn(rectC);
2020-08-28 08:15:29 +00:00
Keyboard.withModifierKeys({ shift: true }, () => {
mouse.clickOn(rectA);
});
2020-08-28 08:15:29 +00:00
Keyboard.withModifierKeys({ ctrl: true }, () => {
Keyboard.keyPress(KEYS.G);
});
expect(rectC.groupIds.length).toBe(2);
expect(rectA.groupIds).toEqual(rectC.groupIds);
expect(rectB.groupIds).toEqual(rectA.groupIds.slice(1));
mouse.click(0, 100);
2020-08-28 08:15:29 +00:00
expect(API.getSelectedElements().length).toBe(0);
mouse.clickOn(rectA);
2020-08-28 08:15:29 +00:00
expect(API.getSelectedElements().length).toBe(3);
expect(h.state.editingGroupId).toBe(null);
mouse.doubleClickOn(rectA);
2020-08-28 08:15:29 +00:00
expect(API.getSelectedElements().length).toBe(2);
expect(h.state.editingGroupId).toBe(rectA.groupIds[1]);
mouse.doubleClickOn(rectA);
2020-08-28 08:15:29 +00:00
expect(API.getSelectedElements().length).toBe(1);
expect(h.state.editingGroupId).toBe(rectA.groupIds[0]);
// click outside current (sub)group
mouse.clickOn(rectB);
2020-08-28 08:15:29 +00:00
expect(API.getSelectedElements().length).toBe(3);
mouse.doubleClickOn(rectB);
2020-08-28 08:15:29 +00:00
expect(API.getSelectedElements().length).toBe(1);
});
2020-05-29 19:59:39 +00:00
it("updates fontSize & fontFamily appState", () => {
2020-08-28 08:15:29 +00:00
UI.clickTool("text");
expect(h.state.currentItemFontFamily).toEqual(FONT_FAMILY.Virgil);
fireEvent.click(screen.getByTitle(/code/i));
expect(h.state.currentItemFontFamily).toEqual(FONT_FAMILY.Cascadia);
2020-05-29 19:59:39 +00:00
});
it("deselects selected element, on pointer up, when click hits element bounding box but doesn't hit the element", () => {
2020-08-28 08:15:29 +00:00
UI.clickTool("ellipse");
mouse.down();
mouse.up(100, 100);
2020-08-28 08:15:29 +00:00
expect(API.getSelectedElements().length).toBe(1);
// hits bounding box without hitting element
mouse.down(98, 98);
mouse.up();
2020-08-28 08:15:29 +00:00
expect(API.getSelectedElements().length).toBe(0);
});
it("switches selected element on pointer down", () => {
2020-08-28 08:15:29 +00:00
UI.clickTool("rectangle");
mouse.down();
mouse.up(10, 10);
2020-08-28 08:15:29 +00:00
UI.clickTool("ellipse");
mouse.down(10, 10);
mouse.up(10, 10);
2020-08-28 08:15:29 +00:00
expect(API.getSelectedElement().type).toBe("ellipse");
// pointer down on rectangle
mouse.reset();
mouse.down();
2020-08-28 08:15:29 +00:00
expect(API.getSelectedElement().type).toBe("rectangle");
});
it("can drag element that covers another element, while another elem is selected", () => {
2020-08-28 08:15:29 +00:00
UI.clickTool("rectangle");
mouse.down(100, 100);
mouse.up(200, 200);
2020-08-28 08:15:29 +00:00
UI.clickTool("rectangle");
mouse.reset();
mouse.down(100, 100);
mouse.up(200, 200);
2020-08-28 08:15:29 +00:00
UI.clickTool("ellipse");
mouse.reset();
mouse.down(300, 300);
mouse.up(350, 350);
2020-08-28 08:15:29 +00:00
expect(API.getSelectedElement().type).toBe("ellipse");
// pointer down on rectangle
mouse.reset();
mouse.down(100, 100);
mouse.up(200, 200);
2020-08-28 08:15:29 +00:00
expect(API.getSelectedElement().type).toBe("rectangle");
});
it("deselects selected element on pointer down when pointer doesn't hit any element", () => {
2020-08-28 08:15:29 +00:00
UI.clickTool("rectangle");
mouse.down();
mouse.up(10, 10);
2020-08-28 08:15:29 +00:00
expect(API.getSelectedElements().length).toBe(1);
// pointer down on space without elements
mouse.down(100, 100);
2020-08-28 08:15:29 +00:00
expect(API.getSelectedElements().length).toBe(0);
});
it("Drags selected element when hitting only bounding box and keeps element selected", () => {
2020-08-28 08:15:29 +00:00
UI.clickTool("ellipse");
mouse.down();
mouse.up(10, 10);
2020-08-28 08:15:29 +00:00
const { x: prevX, y: prevY } = API.getSelectedElement();
// drag element from point on bounding box that doesn't hit element
mouse.reset();
mouse.down(8, 8);
mouse.up(25, 25);
2020-08-28 08:15:29 +00:00
expect(API.getSelectedElement().x).toEqual(prevX + 25);
expect(API.getSelectedElement().y).toEqual(prevY + 25);
});
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",
() => {
// set background color since default is transparent
// and transparent elements can't be selected by clicking inside of them
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);
// pointerdown on rect2 covering rect1 while rect1 is selected should
// retain rect1 selection
mouse.down(900, 900);
expect(API.getSelectedElement().id).toBe(rect1.id);
// pointerup should select rect2
mouse.up();
expect(API.getSelectedElement().id).toBe(rect2.id);
},
);
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",
() => {
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-28 08:15:29 +00:00
const { x: prevX, y: prevY } = API.getSelectedElement();
// pointer down on intersection between ellipse and rectangle
mouse.down(900, 900);
mouse.up(100, 100);
expect(API.getSelectedElement().id).toBe(rect1.id);
2020-08-28 08:15:29 +00:00
expect(API.getSelectedElement().x).toEqual(prevX + 100);
expect(API.getSelectedElement().y).toEqual(prevY + 100);
},
);
it("deselects group of selected elements on pointer down when pointer doesn't hit any element", () => {
2020-08-28 08:15:29 +00:00
UI.clickTool("rectangle");
mouse.down();
mouse.up(10, 10);
2020-08-28 08:15:29 +00:00
UI.clickTool("ellipse");
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 08:15:29 +00:00
Keyboard.withModifierKeys({ shift: true }, () => {
mouse.click(5, 5);
});
2020-08-28 08:15:29 +00:00
expect(API.getSelectedElements().length).toBe(2);
// pointer down on space without elements
mouse.reset();
mouse.down(500, 500);
2020-08-28 08:15:29 +00:00
expect(API.getSelectedElements().length).toBe(0);
});
it("switches from group of selected elements to another element on pointer down", () => {
2020-08-28 08:15:29 +00:00
UI.clickTool("rectangle");
mouse.down();
mouse.up(10, 10);
2020-08-28 08:15:29 +00:00
UI.clickTool("ellipse");
mouse.down(100, 100);
mouse.up(100, 100);
2020-08-28 08:15:29 +00:00
UI.clickTool("diamond");
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 08:15:29 +00:00
Keyboard.withModifierKeys({ shift: true }, () => {
mouse.click(110, 160);
});
2020-08-28 08:15:29 +00:00
expect(API.getSelectedElements().length).toBe(2);
// select rectangle
mouse.reset();
mouse.down();
2020-08-28 08:15:29 +00:00
expect(API.getSelectedElement().type).toBe("rectangle");
});
it("deselects group of selected elements on pointer up when pointer hits common bounding box without hitting any element", () => {
2020-08-28 08:15:29 +00:00
UI.clickTool("rectangle");
mouse.down();
mouse.up(10, 10);
2020-08-28 08:15:29 +00:00
UI.clickTool("ellipse");
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 08:15:29 +00:00
Keyboard.withModifierKeys({ shift: true }, () => {
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 08:15:29 +00:00
expect(API.getSelectedElements().length).toBe(2);
mouse.up();
2020-08-28 08:15:29 +00:00
expect(API.getSelectedElements().length).toBe(0);
});
it("drags selected elements from point inside common bounding box that doesn't hit any element and keeps elements selected after dragging", () => {
UI.clickTool("rectangle");
mouse.down();
mouse.up(10, 10);
UI.clickTool("ellipse");
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();
Keyboard.withModifierKeys({ shift: true }, () => {
mouse.click(5, 5);
});
expect(API.getSelectedElements().length).toBe(2);
const { x: firstElementPrevX, y: firstElementPrevY } =
API.getSelectedElements()[0];
const { x: secondElementPrevX, y: secondElementPrevY } =
API.getSelectedElements()[1];
// 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);
expect(API.getSelectedElements()[0].x).toEqual(firstElementPrevX + 25);
expect(API.getSelectedElements()[0].y).toEqual(firstElementPrevY + 25);
expect(API.getSelectedElements()[1].x).toEqual(secondElementPrevX + 25);
expect(API.getSelectedElements()[1].y).toEqual(secondElementPrevY + 25);
expect(API.getSelectedElements().length).toBe(2);
});
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 08:15:29 +00:00
UI.clickTool("rectangle");
mouse.down();
mouse.up(10, 10);
2020-08-28 08:15:29 +00:00
UI.clickTool("ellipse");
mouse.down(100, 100);
mouse.up(100, 100);
2020-08-28 08:15:29 +00:00
UI.clickTool("diamond");
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 08:15:29 +00:00
Keyboard.withModifierKeys({ shift: true }, () => {
mouse.click();
});
// pointer down on ellipse
mouse.down(110, 160);
2020-08-28 08:15:29 +00:00
expect(API.getSelectedElements().length).toBe(2);
mouse.up();
2020-08-28 08:15:29 +00:00
expect(API.getSelectedElement().type).toBe("ellipse");
},
);
it(
"given a selected element A and a not selected element B with higher z-index than A " +
"and given B partially overlaps A " +
"when there's a shift-click on the overlapped section B is added to the selection",
() => {
2020-08-28 08:15:29 +00:00
UI.clickTool("rectangle");
// change background color since default is transparent
// and transparent elements can't be selected by clicking inside of them
togglePopover("Background");
UI.clickOnTestId("color-red");
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 08:15:29 +00:00
UI.clickTool("ellipse");
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 08:15:29 +00:00
Keyboard.withModifierKeys({ shift: true }, () => {
mouse.click(900, 900);
});
2020-08-28 08:15:29 +00:00
expect(API.getSelectedElements().length).toBe(2);
},
);
it("shift click on selected element should deselect it on pointer up", () => {
2020-08-28 08:15:29 +00:00
UI.clickTool("rectangle");
mouse.down();
mouse.up(10, 10);
// Rectangle is already selected since creating
// it was our last action
2020-08-28 08:15:29 +00:00
Keyboard.withModifierKeys({ shift: true }, () => {
mouse.down(-8, -8);
});
2020-08-28 08:15:29 +00:00
expect(API.getSelectedElements().length).toBe(1);
2020-08-28 08:15:29 +00:00
Keyboard.withModifierKeys({ shift: true }, () => {
mouse.up();
});
2020-08-28 08:15:29 +00:00
expect(API.getSelectedElements().length).toBe(0);
});
2020-08-27 18:32:10 +00:00
it("single-clicking on a subgroup of a selected group should not alter selection", () => {
2020-08-28 08:15:29 +00:00
const rect1 = UI.createElement("rectangle", { x: 10 });
const rect2 = UI.createElement("rectangle", { x: 50 });
UI.group([rect1, rect2]);
2020-08-27 18:32:10 +00:00
2020-08-28 08:15:29 +00: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 18:32:10 +00:00
2020-08-28 08:15:29 +00:00
Keyboard.withModifierKeys({ ctrl: true }, () => {
Keyboard.keyPress(KEYS.A);
Keyboard.keyPress(KEYS.G);
2020-08-27 18:32:10 +00:00
});
const selectedGroupIds_prev = h.state.selectedGroupIds;
2020-08-28 08:15:29 +00:00
const selectedElements_prev = API.getSelectedElements();
2020-08-27 18:32:10 +00:00
mouse.clickOn(rect3);
expect(h.state.selectedGroupIds).toEqual(selectedGroupIds_prev);
2020-08-28 08:15:29 +00:00
expect(API.getSelectedElements()).toEqual(selectedElements_prev);
2020-08-27 18:32:10 +00:00
});
it("Cmd/Ctrl-click exclusively select element under pointer", () => {
2020-08-28 08:15:29 +00:00
const rect1 = UI.createElement("rectangle", { x: 0 });
const rect2 = UI.createElement("rectangle", { x: 30 });
2020-08-28 08:15:29 +00:00
UI.group([rect1, rect2]);
assertSelectedElements(rect1, rect2);
2020-08-28 08:15:29 +00:00
Keyboard.withModifierKeys({ ctrl: true }, () => {
mouse.clickOn(rect1);
});
assertSelectedElements(rect1);
2020-08-28 08:15:29 +00:00
API.clearSelection();
Keyboard.withModifierKeys({ ctrl: true }, () => {
mouse.clickOn(rect1);
});
assertSelectedElements(rect1);
2020-08-28 08:15:29 +00:00
const rect3 = UI.createElement("rectangle", { x: 60 });
UI.group([rect1, rect3]);
assertSelectedElements(rect1, rect2, rect3);
2020-08-28 08:15:29 +00:00
Keyboard.withModifierKeys({ ctrl: true }, () => {
mouse.clickOn(rect1);
});
assertSelectedElements(rect1);
2020-08-28 08:15:29 +00:00
API.clearSelection();
Keyboard.withModifierKeys({ ctrl: true }, () => {
mouse.clickOn(rect3);
});
assertSelectedElements(rect3);
});
it("should show fill icons when element has non transparent background", async () => {
UI.clickTool("rectangle");
expect(screen.queryByText(/fill/i)).not.toBeNull();
mouse.down();
mouse.up(10, 10);
expect(screen.queryByText(/fill/i)).toBeNull();
togglePopover("Background");
UI.clickOnTestId("color-red");
// select rectangle
mouse.reset();
mouse.click();
expect(screen.queryByText(/fill/i)).not.toBeNull();
});
2020-03-23 23:38:41 +00: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 08:15:29 +00:00
const rect1 = UI.createElement("rectangle", { y: 0 });
const rect2 = UI.createElement("rectangle", { y: 30 });
const rect3 = UI.createElement("rectangle", { y: 60 });
2020-08-28 08:15:29 +00:00
UI.group([rect1, rect3]);
2020-08-28 08:15:29 +00:00
expect(API.getSelectedElements().length).toBe(2);
2020-08-27 18:32:10 +00:00
expect(Object.keys(h.state.selectedGroupIds).length).toBe(1);
// Select second rectangle without deselecting group
2020-08-28 08:15:29 +00:00
Keyboard.withModifierKeys({ shift: true }, () => {
2020-08-27 18:32:10 +00:00
mouse.clickOn(rect2);
});
2020-08-28 08:15:29 +00:00
expect(API.getSelectedElements().length).toBe(3);
2020-08-27 18:32:10 +00:00
// clicking on first rectangle that is part of the group should select
// that group (exclusively)
2020-08-27 18:32:10 +00:00
mouse.clickOn(rect1);
2020-08-28 08:15:29 +00:00
expect(API.getSelectedElements().length).toBe(2);
2020-08-27 18:32:10 +00:00
expect(Object.keys(h.state.selectedGroupIds).length).toBe(1);
},
);
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 08:15:29 +00:00
UI.clickTool("rectangle");
mouse.down();
mouse.up(100, 100);
2020-08-28 08:15:29 +00:00
UI.clickTool("rectangle");
mouse.down(10, 10);
mouse.up(100, 100);
2020-08-28 08:15:29 +00:00
UI.clickTool("rectangle");
mouse.down(10, 10);
mouse.up(100, 100);
// Select first rectangle while keeping third one selected.
// Third rectangle is selected because it was the last element to be created.
mouse.reset();
2020-08-28 08:15:29 +00:00
Keyboard.withModifierKeys({ shift: true }, () => {
mouse.click();
});
// Create group with first and third rectangle
2020-08-28 08:15:29 +00:00
Keyboard.withModifierKeys({ ctrl: true }, () => {
Keyboard.keyPress(KEYS.G);
});
2020-08-28 08:15:29 +00:00
expect(API.getSelectedElements().length).toBe(2);
const selectedGroupIds = Object.keys(h.state.selectedGroupIds);
expect(selectedGroupIds.length).toBe(1);
// Select second rectangle without deselecting group
2020-08-28 08:15:29 +00:00
Keyboard.withModifierKeys({ shift: true }, () => {
mouse.click(110, 110);
});
2020-08-28 08:15:29 +00:00
expect(API.getSelectedElements().length).toBe(3);
// Pointer down o first rectangle that is part of the group
mouse.reset();
2020-08-28 08:15:29 +00:00
Keyboard.withModifierKeys({ shift: true }, () => {
mouse.down();
});
2020-08-28 08:15:29 +00:00
expect(API.getSelectedElements().length).toBe(3);
Keyboard.withModifierKeys({ shift: true }, () => {
mouse.up();
});
2020-08-28 08:15:29 +00:00
expect(API.getSelectedElements().length).toBe(1);
},
);