From d9600e521dc9c719bc8bba7d0de45d554dd27a04 Mon Sep 17 00:00:00 2001 From: Katsiaryna Pustakhod Date: Wed, 5 Jul 2023 14:31:19 +0200 Subject: [PATCH] Add test. --- src/__tests__/ControlledTree.test.tsx | 43 +++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/__tests__/ControlledTree.test.tsx b/src/__tests__/ControlledTree.test.tsx index e6975cde..0e085a78 100644 --- a/src/__tests__/ControlledTree.test.tsx +++ b/src/__tests__/ControlledTree.test.tsx @@ -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( + + ); + + getNodes().forEach(node => { + expect(node).toHaveAttribute("aria-checked", "true"); + }); + + rerender(); + expect(getNodes()[0]).toHaveAttribute("aria-checked", "mixed"); + expect(getNodes()[1]).toHaveAttribute("aria-checked", "mixed"); + expect(getNodes()[4]).toHaveAttribute("aria-checked", "true"); + + rerender(); + expect(getNodes()[0]).toHaveAttribute("aria-checked", "false"); + expect(getNodes()[1]).toHaveAttribute("aria-checked", "false"); + }); }); describe("Data with ids", () => {