left-side-panel-small-refactor
[arvados-workbench2.git] / src / store / project / project-reducer.test.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import projectsReducer from "./project-reducer";
6 import actions from "./project-action";
7
8 describe('project-reducer', () => {
9     it('should add new project to the list', () => {
10         const initialState = undefined;
11         const project = {
12             name: 'test',
13             href: 'href',
14             createdAt: '2018-01-01',
15             modifiedAt: '2018-01-01',
16             ownerUuid: 'owner-test123',
17             uuid: 'test123'
18         };
19
20         const state = projectsReducer(initialState, actions.CREATE_PROJECT(project));
21         expect(state).toEqual([project]);
22     });
23
24     it('should load projects', () => {
25         const initialState = undefined;
26         const project = {
27             name: 'test',
28             href: 'href',
29             createdAt: '2018-01-01',
30             modifiedAt: '2018-01-01',
31             ownerUuid: 'owner-test123',
32             uuid: 'test123'
33         };
34
35         const projects = [project, project];
36         const state = projectsReducer(initialState, actions.PROJECTS_SUCCESS({ projects, parentItemId: undefined }));
37         expect(state).toEqual([{
38             active: false,
39             open: false,
40             id: "test123",
41             items: [],
42             data: project,
43             status: 0
44         }, {
45             active: false,
46             open: false,
47             id: "test123",
48             items: [],
49             data: project,
50             status: 0
51         }
52         ]);
53     });
54
55     it('should remove activity on projects list', () => {
56         const initialState = [
57             {
58                 data: {
59                     name: 'test',
60                     href: 'href',
61                     createdAt: '2018-01-01',
62                     modifiedAt: '2018-01-01',
63                     ownerUuid: 'owner-test123',
64                     uuid: 'test123',
65                 },
66                 id: "1",
67                 open: true,
68                 active: true,
69                 status: 1
70             }
71         ];
72         const project = [
73             {
74                 data: {
75                     name: 'test',
76                     href: 'href',
77                     createdAt: '2018-01-01',
78                     modifiedAt: '2018-01-01',
79                     ownerUuid: 'owner-test123',
80                     uuid: 'test123',
81                 },
82                 id: "1",
83                 open: true,
84                 active: false,
85                 status: 1
86             }
87         ];
88
89         const state = projectsReducer(initialState, actions.RESET_PROJECT_TREE_ACTIVITY(initialState[0].id));
90         expect(state).toEqual(project);
91     });
92
93     it('should toggle project tree item activity', () => {
94         const initialState = [
95             {
96                 data: {
97                     name: 'test',
98                     href: 'href',
99                     createdAt: '2018-01-01',
100                     modifiedAt: '2018-01-01',
101                     ownerUuid: 'owner-test123',
102                     uuid: 'test123',
103                 },
104                 id: "1",
105                 open: true,
106                 active: false,
107                 status: 1
108             }
109         ];
110         const project = [
111             {
112                 data: {
113                     name: 'test',
114                     href: 'href',
115                     createdAt: '2018-01-01',
116                     modifiedAt: '2018-01-01',
117                     ownerUuid: 'owner-test123',
118                     uuid: 'test123',
119                 },
120                 id: "1",
121                 open: true,
122                 active: true,
123                 status: 1
124             }
125         ];
126
127         const state = projectsReducer(initialState, actions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(initialState[0].id));
128         expect(state).toEqual(project);
129     });
130
131
132     it('should close project tree item ', () => {
133         const initialState = [
134             {
135                 data: {
136                     name: 'test',
137                     href: 'href',
138                     createdAt: '2018-01-01',
139                     modifiedAt: '2018-01-01',
140                     ownerUuid: 'owner-test123',
141                     uuid: 'test123',
142                 },
143                 id: "1",
144                 open: true,
145                 active: false,
146                 status: 1,
147                 toggled: false,
148             }
149         ];
150         const project = [
151             {
152                 data: {
153                     name: 'test',
154                     href: 'href',
155                     createdAt: '2018-01-01',
156                     modifiedAt: '2018-01-01',
157                     ownerUuid: 'owner-test123',
158                     uuid: 'test123',
159                 },
160                 id: "1",
161                 open: false,
162                 active: false,
163                 status: 1,
164                 toggled: true
165             }
166         ];
167
168         const state = projectsReducer(initialState, actions.TOGGLE_PROJECT_TREE_ITEM_OPEN(initialState[0].id));
169         expect(state).toEqual(project);
170     });
171 });