1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { projectsReducer, getTreePath } from "./project-reducer";
6 import { projectActions } from "./project-action";
7 import { TreeItem, TreeItemStatus } from "~/components/tree/tree";
8 import { mockProjectResource } from "~/models/test-utils";
10 describe('project-reducer', () => {
12 it('should load projects', () => {
13 const initialState = undefined;
15 const projects = [mockProjectResource({ uuid: "1" }), mockProjectResource({ uuid: "2" })];
16 const state = projectsReducer(initialState, projectActions.PROJECTS_SUCCESS({ projects, parentItemId: undefined }));
17 expect(state).toEqual({
23 data: mockProjectResource({ uuid: "1" }),
24 status: TreeItemStatus.INITIAL
30 data: mockProjectResource({ uuid: "2" }),
31 status: TreeItemStatus.INITIAL
46 it('should remove activity on projects list', () => {
47 const initialState = {
49 data: mockProjectResource(),
53 status: TreeItemStatus.PENDING
56 creator: { opened: false, ownerUuid: "" },
57 updater: { opened: false, uuid: '' }
61 data: mockProjectResource(),
65 status: TreeItemStatus.PENDING
68 creator: { opened: false, ownerUuid: "" },
69 updater: { opened: false, uuid: '' }
72 const state = projectsReducer(initialState, projectActions.RESET_PROJECT_TREE_ACTIVITY(initialState.items[0].id));
73 expect(state).toEqual(project);
76 it('should toggle project tree item activity', () => {
77 const initialState = {
79 data: mockProjectResource(),
83 status: TreeItemStatus.PENDING
86 creator: { opened: false, ownerUuid: "" },
87 updater: { opened: false, uuid: '' }
91 data: mockProjectResource(),
95 status: TreeItemStatus.PENDING,
98 creator: { opened: false, ownerUuid: "" },
99 updater: { opened: false, uuid: '' }
102 const state = projectsReducer(initialState, projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(initialState.items[0].id));
103 expect(state).toEqual(project);
107 it('should close project tree item ', () => {
108 const initialState = {
110 data: mockProjectResource(),
114 status: TreeItemStatus.PENDING,
117 creator: { opened: false, ownerUuid: "" },
118 updater: { opened: false, uuid: '' }
122 data: mockProjectResource(),
126 status: TreeItemStatus.PENDING,
129 creator: { opened: false, ownerUuid: "" },
130 updater: { opened: false, uuid: '' }
134 const state = projectsReducer(initialState, projectActions.TOGGLE_PROJECT_TREE_ITEM_OPEN(initialState.items[0].id));
135 expect(state).toEqual(project);
139 describe("findTreeBranch", () => {
140 const createTreeItem = (id: string, items?: Array<TreeItem<string>>): TreeItem<string> => ({
146 status: TreeItemStatus.INITIAL
149 it("should return an array that matches path to the given item", () => {
150 const tree: Array<TreeItem<string>> = [
151 createTreeItem("1", [
152 createTreeItem("1.1", [
153 createTreeItem("1.1.1"),
154 createTreeItem("1.1.2")
157 createTreeItem("2", [
158 createTreeItem("2.1", [
159 createTreeItem("2.1.1"),
160 createTreeItem("2.1.2")
164 const branch = getTreePath(tree, "2.1.1");
165 expect(branch.map(item => item.id)).toEqual(["2", "2.1", "2.1.1"]);
168 it("should return empty array if item is not found", () => {
169 const tree: Array<TreeItem<string>> = [
170 createTreeItem("1", [
171 createTreeItem("1.1", [
172 createTreeItem("1.1.1"),
173 createTreeItem("1.1.2")
176 createTreeItem("2", [
177 createTreeItem("2.1", [
178 createTreeItem("2.1.1"),
179 createTreeItem("2.1.2")
183 expect(getTreePath(tree, "3")).toHaveLength(0);