19691: Adds tests.
[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: ['IDVALCOLORS3', 'Pink', 'IDVALCOLORS1']});
87         });
88
89         // Open project edit via breadcrumbs
90         cy.get('[data-cy=breadcrumbs]').contains(projName).rightclick();
91         cy.get('[data-cy=context-menu]').contains('Edit').click();
92         cy.get('[data-cy=form-dialog]').within(() => {
93             cy.get('[data-cy=resource-properties-list]').within(() => {
94                 cy.get('div[role=button]').contains('Color: Magenta');
95                 cy.get('div[role=button]').contains('Color: Pink');
96                 cy.get('div[role=button]').contains('Color: Yellow');
97             });
98         });
99         // Add another property
100         cy.get('[data-cy=resource-properties-form]').within(() => {
101             cy.get('[data-cy=property-field-key]').within(() => {
102                 cy.get('input').type('Animal');
103             });
104             cy.get('[data-cy=property-field-value]').within(() => {
105                 cy.get('input').type('Dog');
106             });
107             cy.root().submit();
108         });
109         cy.get('[data-cy=form-submit-btn]').click();
110         // Reopen edit via breadcrumbs and verify properties
111         cy.get('[data-cy=breadcrumbs]').contains(projName).rightclick();
112         cy.get('[data-cy=context-menu]').contains('Edit').click();
113         cy.get('[data-cy=form-dialog]').within(() => {
114             cy.get('[data-cy=resource-properties-list]').within(() => {
115                 cy.get('div[role=button]').contains('Color: Magenta');
116                 cy.get('div[role=button]').contains('Color: Pink');
117                 cy.get('div[role=button]').contains('Color: Yellow');
118                 cy.get('div[role=button]').contains('Animal: Dog');
119             });
120         });
121     });
122
123     it('creates new project on home project and then a subproject inside it', function() {
124         const createProject = function(name, parentName) {
125             cy.get('[data-cy=side-panel-button]').click();
126             cy.get('[data-cy=side-panel-new-project]').click();
127             cy.get('[data-cy=form-dialog]')
128                 .should('contain', 'New Project')
129                 .within(() => {
130                     cy.get('[data-cy=parent-field]').within(() => {
131                         cy.get('input').invoke('val').then((val) => {
132                             expect(val).to.include(parentName);
133                         });
134                     });
135                     cy.get('[data-cy=name-field]').within(() => {
136                         cy.get('input').type(name);
137                     });
138                 });
139             cy.get('[data-cy=form-submit-btn]').click();
140         }
141
142         cy.loginAs(activeUser);
143         cy.goToPath(`/projects/${activeUser.user.uuid}`);
144         cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
145         cy.get('[data-cy=breadcrumb-last]').should('not.exist');
146         // Create new project
147         const projName = `Test project (${Math.floor(999999 * Math.random())})`;
148         createProject(projName, 'Home project');
149         // Confirm that the user was taken to the newly created thing
150         cy.get('[data-cy=form-dialog]').should('not.exist');
151         cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
152         cy.get('[data-cy=breadcrumb-last]').should('contain', projName);
153         // Create a subproject
154         const subProjName = `Test project (${Math.floor(999999 * Math.random())})`;
155         createProject(subProjName, projName);
156         cy.get('[data-cy=form-dialog]').should('not.exist');
157         cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
158         cy.get('[data-cy=breadcrumb-last]').should('contain', subProjName);
159     });
160
161     it('attempts to use a preexisting name creating a project', function() {
162         const name = `Test project ${Math.floor(Math.random() * 999999)}`;
163         cy.createGroup(activeUser.token, {
164             name: name,
165             group_class: 'project',
166         });
167         cy.loginAs(activeUser);
168         cy.goToPath(`/projects/${activeUser.user.uuid}`);
169
170         // Attempt to create new collection with a duplicate name
171         cy.get('[data-cy=side-panel-button]').click();
172         cy.get('[data-cy=side-panel-new-project]').click();
173         cy.get('[data-cy=form-dialog]')
174             .should('contain', 'New Project')
175             .within(() => {
176                 cy.get('[data-cy=name-field]').within(() => {
177                     cy.get('input').type(name);
178                 });
179                 cy.get('[data-cy=form-submit-btn]').click();
180             });
181         // Error message should display, allowing editing the name
182         cy.get('[data-cy=form-dialog]').should('exist')
183             .and('contain', 'Project with the same name already exists')
184             .within(() => {
185                 cy.get('[data-cy=name-field]').within(() => {
186                     cy.get('input').type(' renamed');
187                 });
188                 cy.get('[data-cy=form-submit-btn]').click();
189             });
190         cy.get('[data-cy=form-dialog]').should('not.exist');
191     });
192
193     it('navigates to the parent project after trashing the one being displayed', function() {
194         cy.createGroup(activeUser.token, {
195             name: `Test root project ${Math.floor(Math.random() * 999999)}`,
196             group_class: 'project',
197         }).as('testRootProject').then(function() {
198             cy.createGroup(activeUser.token, {
199                 name : `Test subproject ${Math.floor(Math.random() * 999999)}`,
200                 group_class: 'project',
201                 owner_uuid: this.testRootProject.uuid,
202             }).as('testSubProject');
203         });
204         cy.getAll('@testRootProject', '@testSubProject').then(function([testRootProject, testSubProject]) {
205             cy.loginAs(activeUser);
206
207             // Go to subproject and trash it.
208             cy.goToPath(`/projects/${testSubProject.uuid}`);
209             cy.get('[data-cy=side-panel-tree]').should('contain', testSubProject.name);
210             cy.get('[data-cy=breadcrumb-last]')
211                 .should('contain', testSubProject.name)
212                 .rightclick();
213             cy.get('[data-cy=context-menu]').contains('Move to trash').click();
214
215             // Confirm that the parent project should be displayed.
216             cy.get('[data-cy=breadcrumb-last]').should('contain', testRootProject.name);
217             cy.url().should('contain', `/projects/${testRootProject.uuid}`);
218             cy.get('[data-cy=side-panel-tree]').should('not.contain', testSubProject.name);
219
220             // Checks for bugfix #17637.
221             cy.get('[data-cy=not-found-content]').should('not.exist');
222             cy.get('[data-cy=not-found-page]').should('not.exist');
223         });
224     });
225
226     it('navigates to the root project after trashing the parent of the one being displayed', function() {
227         cy.createGroup(activeUser.token, {
228             name: `Test root project ${Math.floor(Math.random() * 999999)}`,
229             group_class: 'project',
230         }).as('testRootProject').then(function() {
231             cy.createGroup(activeUser.token, {
232                 name : `Test subproject ${Math.floor(Math.random() * 999999)}`,
233                 group_class: 'project',
234                 owner_uuid: this.testRootProject.uuid,
235             }).as('testSubProject').then(function() {
236                 cy.createGroup(activeUser.token, {
237                     name : `Test sub subproject ${Math.floor(Math.random() * 999999)}`,
238                     group_class: 'project',
239                     owner_uuid: this.testSubProject.uuid,
240                 }).as('testSubSubProject');
241             });
242         });
243         cy.getAll('@testRootProject', '@testSubProject', '@testSubSubProject').then(function([testRootProject, testSubProject, testSubSubProject]) {
244             cy.loginAs(activeUser);
245
246             // Go to innermost project and trash its parent.
247             cy.goToPath(`/projects/${testSubSubProject.uuid}`);
248             cy.get('[data-cy=side-panel-tree]').should('contain', testSubSubProject.name);
249             cy.get('[data-cy=breadcrumb-last]').should('contain', testSubSubProject.name);
250             cy.get('[data-cy=side-panel-tree]')
251                 .contains(testSubProject.name)
252                 .rightclick();
253             cy.get('[data-cy=context-menu]').contains('Move to trash').click();
254
255             // Confirm that the trashed project's parent should be displayed.
256             cy.get('[data-cy=breadcrumb-last]').should('contain', testRootProject.name);
257             cy.url().should('contain', `/projects/${testRootProject.uuid}`);
258             cy.get('[data-cy=side-panel-tree]').should('not.contain', testSubProject.name);
259             cy.get('[data-cy=side-panel-tree]').should('not.contain', testSubSubProject.name);
260
261             // Checks for bugfix #17637.
262             cy.get('[data-cy=not-found-content]').should('not.exist');
263             cy.get('[data-cy=not-found-page]').should('not.exist');
264         });
265     });
266
267     it('shows details panel when clicking on the info icon', () => {
268         cy.createGroup(activeUser.token, {
269             name: `Test root project ${Math.floor(Math.random() * 999999)}`,
270             group_class: 'project',
271         }).as('testRootProject').then(function(testRootProject) {
272             cy.loginAs(activeUser);
273
274             cy.get('[data-cy=side-panel-tree]').contains(testRootProject.name).click();
275
276             cy.get('[data-cy=additional-info-icon]').click();
277
278             cy.contains(testRootProject.uuid).should('exist');
279         });
280     });
281
282     it('clears search input when changing project', () => {
283         cy.createGroup(activeUser.token, {
284             name: `Test root project ${Math.floor(Math.random() * 999999)}`,
285             group_class: 'project',
286         }).as('testProject1').then((testProject1) => {
287             cy.shareWith(adminUser.token, activeUser.user.uuid, testProject1.uuid, 'can_write');
288         });
289
290         cy.getAll('@testProject1').then(function([testProject1]) {
291             cy.loginAs(activeUser);
292
293             cy.get('[data-cy=side-panel-tree]').contains(testProject1.name).click();
294
295             cy.get('[data-cy=search-input] input').type('test123');
296
297             cy.get('[data-cy=side-panel-tree]').contains('Projects').click();
298
299             cy.get('[data-cy=search-input] input').should('not.have.value', 'test123');
300         });
301     });
302
303     it('opens advanced popup for project with username', () => {
304         const projectName = `Test project ${Math.floor(Math.random() * 999999)}`;
305
306         cy.createGroup(adminUser.token, {
307             name: projectName,
308             group_class: 'project',
309         }).as('mainProject')
310
311         cy.getAll('@mainProject')
312             .then(function ([mainProject]) {
313                 cy.loginAs(adminUser);
314
315                 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
316
317                 cy.get('[data-cy=uuid]').eq(0).invoke('text').then(uuid => {
318                     cy.createLink(adminUser.token, {
319                         name: 'can_write',
320                         link_class: 'permission',
321                         head_uuid: mainProject.uuid,
322                         tail_uuid: uuid
323                     });
324
325                     cy.createLink(adminUser.token, {
326                         name: 'can_write',
327                         link_class: 'permission',
328                         head_uuid: mainProject.uuid,
329                         tail_uuid: activeUser.user.uuid
330                     });
331
332                     cy.get('[data-cy=side-panel-tree]').contains('Projects').click();
333
334                     cy.get('main').contains(projectName).rightclick();
335
336                     cy.get('[data-cy=context-menu]').contains('API Details').click();
337
338                     cy.get('[role=tablist]').contains('METADATA').click();
339
340                     cy.get('td').contains(uuid).should('exist');
341
342                     cy.get('td').contains(activeUser.user.uuid).should('exist');
343                 });
344         });
345     });
346
347     describe('Frozen projects', () => {
348         beforeEach(() => {
349             cy.createGroup(activeUser.token, {
350                 name: `Main project ${Math.floor(Math.random() * 999999)}`,
351                 group_class: 'project',
352             }).as('mainProject');
353
354             cy.createGroup(adminUser.token, {
355                 name: `Admin project ${Math.floor(Math.random() * 999999)}`,
356                 group_class: 'project',
357             }).as('adminProject').then((mainProject) => {
358                 cy.shareWith(adminUser.token, activeUser.user.uuid, mainProject.uuid, 'can_write');
359             });
360
361             cy.get('@mainProject').then((mainProject) => {
362                 cy.createGroup(adminUser.token, {
363                     name : `Sub project ${Math.floor(Math.random() * 999999)}`,
364                     group_class: 'project',
365                     owner_uuid: mainProject.uuid,
366                 }).as('subProject');
367
368                 cy.createCollection(adminUser.token, {
369                     name: `Main collection ${Math.floor(Math.random() * 999999)}`,
370                     owner_uuid: mainProject.uuid,
371                     manifest_text: "./subdir 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo\n. 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
372                 }).as('mainCollection');
373             });
374         });
375
376         it('should be able to froze own project', () => {
377             cy.getAll('@mainProject').then(([mainProject]) => {
378                 cy.loginAs(activeUser);
379
380                 cy.get('[data-cy=project-panel]').contains(mainProject.name).rightclick();
381
382                 cy.get('[data-cy=context-menu]').contains('Freeze').click();
383
384                 cy.get('[data-cy=project-panel]').contains(mainProject.name).rightclick();
385
386                 cy.get('[data-cy=context-menu]').contains('Freeze').should('not.exist');
387             });
388         });
389
390         it('should not be able to modify items within the frozen project', () => {
391             cy.getAll('@mainProject', '@mainCollection').then(([mainProject, mainCollection]) => {
392                 cy.loginAs(activeUser);
393
394                 cy.get('[data-cy=project-panel]').contains(mainProject.name).rightclick();
395
396                 cy.get('[data-cy=context-menu]').contains('Freeze').click();
397
398                 cy.get('[data-cy=project-panel]').contains(mainProject.name).click();
399
400                 cy.get('[data-cy=project-panel]').contains(mainCollection.name).rightclick();
401
402                 cy.get('[data-cy=context-menu]').contains('Move to trash').should('not.exist');
403             });
404         });
405
406         it('should be able to froze not owned project', () => {
407             cy.getAll('@adminProject').then(([adminProject]) => {
408                 cy.loginAs(activeUser);
409
410                 cy.get('[data-cy=side-panel-tree]').contains('Shared with me').click();
411
412                 cy.get('main').contains(adminProject.name).rightclick();
413
414                 cy.get('[data-cy=context-menu]').contains('Freeze').should('not.exist');
415             });
416         });
417
418         it('should be able to unfroze project if user is an admin', () => {
419             cy.getAll('@adminProject').then(([adminProject]) => {
420                 cy.loginAs(adminUser);
421
422                 cy.get('main').contains(adminProject.name).rightclick();
423
424                 cy.get('[data-cy=context-menu]').contains('Freeze').click();
425
426                 cy.wait(1000);
427
428                 cy.get('main').contains(adminProject.name).rightclick();
429
430                 cy.get('[data-cy=context-menu]').contains('Unfreeze').click();
431
432                 cy.get('main').contains(adminProject.name).rightclick();
433
434                 cy.get('[data-cy=context-menu]').contains('Freeze').should('exist');
435             });
436         });
437     });
438
439     it('copies project URL to clipboard', () => {
440         const projectName = `Test project (${Math.floor(999999 * Math.random())})`;
441
442         cy.loginAs(activeUser);
443         cy.get('[data-cy=side-panel-button]').click();
444         cy.get('[data-cy=side-panel-new-project]').click();
445         cy.get('[data-cy=form-dialog]')
446             .should('contain', 'New Project')
447             .within(() => {
448                 cy.get('[data-cy=name-field]').within(() => {
449                     cy.get('input').type(projectName);
450                 });
451                 cy.get('[data-cy=form-submit-btn]').click();
452             });
453
454         cy.get('[data-cy=side-panel-tree]').contains('Projects').click();
455         cy.get('[data-cy=project-panel]').contains(projectName).rightclick();
456         cy.get('[data-cy=context-menu]').contains('Copy to clipboard').click();
457         cy.window().then((win) => (
458             win.navigator.clipboard.readText().then((text) => {
459                 expect(text).to.match(/https\:\/\/localhost\:[0-9]+\/projects\/[a-z0-9]{5}-[a-z0-9]{5}-[a-z0-9]{15}/,);
460             })
461         ));
462
463     });
464 });
465