[ARVADOS-WORKBENCH2] updated: 1.1.4-59-g8916173

Git user git at public.curoverse.com
Fri Jun 15 08:40:39 EDT 2018


Summary of changes:
 src/store/project/project-reducer.test.ts | 78 +++++++++++++++++++++++++------
 src/store/project/project-reducer.ts      | 14 ++++++
 2 files changed, 78 insertions(+), 14 deletions(-)

       via  89161730d7d5e7d16a8fe2f5494db6560e718fa3 (commit)
      from  065f393316fad3472ab2afe526c7965be1fe392d (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 89161730d7d5e7d16a8fe2f5494db6560e718fa3
Author: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
Date:   Fri Jun 15 14:40:25 2018 +0200

    Create function to create tree item branch and tests for it
    
    Feature #13628
    
    Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski at contractors.roche.com>

diff --git a/src/store/project/project-reducer.test.ts b/src/store/project/project-reducer.test.ts
index 9c1ed3b..3e82883 100644
--- a/src/store/project/project-reducer.test.ts
+++ b/src/store/project/project-reducer.test.ts
@@ -2,8 +2,9 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import projectsReducer from "./project-reducer";
+import projectsReducer, { findTreeBranch } from "./project-reducer";
 import actions from "./project-action";
+import { TreeItem } from "../../components/tree/tree";
 
 describe('project-reducer', () => {
     it('should add new project to the list', () => {
@@ -33,20 +34,69 @@ describe('project-reducer', () => {
         };
 
         const projects = [project, project];
-        const state = projectsReducer(initialState, actions.PROJECTS_SUCCESS({projects, parentItemId: undefined}));
+        const state = projectsReducer(initialState, actions.PROJECTS_SUCCESS({ projects, parentItemId: undefined }));
         expect(state).toEqual([{
-                active: false,
-                open: false,
-                id: "test123",
-                items: [],
-                data: project
-            }, {
-                active: false,
-                open: false,
-                id: "test123",
-                items: [],
-                data: project
-            }
+            active: false,
+            open: false,
+            id: "test123",
+            items: [],
+            data: project
+        }, {
+            active: false,
+            open: false,
+            id: "test123",
+            items: [],
+            data: project
+        }
         ]);
     });
 });
+
+describe("findTreeBranch", () => {
+
+    const createTreeItem = (id: string, items?: Array<TreeItem<string>>): TreeItem<string> => ({
+        id,
+        items,
+        active: false,
+        data: "",
+        open: false,
+    });
+
+    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 = findTreeBranch(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(findTreeBranch(tree, "3")).toHaveLength(0);
+    });
+
+});
diff --git a/src/store/project/project-reducer.ts b/src/store/project/project-reducer.ts
index 887cf89..ac6d4b7 100644
--- a/src/store/project/project-reducer.ts
+++ b/src/store/project/project-reducer.ts
@@ -22,6 +22,20 @@ function findTreeItem<T>(tree: Array<TreeItem<T>>, itemId: string): TreeItem<T>
     return item;
 }
 
+export function findTreeBranch<T>(tree: Array<TreeItem<T>>, itemId: string): Array<TreeItem<T>> {
+    for(const item of tree){
+        if(item.id === itemId){
+            return [item];
+        } else {
+            const branch = findTreeBranch(item.items || [], itemId);
+            if(branch.length > 0){
+                return [item, ...branch];
+            }
+        }
+    }
+    return [];
+}
+
 function resetTreeActivity<T>(tree: Array<TreeItem<T>>) {
     for (const t of tree) {
         t.active = false;

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list