43f369459f06ef3e2978fcfc3a98866676e0d178
[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('resets the search box only when navigating out of the current project', function() {
227         const fooProjectNameA = `Test foo project ${Math.floor(Math.random() * 999999)}`;
228         const fooProjectNameB = `Test foo project ${Math.floor(Math.random() * 999999)}`;
229         const barProjectNameA = `Test bar project ${Math.floor(Math.random() * 999999)}`;
230
231         [fooProjectNameA, fooProjectNameB, barProjectNameA].forEach(projName => {
232             cy.createGroup(activeUser.token, {
233                 name: projName,
234                 group_class: 'project',
235             });
236         });
237
238         cy.loginAs(activeUser);
239         cy.get('[data-cy=project-panel]')
240             .should('contain', fooProjectNameA)
241             .and('contain', fooProjectNameB)
242             .and('contain', barProjectNameA);
243
244         cy.get('[data-cy=search-input]').type('foo');
245         cy.get('[data-cy=project-panel]')
246             .should('contain', fooProjectNameA)
247             .and('contain', fooProjectNameB)
248             .and('not.contain', barProjectNameA);
249
250         // Click on the table row to select it, search should remain the same.
251         cy.get(`p:contains(${fooProjectNameA})`)
252             .parent().parent().parent().parent().click();
253         cy.get('[data-cy=search-input] input').should('have.value', 'foo');
254
255         // Click to navigate to the project, search should be reset
256         cy.get(`p:contains(${fooProjectNameA})`).click();
257         cy.get('[data-cy=search-input] input').should('not.have.value', 'foo');
258     });
259
260     it('navigates to the root project after trashing the parent of the one being displayed', function() {
261         cy.createGroup(activeUser.token, {
262             name: `Test root project ${Math.floor(Math.random() * 999999)}`,
263             group_class: 'project',
264         }).as('testRootProject').then(function() {
265             cy.createGroup(activeUser.token, {
266                 name : `Test subproject ${Math.floor(Math.random() * 999999)}`,
267                 group_class: 'project',
268                 owner_uuid: this.testRootProject.uuid,
269             }).as('testSubProject').then(function() {
270                 cy.createGroup(activeUser.token, {
271                     name : `Test sub subproject ${Math.floor(Math.random() * 999999)}`,
272                     group_class: 'project',
273                     owner_uuid: this.testSubProject.uuid,
274                 }).as('testSubSubProject');
275             });
276         });
277         cy.getAll('@testRootProject', '@testSubProject', '@testSubSubProject').then(function([testRootProject, testSubProject, testSubSubProject]) {
278             cy.loginAs(activeUser);
279
280             // Go to innermost project and trash its parent.
281             cy.goToPath(`/projects/${testSubSubProject.uuid}`);
282             cy.get('[data-cy=side-panel-tree]').should('contain', testSubSubProject.name);
283             cy.get('[data-cy=breadcrumb-last]').should('contain', testSubSubProject.name);
284             cy.get('[data-cy=side-panel-tree]')
285                 .contains(testSubProject.name)
286                 .rightclick();
287             cy.get('[data-cy=context-menu]').contains('Move to trash').click();
288
289             // Confirm that the trashed project's parent should be displayed.
290             cy.get('[data-cy=breadcrumb-last]').should('contain', testRootProject.name);
291             cy.url().should('contain', `/projects/${testRootProject.uuid}`);
292             cy.get('[data-cy=side-panel-tree]').should('not.contain', testSubProject.name);
293             cy.get('[data-cy=side-panel-tree]').should('not.contain', testSubSubProject.name);
294
295             // Checks for bugfix #17637.
296             cy.get('[data-cy=not-found-content]').should('not.exist');
297             cy.get('[data-cy=not-found-page]').should('not.exist');
298         });
299     });
300
301     it('shows details panel when clicking on the info icon', () => {
302         cy.createGroup(activeUser.token, {
303             name: `Test root project ${Math.floor(Math.random() * 999999)}`,
304             group_class: 'project',
305         }).as('testRootProject').then(function(testRootProject) {
306             cy.loginAs(activeUser);
307
308             cy.get('[data-cy=side-panel-tree]').contains(testRootProject.name).click();
309
310             cy.get('[data-cy=additional-info-icon]').click();
311
312             cy.contains(testRootProject.uuid).should('exist');
313         });
314     });
315
316     it('clears search input when changing project', () => {
317         cy.createGroup(activeUser.token, {
318             name: `Test root project ${Math.floor(Math.random() * 999999)}`,
319             group_class: 'project',
320         }).as('testProject1').then((testProject1) => {
321             cy.shareWith(adminUser.token, activeUser.user.uuid, testProject1.uuid, 'can_write');
322         });
323
324         cy.getAll('@testProject1').then(function([testProject1]) {
325             cy.loginAs(activeUser);
326
327             cy.get('[data-cy=side-panel-tree]').contains(testProject1.name).click();
328
329             cy.get('[data-cy=search-input] input').type('test123');
330
331             cy.get('[data-cy=side-panel-tree]').contains('Projects').click();
332
333             cy.get('[data-cy=search-input] input').should('not.have.value', 'test123');
334         });
335     });
336
337     it('opens advanced popup for project with username', () => {
338         const projectName = `Test project ${Math.floor(Math.random() * 999999)}`;
339
340         cy.createGroup(adminUser.token, {
341             name: projectName,
342             group_class: 'project',
343         }).as('mainProject')
344
345         cy.getAll('@mainProject')
346             .then(function ([mainProject]) {
347                 cy.loginAs(adminUser);
348
349                 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
350
351                 cy.get('[data-cy=uuid]').eq(0).invoke('text').then(uuid => {
352                     cy.createLink(adminUser.token, {
353                         name: 'can_write',
354                         link_class: 'permission',
355                         head_uuid: mainProject.uuid,
356                         tail_uuid: uuid
357                     });
358
359                     cy.createLink(adminUser.token, {
360                         name: 'can_write',
361                         link_class: 'permission',
362                         head_uuid: mainProject.uuid,
363                         tail_uuid: activeUser.user.uuid
364                     });
365
366                     cy.get('[data-cy=side-panel-tree]').contains('Projects').click();
367
368                     cy.get('main').contains(projectName).rightclick();
369
370                     cy.get('[data-cy=context-menu]').contains('API Details').click();
371
372                     cy.get('[role=tablist]').contains('METADATA').click();
373
374                     cy.get('td').contains(uuid).should('exist');
375
376                     cy.get('td').contains(activeUser.user.uuid).should('exist');
377                 });
378         });
379     });
380
381     describe('Frozen projects', () => {
382         beforeEach(() => {
383             cy.createGroup(activeUser.token, {
384                 name: `Main project ${Math.floor(Math.random() * 999999)}`,
385                 group_class: 'project',
386             }).as('mainProject');
387
388             cy.createGroup(adminUser.token, {
389                 name: `Admin project ${Math.floor(Math.random() * 999999)}`,
390                 group_class: 'project',
391             }).as('adminProject').then((mainProject) => {
392                 cy.shareWith(adminUser.token, activeUser.user.uuid, mainProject.uuid, 'can_write');
393             });
394
395             cy.get('@mainProject').then((mainProject) => {
396                 cy.createGroup(adminUser.token, {
397                     name : `Sub project ${Math.floor(Math.random() * 999999)}`,
398                     group_class: 'project',
399                     owner_uuid: mainProject.uuid,
400                 }).as('subProject');
401
402                 cy.createCollection(adminUser.token, {
403                     name: `Main collection ${Math.floor(Math.random() * 999999)}`,
404                     owner_uuid: mainProject.uuid,
405                     manifest_text: "./subdir 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo\n. 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
406                 }).as('mainCollection');
407             });
408         });
409
410         it('should be able to froze own project', () => {
411             cy.getAll('@mainProject').then(([mainProject]) => {
412                 cy.loginAs(activeUser);
413
414                 cy.get('[data-cy=project-panel]').contains(mainProject.name).rightclick();
415
416                 cy.get('[data-cy=context-menu]').contains('Freeze').click();
417
418                 cy.get('[data-cy=project-panel]').contains(mainProject.name).rightclick();
419
420                 cy.get('[data-cy=context-menu]').contains('Freeze').should('not.exist');
421             });
422         });
423
424         it('should not be able to modify items within the frozen project', () => {
425             cy.getAll('@mainProject', '@mainCollection').then(([mainProject, mainCollection]) => {
426                 cy.loginAs(activeUser);
427
428                 cy.get('[data-cy=project-panel]').contains(mainProject.name).rightclick();
429
430                 cy.get('[data-cy=context-menu]').contains('Freeze').click();
431
432                 cy.get('[data-cy=project-panel]').contains(mainProject.name).click();
433
434                 cy.get('[data-cy=project-panel]').contains(mainCollection.name).rightclick();
435
436                 cy.get('[data-cy=context-menu]').contains('Move to trash').should('not.exist');
437             });
438         });
439
440         it('should be able to froze not owned project', () => {
441             cy.getAll('@adminProject').then(([adminProject]) => {
442                 cy.loginAs(activeUser);
443
444                 cy.get('[data-cy=side-panel-tree]').contains('Shared with me').click();
445
446                 cy.get('main').contains(adminProject.name).rightclick();
447
448                 cy.get('[data-cy=context-menu]').contains('Freeze').should('not.exist');
449             });
450         });
451
452         it('should be able to unfroze project if user is an admin', () => {
453             cy.getAll('@adminProject').then(([adminProject]) => {
454                 cy.loginAs(adminUser);
455
456                 cy.get('main').contains(adminProject.name).rightclick();
457
458                 cy.get('[data-cy=context-menu]').contains('Freeze').click();
459
460                 cy.wait(1000);
461
462                 cy.get('main').contains(adminProject.name).rightclick();
463
464                 cy.get('[data-cy=context-menu]').contains('Unfreeze').click();
465
466                 cy.get('main').contains(adminProject.name).rightclick();
467
468                 cy.get('[data-cy=context-menu]').contains('Freeze').should('exist');
469             });
470         });
471     });
472
473     it('copies project URL to clipboard', () => {
474         const projectName = `Test project (${Math.floor(999999 * Math.random())})`;
475
476         cy.loginAs(activeUser);
477         cy.get('[data-cy=side-panel-button]').click();
478         cy.get('[data-cy=side-panel-new-project]').click();
479         cy.get('[data-cy=form-dialog]')
480             .should('contain', 'New Project')
481             .within(() => {
482                 cy.get('[data-cy=name-field]').within(() => {
483                     cy.get('input').type(projectName);
484                 });
485                 cy.get('[data-cy=form-submit-btn]').click();
486             });
487
488         cy.get('[data-cy=side-panel-tree]').contains('Projects').click();
489         cy.get('[data-cy=project-panel]').contains(projectName).rightclick();
490         cy.get('[data-cy=context-menu]').contains('Copy to clipboard').click();
491         cy.window().then((win) => (
492             win.navigator.clipboard.readText().then((text) => {
493                 expect(text).to.match(/https\:\/\/localhost\:[0-9]+\/projects\/[a-z0-9]{5}-[a-z0-9]{5}-[a-z0-9]{15}/,);
494             })
495         ));
496
497     });
498
499     it('sorts displayed items correctly', () => {
500         cy.loginAs(activeUser);
501
502         cy.get('[data-cy=project-panel] button[title="Select columns"]').click();
503         cy.get('div[role=presentation] ul > div[role=button]').contains('Date Created').click();
504         cy.get('div[role=presentation] ul > div[role=button]').contains('Trash at').click();
505         cy.get('div[role=presentation] ul > div[role=button]').contains('Delete at').click();
506         cy.get('div[role=presentation] > div[aria-hidden=true]').click();
507
508         cy.intercept({method: 'GET', url: '**/arvados/v1/groups/*/contents*'}).as('filteredQuery');
509         [
510             {
511                 name: "Name",
512                 asc: "collections.name asc,container_requests.name asc,groups.name asc",
513                 desc: "collections.name desc,container_requests.name desc,groups.name desc"
514             },
515             {
516                 name: "Last Modified",
517                 asc: "collections.modified_at asc,container_requests.modified_at asc,groups.modified_at asc",
518                 desc: "collections.modified_at desc,container_requests.modified_at desc,groups.modified_at desc"
519             },
520             {
521                 name: "Date Created",
522                 asc: "collections.created_at asc,container_requests.created_at asc,groups.created_at asc",
523                 desc: "collections.created_at desc,container_requests.created_at desc,groups.created_at desc"
524
525             },
526             {
527                 name: "Trash at",
528                 asc: "collections.trash_at asc,container_requests.trash_at asc,groups.trash_at asc",
529                 desc: "collections.trash_at desc,container_requests.trash_at desc,groups.trash_at desc"
530
531             },
532             {
533                 name: "Delete at",
534                 asc: "collections.delete_at asc,container_requests.delete_at asc,groups.delete_at asc",
535                 desc: "collections.delete_at desc,container_requests.delete_at desc,groups.delete_at desc"
536
537             },
538         ].forEach((test) => {
539             cy.get('[data-cy=project-panel] table thead th').contains(test.name).click();
540             cy.wait('@filteredQuery').then(interception => {
541                 const searchParams = new URLSearchParams((new URL(interception.request.url).search));
542                 expect(searchParams.get('order')).to.eq(test.asc);
543             });
544             cy.get('[data-cy=project-panel] table thead th').contains(test.name).click();
545             cy.wait('@filteredQuery').then(interception => {
546                 const searchParams = new URLSearchParams((new URL(interception.request.url).search));
547                 expect(searchParams.get('order')).to.eq(test.desc);
548             });
549         });
550
551     });
552 });