7590cce4c7f7da9797d793fee5c6f040b330eba1
[arvados-workbench2.git] / cypress / integration / project.spec.js
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 describe('Project tests', function() {
6     let activeUser;
7     let adminUser;
8
9     before(function() {
10         // Only set up common users once. These aren't set up as aliases because
11         // aliases are cleaned up after every test. Also it doesn't make sense
12         // to set the same users on beforeEach() over and over again, so we
13         // separate a little from Cypress' 'Best Practices' here.
14         cy.getUser('admin', 'Admin', 'User', true, true)
15             .as('adminUser').then(function() {
16                 adminUser = this.adminUser;
17             }
18         );
19         cy.getUser('user', 'Active', 'User', false, true)
20             .as('activeUser').then(function() {
21                 activeUser = this.activeUser;
22             }
23         );
24     });
25
26     beforeEach(function() {
27         cy.clearCookies();
28         cy.clearLocalStorage();
29     });
30
31     it('creates a new project with multiple properties', function() {
32         const projName = `Test project (${Math.floor(999999 * Math.random())})`;
33         cy.loginAs(activeUser);
34         cy.get('[data-cy=side-panel-button]').click();
35         cy.get('[data-cy=side-panel-new-project]').click();
36         cy.get('[data-cy=form-dialog]')
37             .should('contain', 'New Project')
38             .within(() => {
39                 cy.get('[data-cy=name-field]').within(() => {
40                     cy.get('input').type(projName);
41                 });
42
43             });
44         // Key: Color (IDTAGCOLORS) - Value: Magenta (IDVALCOLORS3)
45         cy.get('[data-cy=form-dialog]').should('not.contain', 'Color: Magenta');
46         cy.get('[data-cy=resource-properties-form]').within(() => {
47             cy.get('[data-cy=property-field-key]').within(() => {
48                 cy.get('input').type('Color');
49             });
50             cy.get('[data-cy=property-field-value]').within(() => {
51                 cy.get('input').type('Magenta');
52             });
53             cy.root().submit();
54             cy.get('[data-cy=property-field-value]').within(() => {
55                 cy.get('input').type('Pink');
56             });
57             cy.root().submit();
58             cy.get('[data-cy=property-field-value]').within(() => {
59                 cy.get('input').type('Yellow');
60             });
61             cy.root().submit();
62         });
63         // Confirm proper vocabulary labels are displayed on the UI.
64         cy.get('[data-cy=form-dialog]').should('contain', 'Color: Magenta');
65         cy.get('[data-cy=form-dialog]').should('contain', 'Color: Pink');
66         cy.get('[data-cy=form-dialog]').should('contain', 'Color: Yellow');
67
68         cy.get('[data-cy=resource-properties-form]').within(() => {
69             cy.get('[data-cy=property-field-key]').within(() => {
70                 cy.get('input').focus();
71             });
72             cy.get('[data-cy=property-field-key]').should('not.contain', 'Color');
73         });
74
75         // Create project and confirm the properties' real values.
76         cy.get('[data-cy=form-submit-btn]').click();
77         cy.get('[data-cy=breadcrumb-last]').should('contain', projName);
78         cy.doRequest('GET', '/arvados/v1/groups', null, {
79             filters: `[["name", "=", "${projName}"], ["group_class", "=", "project"]]`,
80         })
81         .its('body.items').as('projects')
82         .then(function() {
83             expect(this.projects).to.have.lengthOf(1);
84             expect(this.projects[0].properties).to.deep.equal(
85                 // Pink is not in the test vocab
86                 {IDTAGCOLORS: ['IDVALCOLORS1', 'IDVALCOLORS3', 'Pink']});
87         });
88     });
89
90     it('creates new project on home project and then a subproject inside it', function() {
91         const createProject = function(name, parentName) {
92             cy.get('[data-cy=side-panel-button]').click();
93             cy.get('[data-cy=side-panel-new-project]').click();
94             cy.get('[data-cy=form-dialog]')
95                 .should('contain', 'New Project')
96                 .within(() => {
97                     cy.get('[data-cy=parent-field]').within(() => {
98                         cy.get('input').invoke('val').then((val) => {
99                             expect(val).to.include(parentName);
100                         });
101                     });
102                     cy.get('[data-cy=name-field]').within(() => {
103                         cy.get('input').type(name);
104                     });
105                 });
106             cy.get('[data-cy=form-submit-btn]').click();
107         }
108
109         cy.loginAs(activeUser);
110         cy.goToPath(`/projects/${activeUser.user.uuid}`);
111         cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
112         cy.get('[data-cy=breadcrumb-last]').should('not.exist');
113         // Create new project
114         const projName = `Test project (${Math.floor(999999 * Math.random())})`;
115         createProject(projName, 'Home project');
116         // Confirm that the user was taken to the newly created thing
117         cy.get('[data-cy=form-dialog]').should('not.exist');
118         cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
119         cy.get('[data-cy=breadcrumb-last]').should('contain', projName);
120         // Create a subproject
121         const subProjName = `Test project (${Math.floor(999999 * Math.random())})`;
122         createProject(subProjName, projName);
123         cy.get('[data-cy=form-dialog]').should('not.exist');
124         cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
125         cy.get('[data-cy=breadcrumb-last]').should('contain', subProjName);
126     });
127
128     it('navigates to the parent project after trashing the one being displayed', function() {
129         cy.createGroup(activeUser.token, {
130             name: `Test root project ${Math.floor(Math.random() * 999999)}`,
131             group_class: 'project',
132         }).as('testRootProject').then(function() {
133             cy.createGroup(activeUser.token, {
134                 name : `Test subproject ${Math.floor(Math.random() * 999999)}`,
135                 group_class: 'project',
136                 owner_uuid: this.testRootProject.uuid,
137             }).as('testSubProject');
138         });
139         cy.getAll('@testRootProject', '@testSubProject').then(function([testRootProject, testSubProject]) {
140             cy.loginAs(activeUser);
141
142             // Go to subproject and trash it.
143             cy.goToPath(`/projects/${testSubProject.uuid}`);
144             cy.get('[data-cy=side-panel-tree]').should('contain', testSubProject.name);
145             cy.get('[data-cy=breadcrumb-last]')
146                 .should('contain', testSubProject.name)
147                 .rightclick();
148             cy.get('[data-cy=context-menu]').contains('Move to trash').click();
149
150             // Confirm that the parent project should be displayed.
151             cy.get('[data-cy=breadcrumb-last]').should('contain', testRootProject.name);
152             cy.url().should('contain', `/projects/${testRootProject.uuid}`);
153             cy.get('[data-cy=side-panel-tree]').should('not.contain', testSubProject.name);
154
155             // Checks for bugfix #17637.
156             cy.get('[data-cy=not-found-content]').should('not.exist');
157             cy.get('[data-cy=not-found-page]').should('not.exist');
158         });
159     });
160
161     it('navigates to the root project after trashing the parent of the one being displayed', function() {
162         cy.createGroup(activeUser.token, {
163             name: `Test root project ${Math.floor(Math.random() * 999999)}`,
164             group_class: 'project',
165         }).as('testRootProject').then(function() {
166             cy.createGroup(activeUser.token, {
167                 name : `Test subproject ${Math.floor(Math.random() * 999999)}`,
168                 group_class: 'project',
169                 owner_uuid: this.testRootProject.uuid,
170             }).as('testSubProject').then(function() {
171                 cy.createGroup(activeUser.token, {
172                     name : `Test sub subproject ${Math.floor(Math.random() * 999999)}`,
173                     group_class: 'project',
174                     owner_uuid: this.testSubProject.uuid,
175                 }).as('testSubSubProject');
176             });
177         });
178         cy.getAll('@testRootProject', '@testSubProject', '@testSubSubProject').then(function([testRootProject, testSubProject, testSubSubProject]) {
179             cy.loginAs(activeUser);
180
181             // Go to innermost project and trash its parent.
182             cy.goToPath(`/projects/${testSubSubProject.uuid}`);
183             cy.get('[data-cy=side-panel-tree]').should('contain', testSubSubProject.name);
184             cy.get('[data-cy=breadcrumb-last]').should('contain', testSubSubProject.name);
185             cy.get('[data-cy=side-panel-tree]')
186                 .contains(testSubProject.name)
187                 .rightclick();
188             cy.get('[data-cy=context-menu]').contains('Move to trash').click();
189
190             // Confirm that the trashed project's parent should be displayed.
191             cy.get('[data-cy=breadcrumb-last]').should('contain', testRootProject.name);
192             cy.url().should('contain', `/projects/${testRootProject.uuid}`);
193             cy.get('[data-cy=side-panel-tree]').should('not.contain', testSubProject.name);
194             cy.get('[data-cy=side-panel-tree]').should('not.contain', testSubSubProject.name);
195
196             // Checks for bugfix #17637.
197             cy.get('[data-cy=not-found-content]').should('not.exist');
198             cy.get('[data-cy=not-found-page]').should('not.exist');
199         });
200     });
201
202     it('shows details panel when clicking on the info icon', () => {
203         cy.createGroup(activeUser.token, {
204             name: `Test root project ${Math.floor(Math.random() * 999999)}`,
205             group_class: 'project',
206         }).as('testRootProject').then(function(testRootProject) {
207             cy.loginAs(activeUser);
208
209             cy.get('[data-cy=side-panel-tree]').contains(testRootProject.name).click();
210
211             cy.get('[data-cy=additional-info-icon]').click();
212
213             cy.contains(testRootProject.uuid).should('exist');
214         });
215     });
216
217     it('clears search input when changing project', () => {
218         cy.createGroup(activeUser.token, {
219             name: `Test root project ${Math.floor(Math.random() * 999999)}`,
220             group_class: 'project',
221         }).as('testProject1').then((testProject1) => {
222             cy.shareWith(adminUser.token, activeUser.user.uuid, testProject1.uuid, 'can_write');
223         });
224
225         cy.getAll('@testProject1').then(function([testProject1]) {
226             cy.loginAs(activeUser);
227
228             cy.get('[data-cy=side-panel-tree]').contains(testProject1.name).click();
229
230             cy.get('[data-cy=search-input] input').type('test123');
231
232             cy.get('[data-cy=side-panel-tree]').contains('Projects').click();
233
234             cy.get('[data-cy=search-input] input').should('not.have.value', 'test123');
235         });
236     });
237
238     it('opens advanced popup for project with username', () => {
239         const projectName = `Test project ${Math.floor(Math.random() * 999999)}`;
240
241         cy.createGroup(adminUser.token, {
242             name: projectName,
243             group_class: 'project',
244         }).as('mainProject')
245
246         cy.getAll('@mainProject')
247             .then(function ([mainProject]) {
248                 cy.loginAs(adminUser);
249
250                 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
251
252                 cy.get('[data-cy=uuid]').eq(0).invoke('text').then(uuid => {
253                     cy.createLink(adminUser.token, {
254                         name: 'can_write',
255                         link_class: 'permission',
256                         head_uuid: mainProject.uuid,
257                         tail_uuid: uuid
258                     });
259
260                     cy.createLink(adminUser.token, {
261                         name: 'can_write',
262                         link_class: 'permission',
263                         head_uuid: mainProject.uuid,
264                         tail_uuid: activeUser.user.uuid
265                     });
266
267                     cy.get('[data-cy=side-panel-tree]').contains('Projects').click();
268
269                     cy.get('main').contains(projectName).rightclick();
270
271                     cy.get('[data-cy=context-menu]').contains('Advanced').click();
272
273                     cy.get('[role=tablist]').contains('METADATA').click();
274
275                     cy.get('td').contains(uuid).should('exist');
276
277                     cy.get('td').contains(activeUser.user.uuid).should('exist');
278                 });
279         });
280     });
281 });