diff --git a/ui/package.json b/ui/package.json index 7f51dc93c4..ab16f42e64 100644 --- a/ui/package.json +++ b/ui/package.json @@ -33,6 +33,7 @@ "@testing-library/dom": "^10.3.1", "@testing-library/jest-dom": "^6.4.6", "@testing-library/react": "^16.0.0", + "@testing-library/user-event": "^14.5.2", "@types/d3-array": "^3.2.1", "@types/d3-color": "^3.1.3", "@types/d3-hierarchy": "^3.1.7", diff --git a/ui/pnpm-lock.yaml b/ui/pnpm-lock.yaml index 887d61d17c..3536f7286a 100644 --- a/ui/pnpm-lock.yaml +++ b/ui/pnpm-lock.yaml @@ -60,6 +60,9 @@ importers: '@testing-library/react': specifier: ^16.0.0 version: 16.0.0(@testing-library/dom@10.3.1)(@types/react-dom@18.3.0)(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + '@testing-library/user-event': + specifier: ^14.5.2 + version: 14.5.2(@testing-library/dom@10.3.1) '@types/d3-array': specifier: ^3.2.1 version: 3.2.1 @@ -1188,6 +1191,12 @@ packages: '@types/react-dom': optional: true + '@testing-library/user-event@14.5.2': + resolution: {integrity: sha512-YAh82Wh4TIrxYLmfGcixwD18oIjyC1pFQC2Y01F2lzV2HTMiYrI0nze0FD0ocB//CKS/7jIUgae+adPqxK5yCQ==} + engines: {node: '>=12', npm: '>=6'} + peerDependencies: + '@testing-library/dom': '>=7.21.4' + '@types/aria-query@5.0.4': resolution: {integrity: sha512-rfT93uj5s0PRL7EzccGMs3brplhcrghnDoV26NqKhCAS1hVo+WdNsPvE/yb6ilfr5hi2MEk6d5EWJTKdxg8jVw==} @@ -5120,6 +5129,10 @@ snapshots: '@types/react': 18.3.3 '@types/react-dom': 18.3.0 + '@testing-library/user-event@14.5.2(@testing-library/dom@10.3.1)': + dependencies: + '@testing-library/dom': 10.3.1 + '@types/aria-query@5.0.4': {} '@types/d3-array@3.2.1': {} diff --git a/ui/src/TreeMap.tsx b/ui/src/TreeMap.tsx index cc3c75df41..9a08670ec1 100644 --- a/ui/src/TreeMap.tsx +++ b/ui/src/TreeMap.tsx @@ -172,13 +172,13 @@ function TreeMap({ entry }: TreeMapProps) { const onMouseMove = useCallback((e: React.MouseEvent) => { setTooltipPosition([e.clientX, e.clientY]); + console.log(e.clientX, e.clientY); const node = getTargetNode(e); if (node === null) { setTooltipNode(undefined); return; } - setTooltipNode(node); }, [getTargetNode]); @@ -245,7 +245,7 @@ function TreeMap({ entry }: TreeMapProps) { viewBox={`0 0 ${width} ${height}`} onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave} - onMouseMoveCapture={onMouseMove} + onMouseMove={onMouseMove} onClick={onClick} > {nodes} diff --git a/ui/src/Treemap.test.tsx b/ui/src/Treemap.test.tsx index 6b3b60f88e..46d04f946f 100644 --- a/ui/src/Treemap.test.tsx +++ b/ui/src/Treemap.test.tsx @@ -1,5 +1,6 @@ import { describe, expect, it } from "vitest"; import { fireEvent, render } from "@testing-library/react"; +import userEvent from "@testing-library/user-event"; import { createEntry } from "./tool/entry.ts"; import TreeMap from "./TreeMap.tsx"; import { getTestResult } from "./test/testhelper.ts"; @@ -58,7 +59,7 @@ describe("treeMap", () => { expect(getByText("Std Packages Size")).not.toBeNull(); }); - it("should handle move event", () => { + it("should handle move event", async () => { const { getByText, container } = render( , ); @@ -68,8 +69,15 @@ describe("treeMap", () => { const rect = getByText("symtab.go"); - fireEvent.mouseEnter(svg!); - fireEvent.mouseMove(rect); + const user = userEvent.setup(); + + await user.pointer({ + coords: { + x: 1, + y: 1, + }, + }); + await user.hover(rect); const tooltip = document.querySelector(".tooltip"); expect(tooltip).not.toBeNull();