mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-14 18:01:06 +00:00
test(tree-view): add more test cases
This commit is contained in:
parent
d7158ced73
commit
becb1503d8
2 changed files with 46 additions and 1 deletions
|
@ -7,7 +7,7 @@
|
||||||
let treeview: TreeView;
|
let treeview: TreeView;
|
||||||
let activeId: TreeNodeId = "";
|
let activeId: TreeNodeId = "";
|
||||||
let selectedIds: TreeNodeId[] = [];
|
let selectedIds: TreeNodeId[] = [];
|
||||||
let expandedIds: TreeNodeId[] = [1];
|
let expandedIds: TreeNodeId[] = [];
|
||||||
let nodes: ComponentProps<TreeView>["nodes"] = [
|
let nodes: ComponentProps<TreeView>["nodes"] = [
|
||||||
{ id: 0, text: "AI / Machine learning", icon: Analytics },
|
{ id: 0, text: "AI / Machine learning", icon: Analytics },
|
||||||
{
|
{
|
||||||
|
@ -81,3 +81,12 @@
|
||||||
</TreeView>
|
</TreeView>
|
||||||
|
|
||||||
<Button on:click={treeview.expandAll}>Expand all</Button>
|
<Button on:click={treeview.expandAll}>Expand all</Button>
|
||||||
|
<Button
|
||||||
|
on:click={() => {
|
||||||
|
treeview.expandNodes((node) => {
|
||||||
|
return /^IBM/.test(node.text);
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Expand some nodes
|
||||||
|
</Button>
|
||||||
|
|
|
@ -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 () => {
|
it("can select a node", async () => {
|
||||||
const consoleLog = vi.spyOn(console, "log");
|
const consoleLog = vi.spyOn(console, "log");
|
||||||
|
|
||||||
|
@ -37,4 +47,30 @@ describe("TreeView", () => {
|
||||||
text: "AI / Machine learning",
|
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");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue