learn and share notes on atproto (wip) 馃
malfestio.stormlightlabs.org/
readability
solid
axum
atproto
srs
1import { cleanup, fireEvent, render, screen } from "@solidjs/testing-library";
2import { afterEach, describe, expect, it, vi } from "vitest";
3import { type TreeNode, TreeView } from "../TreeView";
4
5const sampleNodes: TreeNode[] = [{
6 id: "1",
7 label: "Root",
8 children: [{ id: "1-1", label: "Child 1" }, { id: "1-2", label: "Child 2" }],
9}, { id: "2", label: "Sibling" }];
10
11describe("TreeView", () => {
12 afterEach(cleanup);
13
14 it("renders nodes", () => {
15 render(() => <TreeView nodes={sampleNodes} />);
16 expect(screen.getByRole("tree")).toBeInTheDocument();
17 expect(screen.getByText("Root")).toBeInTheDocument();
18 expect(screen.getByText("Sibling")).toBeInTheDocument();
19 });
20
21 it("expands children on click", () => {
22 render(() => <TreeView nodes={sampleNodes} />);
23 expect(screen.queryByText("Child 1")).not.toBeInTheDocument();
24 fireEvent.click(screen.getByText("Root"));
25 expect(screen.getByText("Child 1")).toBeInTheDocument();
26 expect(screen.getByText("Child 2")).toBeInTheDocument();
27 });
28
29 it("calls onSelect when node clicked", () => {
30 const handleSelect = vi.fn();
31 render(() => <TreeView nodes={sampleNodes} onSelect={handleSelect} />);
32 fireEvent.click(screen.getByText("Sibling"));
33 expect(handleSelect).toHaveBeenCalledWith(expect.objectContaining({ id: "2" }));
34 });
35});