+
+describe("findTreeBranch", () => {
+ const createTreeItem = (id: string, items?: Array<TreeItem<string>>): TreeItem<string> => ({
+ id,
+ items,
+ active: false,
+ data: "",
+ open: false,
+ status: TreeItemStatus.INITIAL
+ });
+
+ it("should return an array that matches path to the given item", () => {
+ const tree: Array<TreeItem<string>> = [
+ createTreeItem("1", [
+ createTreeItem("1.1", [
+ createTreeItem("1.1.1"),
+ createTreeItem("1.1.2")
+ ])
+ ]),
+ createTreeItem("2", [
+ createTreeItem("2.1", [
+ createTreeItem("2.1.1"),
+ createTreeItem("2.1.2")
+ ])
+ ])
+ ];
+ const branch = getTreePath(tree, "2.1.1");
+ expect(branch.map(item => item.id)).toEqual(["2", "2.1", "2.1.1"]);
+ });
+
+ it("should return empty array if item is not found", () => {
+ const tree: Array<TreeItem<string>> = [
+ createTreeItem("1", [
+ createTreeItem("1.1", [
+ createTreeItem("1.1.1"),
+ createTreeItem("1.1.2")
+ ])
+ ]),
+ createTreeItem("2", [
+ createTreeItem("2.1", [
+ createTreeItem("2.1.1"),
+ createTreeItem("2.1.2")
+ ])
+ ])
+ ];
+ expect(getTreePath(tree, "3")).toHaveLength(0);
+ });
+
+});