|
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
|
|
import { API } from "../tests/helpers/api";
|
|
|
|
|
import { mutateElement } from "./mutateElement";
|
|
|
|
|
import { getOriginalContainerHeightFromCache } from "./textWysiwyg";
|
|
|
|
|
import { getTextEditor } from "../tests/queries/dom";
|
|
|
|
|
import { getTextEditor, updateTextEditor } from "../tests/queries/dom";
|
|
|
|
|
|
|
|
|
|
// Unmount ReactDOM from root
|
|
|
|
|
ReactDOM.unmountComponentAtNode(document.getElementById("root")!);
|
|
|
|
@@ -26,10 +26,7 @@ ReactDOM.unmountComponentAtNode(document.getElementById("root")!);
|
|
|
|
|
const tab = " ";
|
|
|
|
|
const mouse = new Pointer("mouse");
|
|
|
|
|
|
|
|
|
|
const updateTextEditor = (editor: HTMLTextAreaElement, value: string) => {
|
|
|
|
|
fireEvent.change(editor, { target: { value } });
|
|
|
|
|
editor.dispatchEvent(new Event("input"));
|
|
|
|
|
};
|
|
|
|
|
const textEditorSelector = ".excalidraw-textEditorContainer > textarea";
|
|
|
|
|
|
|
|
|
|
describe("textWysiwyg", () => {
|
|
|
|
|
describe("start text editing", () => {
|
|
|
|
@@ -195,7 +192,7 @@ describe("textWysiwyg", () => {
|
|
|
|
|
|
|
|
|
|
mouse.clickAt(text.x + 50, text.y + 50);
|
|
|
|
|
|
|
|
|
|
const editor = await getTextEditor(false);
|
|
|
|
|
const editor = await getTextEditor(textEditorSelector, false);
|
|
|
|
|
|
|
|
|
|
expect(editor).not.toBe(null);
|
|
|
|
|
expect(h.state.editingElement?.id).toBe(text.id);
|
|
|
|
@@ -217,7 +214,7 @@ describe("textWysiwyg", () => {
|
|
|
|
|
|
|
|
|
|
mouse.doubleClickAt(text.x + 50, text.y + 50);
|
|
|
|
|
|
|
|
|
|
const editor = await getTextEditor(false);
|
|
|
|
|
const editor = await getTextEditor(textEditorSelector, false);
|
|
|
|
|
|
|
|
|
|
expect(editor).not.toBe(null);
|
|
|
|
|
expect(h.state.editingElement?.id).toBe(text.id);
|
|
|
|
@@ -252,13 +249,15 @@ describe("textWysiwyg", () => {
|
|
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
|
await render(<Excalidraw handleKeyboardGlobally={true} />);
|
|
|
|
|
//@ts-ignore
|
|
|
|
|
h.app.refreshDeviceState(h.app.excalidrawContainerRef.current!);
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
h.app.refreshViewportBreakpoints();
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
h.app.refreshEditorBreakpoints();
|
|
|
|
|
|
|
|
|
|
textElement = UI.createElement("text");
|
|
|
|
|
|
|
|
|
|
mouse.clickOn(textElement);
|
|
|
|
|
textarea = await getTextEditor(true);
|
|
|
|
|
textarea = await getTextEditor(textEditorSelector, true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
afterAll(() => {
|
|
|
|
@@ -468,7 +467,7 @@ describe("textWysiwyg", () => {
|
|
|
|
|
UI.clickTool("text");
|
|
|
|
|
mouse.clickAt(750, 300);
|
|
|
|
|
|
|
|
|
|
textarea = await getTextEditor(true);
|
|
|
|
|
textarea = await getTextEditor(textEditorSelector, true);
|
|
|
|
|
updateTextEditor(
|
|
|
|
|
textarea,
|
|
|
|
|
"Excalidraw is an opensource virtual collaborative whiteboard for sketching hand-drawn like diagrams!",
|
|
|
|
@@ -520,7 +519,7 @@ describe("textWysiwyg", () => {
|
|
|
|
|
{ id: text.id, type: "text" },
|
|
|
|
|
]);
|
|
|
|
|
mouse.down();
|
|
|
|
|
const editor = await getTextEditor(true);
|
|
|
|
|
const editor = await getTextEditor(textEditorSelector, true);
|
|
|
|
|
|
|
|
|
|
updateTextEditor(editor, "Hello World!");
|
|
|
|
|
|
|
|
|
@@ -548,7 +547,7 @@ describe("textWysiwyg", () => {
|
|
|
|
|
]);
|
|
|
|
|
expect(text.angle).toBe(rectangle.angle);
|
|
|
|
|
mouse.down();
|
|
|
|
|
const editor = await getTextEditor(true);
|
|
|
|
|
const editor = await getTextEditor(textEditorSelector, true);
|
|
|
|
|
|
|
|
|
|
updateTextEditor(editor, "Hello World!");
|
|
|
|
|
|
|
|
|
@@ -575,7 +574,7 @@ describe("textWysiwyg", () => {
|
|
|
|
|
API.setSelectedElements([diamond]);
|
|
|
|
|
Keyboard.keyPress(KEYS.ENTER);
|
|
|
|
|
|
|
|
|
|
const editor = await getTextEditor(true);
|
|
|
|
|
const editor = await getTextEditor(textEditorSelector, true);
|
|
|
|
|
|
|
|
|
|
await new Promise((r) => setTimeout(r, 0));
|
|
|
|
|
const value = new Array(1000).fill("1").join("\n");
|
|
|
|
@@ -610,7 +609,7 @@ describe("textWysiwyg", () => {
|
|
|
|
|
expect(text.type).toBe("text");
|
|
|
|
|
expect(text.containerId).toBe(null);
|
|
|
|
|
mouse.down();
|
|
|
|
|
let editor = await getTextEditor(true);
|
|
|
|
|
let editor = await getTextEditor(textEditorSelector, true);
|
|
|
|
|
await new Promise((r) => setTimeout(r, 0));
|
|
|
|
|
editor.blur();
|
|
|
|
|
|
|
|
|
@@ -625,7 +624,7 @@ describe("textWysiwyg", () => {
|
|
|
|
|
expect(text.containerId).toBe(rectangle.id);
|
|
|
|
|
|
|
|
|
|
mouse.down();
|
|
|
|
|
editor = await getTextEditor(true);
|
|
|
|
|
editor = await getTextEditor(textEditorSelector, true);
|
|
|
|
|
|
|
|
|
|
updateTextEditor(editor, "Hello World!");
|
|
|
|
|
await new Promise((r) => setTimeout(r, 0));
|
|
|
|
@@ -647,7 +646,7 @@ describe("textWysiwyg", () => {
|
|
|
|
|
const text = h.elements[1] as ExcalidrawTextElementWithContainer;
|
|
|
|
|
expect(text.type).toBe("text");
|
|
|
|
|
expect(text.containerId).toBe(rectangle.id);
|
|
|
|
|
const editor = await getTextEditor(true);
|
|
|
|
|
const editor = await getTextEditor(textEditorSelector, true);
|
|
|
|
|
|
|
|
|
|
await new Promise((r) => setTimeout(r, 0));
|
|
|
|
|
|
|
|
|
@@ -682,7 +681,7 @@ describe("textWysiwyg", () => {
|
|
|
|
|
{ id: text.id, type: "text" },
|
|
|
|
|
]);
|
|
|
|
|
mouse.down();
|
|
|
|
|
const editor = await getTextEditor(true);
|
|
|
|
|
const editor = await getTextEditor(textEditorSelector, true);
|
|
|
|
|
updateTextEditor(editor, "Hello World!");
|
|
|
|
|
|
|
|
|
|
await new Promise((r) => setTimeout(r, 0));
|
|
|
|
@@ -707,7 +706,7 @@ describe("textWysiwyg", () => {
|
|
|
|
|
freedraw.y + freedraw.height / 2,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const editor = await getTextEditor(true);
|
|
|
|
|
const editor = await getTextEditor(textEditorSelector, true);
|
|
|
|
|
updateTextEditor(editor, "Hello World!");
|
|
|
|
|
fireEvent.keyDown(editor, { key: KEYS.ESCAPE });
|
|
|
|
|
|
|
|
|
@@ -741,7 +740,7 @@ describe("textWysiwyg", () => {
|
|
|
|
|
expect(text.type).toBe("text");
|
|
|
|
|
expect(text.containerId).toBe(null);
|
|
|
|
|
mouse.down();
|
|
|
|
|
const editor = await getTextEditor(true);
|
|
|
|
|
const editor = await getTextEditor(textEditorSelector, true);
|
|
|
|
|
|
|
|
|
|
updateTextEditor(editor, "Hello World!");
|
|
|
|
|
|
|
|
|
@@ -756,7 +755,7 @@ describe("textWysiwyg", () => {
|
|
|
|
|
|
|
|
|
|
UI.clickTool("text");
|
|
|
|
|
mouse.clickAt(20, 30);
|
|
|
|
|
const editor = await getTextEditor(true);
|
|
|
|
|
const editor = await getTextEditor(textEditorSelector, true);
|
|
|
|
|
|
|
|
|
|
updateTextEditor(
|
|
|
|
|
editor,
|
|
|
|
@@ -801,7 +800,7 @@ describe("textWysiwyg", () => {
|
|
|
|
|
mouse.down();
|
|
|
|
|
|
|
|
|
|
const text = h.elements[1] as ExcalidrawTextElementWithContainer;
|
|
|
|
|
let editor = await getTextEditor(true);
|
|
|
|
|
let editor = await getTextEditor(textEditorSelector, true);
|
|
|
|
|
|
|
|
|
|
await new Promise((r) => setTimeout(r, 0));
|
|
|
|
|
updateTextEditor(editor, "Hello World!");
|
|
|
|
@@ -814,7 +813,7 @@ describe("textWysiwyg", () => {
|
|
|
|
|
rectangle.y + rectangle.height / 2,
|
|
|
|
|
);
|
|
|
|
|
mouse.down();
|
|
|
|
|
editor = await getTextEditor(true);
|
|
|
|
|
editor = await getTextEditor(textEditorSelector, true);
|
|
|
|
|
|
|
|
|
|
editor.select();
|
|
|
|
|
fireEvent.click(screen.getByTitle(/code/i));
|
|
|
|
@@ -847,7 +846,7 @@ describe("textWysiwyg", () => {
|
|
|
|
|
|
|
|
|
|
Keyboard.keyDown(KEYS.ENTER);
|
|
|
|
|
let text = h.elements[1] as ExcalidrawTextElementWithContainer;
|
|
|
|
|
let editor = await getTextEditor(true);
|
|
|
|
|
let editor = await getTextEditor(textEditorSelector, true);
|
|
|
|
|
|
|
|
|
|
updateTextEditor(editor, "Hello World!");
|
|
|
|
|
|
|
|
|
@@ -868,7 +867,7 @@ describe("textWysiwyg", () => {
|
|
|
|
|
mouse.select(rectangle);
|
|
|
|
|
Keyboard.keyPress(KEYS.ENTER);
|
|
|
|
|
|
|
|
|
|
editor = await getTextEditor(true);
|
|
|
|
|
editor = await getTextEditor(textEditorSelector, true);
|
|
|
|
|
updateTextEditor(editor, "Hello");
|
|
|
|
|
|
|
|
|
|
await new Promise((r) => setTimeout(r, 0));
|
|
|
|
@@ -897,7 +896,7 @@ describe("textWysiwyg", () => {
|
|
|
|
|
const text = h.elements[1] as ExcalidrawTextElementWithContainer;
|
|
|
|
|
expect(text.containerId).toBe(rectangle.id);
|
|
|
|
|
|
|
|
|
|
const editor = await getTextEditor(true);
|
|
|
|
|
const editor = await getTextEditor(textEditorSelector, true);
|
|
|
|
|
|
|
|
|
|
await new Promise((r) => setTimeout(r, 0));
|
|
|
|
|
|
|
|
|
@@ -934,7 +933,7 @@ describe("textWysiwyg", () => {
|
|
|
|
|
// Bind first text
|
|
|
|
|
const text = h.elements[1] as ExcalidrawTextElementWithContainer;
|
|
|
|
|
expect(text.containerId).toBe(rectangle.id);
|
|
|
|
|
const editor = await getTextEditor(true);
|
|
|
|
|
const editor = await getTextEditor(textEditorSelector, true);
|
|
|
|
|
await new Promise((r) => setTimeout(r, 0));
|
|
|
|
|
updateTextEditor(editor, "Hello World!");
|
|
|
|
|
editor.blur();
|
|
|
|
@@ -955,7 +954,7 @@ describe("textWysiwyg", () => {
|
|
|
|
|
it("should respect text alignment when resizing", async () => {
|
|
|
|
|
Keyboard.keyPress(KEYS.ENTER);
|
|
|
|
|
|
|
|
|
|
let editor = await getTextEditor(true);
|
|
|
|
|
let editor = await getTextEditor(textEditorSelector, true);
|
|
|
|
|
await new Promise((r) => setTimeout(r, 0));
|
|
|
|
|
updateTextEditor(editor, "Hello");
|
|
|
|
|
editor.blur();
|
|
|
|
@@ -972,7 +971,7 @@ describe("textWysiwyg", () => {
|
|
|
|
|
mouse.select(rectangle);
|
|
|
|
|
Keyboard.keyPress(KEYS.ENTER);
|
|
|
|
|
|
|
|
|
|
editor = await getTextEditor(true);
|
|
|
|
|
editor = await getTextEditor(textEditorSelector, true);
|
|
|
|
|
|
|
|
|
|
editor.select();
|
|
|
|
|
|
|
|
|
@@ -995,7 +994,7 @@ describe("textWysiwyg", () => {
|
|
|
|
|
|
|
|
|
|
mouse.select(rectangle);
|
|
|
|
|
Keyboard.keyPress(KEYS.ENTER);
|
|
|
|
|
editor = await getTextEditor(true);
|
|
|
|
|
editor = await getTextEditor(textEditorSelector, true);
|
|
|
|
|
|
|
|
|
|
editor.select();
|
|
|
|
|
|
|
|
|
@@ -1033,7 +1032,7 @@ describe("textWysiwyg", () => {
|
|
|
|
|
expect(text.type).toBe("text");
|
|
|
|
|
expect(text.containerId).toBe(rectangle.id);
|
|
|
|
|
mouse.down();
|
|
|
|
|
const editor = await getTextEditor(true);
|
|
|
|
|
const editor = await getTextEditor(textEditorSelector, true);
|
|
|
|
|
|
|
|
|
|
updateTextEditor(editor, "Hello World!");
|
|
|
|
|
|
|
|
|
@@ -1048,7 +1047,7 @@ describe("textWysiwyg", () => {
|
|
|
|
|
it("should scale font size correctly when resizing using shift", async () => {
|
|
|
|
|
Keyboard.keyPress(KEYS.ENTER);
|
|
|
|
|
|
|
|
|
|
const editor = await getTextEditor(true);
|
|
|
|
|
const editor = await getTextEditor(textEditorSelector, true);
|
|
|
|
|
await new Promise((r) => setTimeout(r, 0));
|
|
|
|
|
updateTextEditor(editor, "Hello");
|
|
|
|
|
editor.blur();
|
|
|
|
@@ -1068,7 +1067,7 @@ describe("textWysiwyg", () => {
|
|
|
|
|
it("should bind text correctly when container duplicated with alt-drag", async () => {
|
|
|
|
|
Keyboard.keyPress(KEYS.ENTER);
|
|
|
|
|
|
|
|
|
|
const editor = await getTextEditor(true);
|
|
|
|
|
const editor = await getTextEditor(textEditorSelector, true);
|
|
|
|
|
await new Promise((r) => setTimeout(r, 0));
|
|
|
|
|
updateTextEditor(editor, "Hello");
|
|
|
|
|
editor.blur();
|
|
|
|
@@ -1100,7 +1099,7 @@ describe("textWysiwyg", () => {
|
|
|
|
|
|
|
|
|
|
it("undo should work", async () => {
|
|
|
|
|
Keyboard.keyPress(KEYS.ENTER);
|
|
|
|
|
const editor = await getTextEditor(true);
|
|
|
|
|
const editor = await getTextEditor(textEditorSelector, true);
|
|
|
|
|
await new Promise((r) => setTimeout(r, 0));
|
|
|
|
|
updateTextEditor(editor, "Hello");
|
|
|
|
|
editor.blur();
|
|
|
|
@@ -1137,7 +1136,7 @@ describe("textWysiwyg", () => {
|
|
|
|
|
|
|
|
|
|
it("should not allow bound text with only whitespaces", async () => {
|
|
|
|
|
Keyboard.keyPress(KEYS.ENTER);
|
|
|
|
|
const editor = await getTextEditor(true);
|
|
|
|
|
const editor = await getTextEditor(textEditorSelector, true);
|
|
|
|
|
await new Promise((r) => setTimeout(r, 0));
|
|
|
|
|
|
|
|
|
|
updateTextEditor(editor, " ");
|
|
|
|
@@ -1192,7 +1191,7 @@ describe("textWysiwyg", () => {
|
|
|
|
|
it("should reset the container height cache when resizing", async () => {
|
|
|
|
|
Keyboard.keyPress(KEYS.ENTER);
|
|
|
|
|
expect(getOriginalContainerHeightFromCache(rectangle.id)).toBe(75);
|
|
|
|
|
let editor = await getTextEditor(true);
|
|
|
|
|
let editor = await getTextEditor(textEditorSelector, true);
|
|
|
|
|
await new Promise((r) => setTimeout(r, 0));
|
|
|
|
|
updateTextEditor(editor, "Hello");
|
|
|
|
|
editor.blur();
|
|
|
|
@@ -1204,7 +1203,7 @@ describe("textWysiwyg", () => {
|
|
|
|
|
mouse.select(rectangle);
|
|
|
|
|
Keyboard.keyPress(KEYS.ENTER);
|
|
|
|
|
|
|
|
|
|
editor = await getTextEditor(true);
|
|
|
|
|
editor = await getTextEditor(textEditorSelector, true);
|
|
|
|
|
|
|
|
|
|
await new Promise((r) => setTimeout(r, 0));
|
|
|
|
|
editor.blur();
|
|
|
|
@@ -1220,7 +1219,7 @@ describe("textWysiwyg", () => {
|
|
|
|
|
Keyboard.keyPress(KEYS.ENTER);
|
|
|
|
|
expect(getOriginalContainerHeightFromCache(rectangle.id)).toBe(75);
|
|
|
|
|
|
|
|
|
|
const editor = await getTextEditor(true);
|
|
|
|
|
const editor = await getTextEditor(textEditorSelector, true);
|
|
|
|
|
updateTextEditor(editor, "Hello World!");
|
|
|
|
|
editor.blur();
|
|
|
|
|
|
|
|
|
@@ -1245,7 +1244,7 @@ describe("textWysiwyg", () => {
|
|
|
|
|
Keyboard.keyPress(KEYS.ENTER);
|
|
|
|
|
expect(getOriginalContainerHeightFromCache(rectangle.id)).toBe(75);
|
|
|
|
|
|
|
|
|
|
const editor = await getTextEditor(true);
|
|
|
|
|
const editor = await getTextEditor(textEditorSelector, true);
|
|
|
|
|
updateTextEditor(editor, "Hello World!");
|
|
|
|
|
editor.blur();
|
|
|
|
|
expect(
|
|
|
|
@@ -1277,12 +1276,12 @@ describe("textWysiwyg", () => {
|
|
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
|
Keyboard.keyPress(KEYS.ENTER);
|
|
|
|
|
editor = await getTextEditor(true);
|
|
|
|
|
editor = await getTextEditor(textEditorSelector, true);
|
|
|
|
|
updateTextEditor(editor, "Hello");
|
|
|
|
|
editor.blur();
|
|
|
|
|
mouse.select(rectangle);
|
|
|
|
|
Keyboard.keyPress(KEYS.ENTER);
|
|
|
|
|
editor = await getTextEditor(true);
|
|
|
|
|
editor = await getTextEditor(textEditorSelector, true);
|
|
|
|
|
editor.select();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@@ -1393,7 +1392,7 @@ describe("textWysiwyg", () => {
|
|
|
|
|
it("should wrap text in a container when wrap text in container triggered from context menu", async () => {
|
|
|
|
|
UI.clickTool("text");
|
|
|
|
|
mouse.clickAt(20, 30);
|
|
|
|
|
const editor = await getTextEditor(true);
|
|
|
|
|
const editor = await getTextEditor(textEditorSelector, true);
|
|
|
|
|
|
|
|
|
|
updateTextEditor(
|
|
|
|
|
editor,
|
|
|
|
@@ -1481,7 +1480,7 @@ describe("textWysiwyg", () => {
|
|
|
|
|
// Bind first text
|
|
|
|
|
let text = h.elements[1] as ExcalidrawTextElementWithContainer;
|
|
|
|
|
expect(text.containerId).toBe(rectangle.id);
|
|
|
|
|
let editor = await getTextEditor(true);
|
|
|
|
|
let editor = await getTextEditor(textEditorSelector, true);
|
|
|
|
|
await new Promise((r) => setTimeout(r, 0));
|
|
|
|
|
updateTextEditor(editor, "Hello!");
|
|
|
|
|
expect(
|
|
|
|
@@ -1506,7 +1505,7 @@ describe("textWysiwyg", () => {
|
|
|
|
|
rectangle.x + rectangle.width / 2,
|
|
|
|
|
rectangle.y + rectangle.height / 2,
|
|
|
|
|
);
|
|
|
|
|
editor = await getTextEditor(true);
|
|
|
|
|
editor = await getTextEditor(textEditorSelector, true);
|
|
|
|
|
await new Promise((r) => setTimeout(r, 0));
|
|
|
|
|
updateTextEditor(editor, "Excalidraw");
|
|
|
|
|
editor.blur();
|
|
|
|
|