X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/89161730d7d5e7d16a8fe2f5494db6560e718fa3..24ddc06cb04b124d337e91c190230bfad83e490b:/src/store/project/project-reducer.test.ts diff --git a/src/store/project/project-reducer.test.ts b/src/store/project/project-reducer.test.ts index 3e828830..0fc28960 100644 --- a/src/store/project/project-reducer.test.ts +++ b/src/store/project/project-reducer.test.ts @@ -2,64 +2,138 @@ // // SPDX-License-Identifier: AGPL-3.0 -import projectsReducer, { findTreeBranch } from "./project-reducer"; -import actions from "./project-action"; -import { TreeItem } from "../../components/tree/tree"; +import { projectsReducer, getTreePath } from "./project-reducer"; +import { projectActions } from "./project-action"; +import { TreeItem, TreeItemStatus } from "../../components/tree/tree"; +import { mockProjectResource } from "../../models/test-utils"; describe('project-reducer', () => { - it('should add new project to the list', () => { + + it('should load projects', () => { const initialState = undefined; + + const projects = [mockProjectResource({ uuid: "1" }), mockProjectResource({ uuid: "2" })]; + const state = projectsReducer(initialState, projectActions.PROJECTS_SUCCESS({ projects, parentItemId: undefined })); + expect(state).toEqual({ + items: [{ + active: false, + open: false, + id: "1", + items: [], + data: mockProjectResource({ uuid: "1" }), + status: 0 + }, { + active: false, + open: false, + id: "2", + items: [], + data: mockProjectResource({ uuid: "2" }), + status: TreeItemStatus.INITIAL + } + ], + currentItemId: "", + creator: { + opened: false, + ownerUuid: "", + pending: false + } + }); + }); + + it('should remove activity on projects list', () => { + const initialState = { + items: [{ + data: mockProjectResource(), + id: "1", + open: true, + active: true, + status: TreeItemStatus.PENDING + }], + currentItemId: "1", + creator: { opened: false, pending: false, ownerUuid: "" }, + }; const project = { - name: 'test', - href: 'href', - createdAt: '2018-01-01', - modifiedAt: '2018-01-01', - ownerUuid: 'owner-test123', - uuid: 'test123' + items: [{ + data: mockProjectResource(), + id: "1", + open: true, + active: false, + status: TreeItemStatus.PENDING + }], + currentItemId: "", + creator: { opened: false, pending: false, ownerUuid: "" }, }; - const state = projectsReducer(initialState, actions.CREATE_PROJECT(project)); - expect(state).toEqual([project]); + const state = projectsReducer(initialState, projectActions.RESET_PROJECT_TREE_ACTIVITY(initialState.items[0].id)); + expect(state).toEqual(project); }); - it('should load projects', () => { - const initialState = undefined; + it('should toggle project tree item activity', () => { + const initialState = { + items: [{ + data: mockProjectResource(), + id: "1", + open: true, + active: false, + status: TreeItemStatus.PENDING + }], + currentItemId: "1", + creator: { opened: false, pending: false, ownerUuid: "" } + }; const project = { - name: 'test', - href: 'href', - createdAt: '2018-01-01', - modifiedAt: '2018-01-01', - ownerUuid: 'owner-test123', - uuid: 'test123' + items: [{ + data: mockProjectResource(), + id: "1", + open: true, + active: true, + status: TreeItemStatus.PENDING, + }], + currentItemId: "1", + creator: { opened: false, pending: false, ownerUuid: "" }, }; - const projects = [project, project]; - 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 - } - ]); + const state = projectsReducer(initialState, projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(initialState.items[0].id)); + expect(state).toEqual(project); + }); + + + it('should close project tree item ', () => { + const initialState = { + items: [{ + data: mockProjectResource(), + id: "1", + open: true, + active: false, + status: TreeItemStatus.PENDING, + }], + currentItemId: "1", + creator: { opened: false, pending: false, ownerUuid: "" } + }; + const project = { + items: [{ + data: mockProjectResource(), + id: "1", + open: false, + active: false, + status: TreeItemStatus.PENDING, + }], + currentItemId: "1", + creator: { opened: false, pending: false, ownerUuid: "" }, + }; + + const state = projectsReducer(initialState, projectActions.TOGGLE_PROJECT_TREE_ITEM_OPEN(initialState.items[0].id)); + expect(state).toEqual(project); }); }); describe("findTreeBranch", () => { - const createTreeItem = (id: string, items?: Array>): TreeItem => ({ id, items, active: false, data: "", open: false, + status: TreeItemStatus.INITIAL }); it("should return an array that matches path to the given item", () => { @@ -77,7 +151,7 @@ describe("findTreeBranch", () => { ]) ]) ]; - const branch = findTreeBranch(tree, "2.1.1"); + const branch = getTreePath(tree, "2.1.1"); expect(branch.map(item => item.id)).toEqual(["2", "2.1", "2.1.1"]); }); @@ -96,7 +170,7 @@ describe("findTreeBranch", () => { ]) ]) ]; - expect(findTreeBranch(tree, "3")).toHaveLength(0); + expect(getTreePath(tree, "3")).toHaveLength(0); }); });