diff --git a/tests/TreeView/TreeView.test.svelte b/tests/TreeView/TreeView.test.svelte index ee2776475b..fb89bb49fe 100644 --- a/tests/TreeView/TreeView.test.svelte +++ b/tests/TreeView/TreeView.test.svelte @@ -7,7 +7,7 @@ let treeview: TreeView; let activeId: TreeNodeId = ""; let selectedIds: TreeNodeId[] = []; - let expandedIds: TreeNodeId[] = [1]; + let expandedIds: TreeNodeId[] = []; let nodes: ComponentProps["nodes"] = [ { id: 0, text: "AI / Machine learning", icon: Analytics }, { @@ -81,3 +81,12 @@ + diff --git a/tests/TreeView/TreeView.test.ts b/tests/TreeView/TreeView.test.ts index b2a0a6a3f2..3f1210f753 100644 --- a/tests/TreeView/TreeView.test.ts +++ b/tests/TreeView/TreeView.test.ts @@ -17,6 +17,16 @@ describe("TreeView", () => { }); }; + const noExpandedItems = () => { + expect(screen.queryAllByRole("treeitem", { expanded: true })).toHaveLength( + 0, + ); + }; + + const getAllExpandedItems = () => { + return screen.getAllByRole("treeitem", { expanded: true }); + }; + it("can select a node", async () => { const consoleLog = vi.spyOn(console, "log"); @@ -37,4 +47,30 @@ describe("TreeView", () => { text: "AI / Machine learning", }); }); + + it("can expand all nodes", async () => { + render(TreeView); + + noExpandedItems(); + + const expandAllButton = screen.getByText("Expand all"); + await user.click(expandAllButton); + + expect(getAllExpandedItems()).toHaveLength(5); + }); + + it("can expand some nodes", async () => { + render(TreeView); + + noExpandedItems(); + + const expandSomeNodesButton = screen.getByText("Expand some nodes"); + await user.click(expandSomeNodesButton); + + expect(getAllExpandedItems()).toHaveLength(2); + + expect( + screen.getByText("IBM Analytics Engine").parentNode?.parentNode, + ).toHaveAttribute("aria-expanded", "true"); + }); });