7371ed060bf79bded70edd01f3bd0d8ff18f1892
[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                 {IDTAGCOLORS: 'IDVALCOLORS3'});
86         });
87     });
88
89     it('creates new project on home project and then a subproject inside it', function() {
90         const createProject = function(name, parentName) {
91             cy.get('[data-cy=side-panel-button]').click();
92             cy.get('[data-cy=side-panel-new-project]').click();
93             cy.get('[data-cy=form-dialog]')
94                 .should('contain', 'New Project')
95                 .within(() => {
96                     cy.get('[data-cy=parent-field]').within(() => {
97                         cy.get('input').invoke('val').then((val) => {
98                             expect(val).to.include(parentName);
99                         });
100                     });
101                     cy.get('[data-cy=name-field]').within(() => {
102                         cy.get('input').type(name);
103                     });
104                 });
105             cy.get('[data-cy=form-submit-btn]').click();
106         }
107
108         cy.loginAs(activeUser);
109         cy.goToPath(`/projects/${activeUser.user.uuid}`);
110         cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
111         cy.get('[data-cy=breadcrumb-last]').should('not.exist');
112         // Create new project
113         const projName = `Test project (${Math.floor(999999 * Math.random())})`;
114         createProject(projName, 'Home project');
115         // Confirm that the user was taken to the newly created thing
116         cy.get('[data-cy=form-dialog]').should('not.exist');
117         cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
118         cy.get('[data-cy=breadcrumb-last]').should('contain', projName);
119         // Create a subproject
120         const subProjName = `Test project (${Math.floor(999999 * Math.random())})`;
121         createProject(subProjName, projName);
122         cy.get('[data-cy=form-dialog]').should('not.exist');
123         cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
124         cy.get('[data-cy=breadcrumb-last]').should('contain', subProjName);
125     });
126
127     it('navigates to the parent project after trashing the one being displayed', function() {
128         cy.createGroup(activeUser.token, {
129             name: `Test root project ${Math.floor(Math.random() * 999999)}`,
130             group_class: 'project',
131         }).as('testRootProject').then(function() {
132             cy.createGroup(activeUser.token, {
133                 name : `Test subproject ${Math.floor(Math.random() * 999999)}`,
134                 group_class: 'project',
135                 owner_uuid: this.testRootProject.uuid,
136             }).as('testSubProject');
137         });
138         cy.getAll('@testRootProject', '@testSubProject').then(function([testRootProject, testSubProject]) {
139             cy.loginAs(activeUser);
140
141             // Go to subproject and trash it.
142             cy.goToPath(`/projects/${testSubProject.uuid}`);
143             cy.get('[data-cy=side-panel-tree]').should('contain', testSubProject.name);
144             cy.get('[data-cy=breadcrumb-last]')
145                 .should('contain', testSubProject.name)
146                 .rightclick();
147             cy.get('[data-cy=context-menu]').contains('Move to trash').click();
148
149             // Confirm that the parent project should be displayed.
150             cy.get('[data-cy=breadcrumb-last]').should('contain', testRootProject.name);
151             cy.url().should('contain', `/projects/${testRootProject.uuid}`);
152             cy.get('[data-cy=side-panel-tree]').should('not.contain', testSubProject.name);
153
154             // Checks for bugfix #17637.
155             cy.get('[data-cy=not-found-content]').should('not.exist');
156             cy.get('[data-cy=not-found-page]').should('not.exist');
157         });
158     });
159
160     it('navigates to the root project after trashing the parent of the one being displayed', function() {
161         cy.createGroup(activeUser.token, {
162             name: `Test root project ${Math.floor(Math.random() * 999999)}`,
163             group_class: 'project',
164         }).as('testRootProject').then(function() {
165             cy.createGroup(activeUser.token, {
166                 name : `Test subproject ${Math.floor(Math.random() * 999999)}`,
167                 group_class: 'project',
168                 owner_uuid: this.testRootProject.uuid,
169             }).as('testSubProject').then(function() {
170                 cy.createGroup(activeUser.token, {
171                     name : `Test sub subproject ${Math.floor(Math.random() * 999999)}`,
172                     group_class: 'project',
173                     owner_uuid: this.testSubProject.uuid,
174                 }).as('testSubSubProject');
175             });
176         });
177         cy.getAll('@testRootProject', '@testSubProject', '@testSubSubProject').then(function([testRootProject, testSubProject, testSubSubProject]) {
178             cy.loginAs(activeUser);
179
180             // Go to innermost project and trash its parent.
181             cy.goToPath(`/projects/${testSubSubProject.uuid}`);
182             cy.get('[data-cy=side-panel-tree]').should('contain', testSubSubProject.name);
183             cy.get('[data-cy=breadcrumb-last]').should('contain', testSubSubProject.name);
184             cy.get('[data-cy=side-panel-tree]')
185                 .contains(testSubProject.name)
186                 .rightclick();
187             cy.get('[data-cy=context-menu]').contains('Move to trash').click();
188
189             // Confirm that the trashed project's parent should be displayed.
190             cy.get('[data-cy=breadcrumb-last]').should('contain', testRootProject.name);
191             cy.url().should('contain', `/projects/${testRootProject.uuid}`);
192             cy.get('[data-cy=side-panel-tree]').should('not.contain', testSubProject.name);
193             cy.get('[data-cy=side-panel-tree]').should('not.contain', testSubSubProject.name);
194
195             // Checks for bugfix #17637.
196             cy.get('[data-cy=not-found-content]').should('not.exist');
197             cy.get('[data-cy=not-found-page]').should('not.exist');
198         });
199     });
200
201     it('shows details panel when clicking on the info icon', () => {
202         cy.createGroup(activeUser.token, {
203             name: `Test root project ${Math.floor(Math.random() * 999999)}`,
204             group_class: 'project',
205         }).as('testRootProject').then(function(testRootProject) {
206             cy.loginAs(activeUser);
207
208             cy.get('[data-cy=side-panel-tree]').contains(testRootProject.name).click();
209
210             cy.get('[data-cy=additional-info-icon]').click();
211
212             cy.contains(testRootProject.uuid).should('exist');
213         });
214     });
215
216     it('clears search input when changing project', () => {
217         cy.createGroup(activeUser.token, {
218             name: `Test root project ${Math.floor(Math.random() * 999999)}`,
219             group_class: 'project',
220         }).as('testProject1').then((testProject1) => {
221             cy.shareWith(adminUser.token, activeUser.user.uuid, testProject1.uuid, 'can_write');
222         });
223
224         cy.getAll('@testProject1').then(function([testProject1]) {
225             cy.loginAs(activeUser);
226
227             cy.get('[data-cy=side-panel-tree]').contains(testProject1.name).click();
228
229             cy.get('[data-cy=search-input] input').type('test123');
230
231             cy.get('[data-cy=side-panel-tree]').contains('Projects').click();
232
233             cy.get('[data-cy=search-input] input').should('not.have.value', 'test123');
234         });
235     });
236
237     it('opens advanced popup for project with username', () => {
238         const projectName = `Test project ${Math.floor(Math.random() * 999999)}`;
239
240         cy.createGroup(adminUser.token, {
241             name: projectName,
242             group_class: 'project',
243         }).as('mainProject')
244
245         cy.getAll('@mainProject')
246             .then(function ([mainProject]) {
247                 cy.loginAs(adminUser);
248                 
249                 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
250
251                 cy.get('[data-cy=uuid]').eq(0).invoke('text').then(uuid => {
252                     cy.createLink(adminUser.token, {
253                         name: 'can_write',
254                         link_class: 'permission',
255                         head_uuid: mainProject.uuid,
256                         tail_uuid: uuid
257                     });
258
259                     cy.createLink(adminUser.token, {
260                         name: 'can_write',
261                         link_class: 'permission',
262                         head_uuid: mainProject.uuid,
263                         tail_uuid: activeUser.user.uuid
264                     });
265
266                     cy.get('[data-cy=side-panel-tree]').contains('Projects').click();
267
268                     cy.get('main').contains(projectName).rightclick();
269
270                     cy.get('[data-cy=context-menu]').contains('Advanced').click();
271
272                     cy.get('[role=tablist]').contains('METADATA').click();
273
274                     cy.get('td').contains(uuid).should('exist');
275
276                     cy.get('td').contains(activeUser.user.uuid).should('exist');
277                 });
278         });
279     });
280 });