Skip to content

Commit

Permalink
Add test.
Browse files Browse the repository at this point in the history
  • Loading branch information
kpustakhod committed Jul 5, 2023
1 parent e36bfe2 commit d9600e5
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/__tests__/ControlledTree.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,49 @@ describe("Data without ids", () => {
expect(newNodes[4]).toHaveAttribute("aria-checked", "false");
expect(newNodes[5]).toHaveAttribute("aria-checked", "false");
});

test("SelectedIds should propagate upward when deselection happens via selectedIds", () => {
const data = flattenTree({
name: "",
children: [
{
name: "Drinks",
children: [
{
name: "Coffee",
children: [
{
name: "Arabica",
children: [
{ name: "Black", children: [{ name: "Espresso" }] },
],
},
{ name: "Robusta" },
],
},
],
},
],
});
const getNodes = () => container.querySelectorAll('[role="treeitem"]');

const { rerender, container } = render(
<MultiSelectCheckboxControlled selectedIds={[1]} data={data} defaultExpandedIds={[1,2,3]} />
);

getNodes().forEach(node => {
expect(node).toHaveAttribute("aria-checked", "true");
});

rerender(<MultiSelectCheckboxControlled selectedIds={[6]} data={data} defaultExpandedIds={[1,2,3]} />);
expect(getNodes()[0]).toHaveAttribute("aria-checked", "mixed");
expect(getNodes()[1]).toHaveAttribute("aria-checked", "mixed");
expect(getNodes()[4]).toHaveAttribute("aria-checked", "true");

rerender(<MultiSelectCheckboxControlled selectedIds={[]} data={data} defaultExpandedIds={[1,2,3]} />);
expect(getNodes()[0]).toHaveAttribute("aria-checked", "false");
expect(getNodes()[1]).toHaveAttribute("aria-checked", "false");
});
});

describe("Data with ids", () => {
Expand Down

0 comments on commit d9600e5

Please sign in to comment.