|  | @@ -3,7 +3,11 @@ import ExcalidrawApp from "../excalidraw-app";
 | 
	
		
			
				|  |  |  import { GlobalTestState, render, screen } from "../tests/test-utils";
 | 
	
		
			
				|  |  |  import { Keyboard, Pointer, UI } from "../tests/helpers/ui";
 | 
	
		
			
				|  |  |  import { CODES, KEYS } from "../keys";
 | 
	
		
			
				|  |  | -import { fireEvent } from "../tests/test-utils";
 | 
	
		
			
				|  |  | +import {
 | 
	
		
			
				|  |  | +  fireEvent,
 | 
	
		
			
				|  |  | +  mockBoundingClientRect,
 | 
	
		
			
				|  |  | +  restoreOriginalGetBoundingClientRect,
 | 
	
		
			
				|  |  | +} from "../tests/test-utils";
 | 
	
		
			
				|  |  |  import { queryByText } from "@testing-library/react";
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import { FONT_FAMILY } from "../constants";
 | 
	
	
		
			
				|  | @@ -221,11 +225,19 @@ describe("textWysiwyg", () => {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    describe("Test container-unbound text", () => {
 | 
	
		
			
				|  |  |      const { h } = window;
 | 
	
		
			
				|  |  | +    const dimensions = { height: 400, width: 800 };
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      let textarea: HTMLTextAreaElement;
 | 
	
		
			
				|  |  |      let textElement: ExcalidrawTextElement;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    beforeAll(() => {
 | 
	
		
			
				|  |  | +      mockBoundingClientRect(dimensions);
 | 
	
		
			
				|  |  | +    });
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      beforeEach(async () => {
 | 
	
		
			
				|  |  |        await render(<ExcalidrawApp />);
 | 
	
		
			
				|  |  | +      //@ts-ignore
 | 
	
		
			
				|  |  | +      h.app.refreshDeviceState(h.app.excalidrawContainerRef.current!);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |        textElement = UI.createElement("text");
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -235,6 +247,10 @@ describe("textWysiwyg", () => {
 | 
	
		
			
				|  |  |        )!;
 | 
	
		
			
				|  |  |      });
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    afterAll(() => {
 | 
	
		
			
				|  |  | +      restoreOriginalGetBoundingClientRect();
 | 
	
		
			
				|  |  | +    });
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      it("should add a tab at the start of the first line", () => {
 | 
	
		
			
				|  |  |        const event = new KeyboardEvent("keydown", { key: KEYS.TAB });
 | 
	
		
			
				|  |  |        textarea.value = "Line#1\nLine#2";
 | 
	
	
		
			
				|  | @@ -433,6 +449,27 @@ describe("textWysiwyg", () => {
 | 
	
		
			
				|  |  |        );
 | 
	
		
			
				|  |  |        expect(h.state.zoom.value).toBe(1);
 | 
	
		
			
				|  |  |      });
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    it("text should never go beyond max width", async () => {
 | 
	
		
			
				|  |  | +      UI.clickTool("text");
 | 
	
		
			
				|  |  | +      mouse.clickAt(750, 300);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +      textarea = document.querySelector(
 | 
	
		
			
				|  |  | +        ".excalidraw-textEditorContainer > textarea",
 | 
	
		
			
				|  |  | +      )!;
 | 
	
		
			
				|  |  | +      fireEvent.change(textarea, {
 | 
	
		
			
				|  |  | +        target: {
 | 
	
		
			
				|  |  | +          value:
 | 
	
		
			
				|  |  | +            "Excalidraw is an opensource virtual collaborative whiteboard for sketching hand-drawn like diagrams!",
 | 
	
		
			
				|  |  | +        },
 | 
	
		
			
				|  |  | +      });
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +      textarea.dispatchEvent(new Event("input"));
 | 
	
		
			
				|  |  | +      await new Promise((cb) => setTimeout(cb, 0));
 | 
	
		
			
				|  |  | +      textarea.blur();
 | 
	
		
			
				|  |  | +      expect(textarea.style.width).toBe("792px");
 | 
	
		
			
				|  |  | +      expect(h.elements[0].width).toBe(1000);
 | 
	
		
			
				|  |  | +    });
 | 
	
		
			
				|  |  |    });
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    describe("Test container-bound text", () => {
 | 
	
	
		
			
				|  | @@ -631,11 +668,11 @@ describe("textWysiwyg", () => {
 | 
	
		
			
				|  |  |      ["freedraw", "line"].forEach((type: any) => {
 | 
	
		
			
				|  |  |        it(`shouldn't create text element when pressing 'Enter' key on ${type} `, async () => {
 | 
	
		
			
				|  |  |          h.elements = [];
 | 
	
		
			
				|  |  | -        const elemnet = UI.createElement(type, {
 | 
	
		
			
				|  |  | +        const element = UI.createElement(type, {
 | 
	
		
			
				|  |  |            width: 100,
 | 
	
		
			
				|  |  |            height: 50,
 | 
	
		
			
				|  |  |          });
 | 
	
		
			
				|  |  | -        API.setSelectedElements([elemnet]);
 | 
	
		
			
				|  |  | +        API.setSelectedElements([element]);
 | 
	
		
			
				|  |  |          Keyboard.keyPress(KEYS.ENTER);
 | 
	
		
			
				|  |  |          expect(h.elements.length).toBe(1);
 | 
	
		
			
				|  |  |        });
 |