diff options
| author | kj_sh604 | 2026-03-15 16:19:35 -0400 |
|---|---|---|
| committer | kj_sh604 | 2026-03-15 16:19:35 -0400 |
| commit | 6ec259a0e71174651bae95d4628138bf6fd68742 (patch) | |
| tree | 5e33c6a5ec091ecabfcb257fdc7b6a88ed8754ac /packages/excalidraw/tests/tool.test.tsx | |
| parent | 16c8578b15c727f22921f8a80a56ee4d4e7f2272 (diff) | |
refactor: packages/
Diffstat (limited to 'packages/excalidraw/tests/tool.test.tsx')
| -rw-r--r-- | packages/excalidraw/tests/tool.test.tsx | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/packages/excalidraw/tests/tool.test.tsx b/packages/excalidraw/tests/tool.test.tsx new file mode 100644 index 0000000..662c61b --- /dev/null +++ b/packages/excalidraw/tests/tool.test.tsx @@ -0,0 +1,64 @@ +import React from "react"; +import { Excalidraw } from "../index"; +import type { ExcalidrawImperativeAPI } from "../types"; +import { resolvablePromise } from "../utils"; +import { act, render } from "./test-utils"; +import { Pointer } from "./helpers/ui"; + +describe("setActiveTool()", () => { + const h = window.h; + + let excalidrawAPI: ExcalidrawImperativeAPI; + + const mouse = new Pointer("mouse"); + + beforeEach(async () => { + const excalidrawAPIPromise = resolvablePromise<ExcalidrawImperativeAPI>(); + await render( + <Excalidraw + excalidrawAPI={(api) => excalidrawAPIPromise.resolve(api as any)} + />, + ); + excalidrawAPI = await excalidrawAPIPromise; + }); + + it("should expose setActiveTool on package API", () => { + expect(excalidrawAPI.setActiveTool).toBeDefined(); + expect(excalidrawAPI.setActiveTool).toBe(h.app.setActiveTool); + }); + + it("should set the active tool type", async () => { + expect(h.state.activeTool.type).toBe("selection"); + act(() => { + excalidrawAPI.setActiveTool({ type: "rectangle" }); + }); + expect(h.state.activeTool.type).toBe("rectangle"); + + mouse.down(10, 10); + mouse.up(20, 20); + + expect(h.state.activeTool.type).toBe("selection"); + }); + + it("should support tool locking", async () => { + expect(h.state.activeTool.type).toBe("selection"); + act(() => { + excalidrawAPI.setActiveTool({ type: "rectangle", locked: true }); + }); + expect(h.state.activeTool.type).toBe("rectangle"); + + mouse.down(10, 10); + mouse.up(20, 20); + + expect(h.state.activeTool.type).toBe("rectangle"); + }); + + it("should set custom tool", async () => { + expect(h.state.activeTool.type).toBe("selection"); + act(() => { + excalidrawAPI.setActiveTool({ type: "custom", customType: "comment" }); + }); + expect(h.state.activeTool.type).toBe("custom"); + expect(h.state.activeTool.customType).toBe("comment"); + }); +}); |
