18482: Fixed info icon issue and added cypress test
[arvados.git] / cypress / integration / sharing.spec.js
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 describe('Sharing 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('collectionuser1', 'Collection', '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('can share projects to other users', () => {
32         cy.loginAs(adminUser);
33
34         cy.createGroup(adminUser.token, {
35             name: `my-shared-writable-project ${Math.floor(Math.random() * 999999)}`,
36             group_class: 'project',
37         }).as('mySharedWritableProject').then(function (mySharedWritableProject) {
38             cy.contains('Refresh').click();
39             cy.get('main').contains(mySharedWritableProject.name).rightclick();
40             cy.get('[data-cy=context-menu]').within(() => {
41                 cy.contains('Share').click();
42             });
43             cy.get('[id="select-permissions"]').as('selectPermissions');
44             cy.get('@selectPermissions').click();
45             cy.contains('Write').click();
46             cy.get('.sharing-dialog').as('sharingDialog');
47             cy.get('[data-cy=invite-people-field]').find('input').type(activeUser.user.email);
48             cy.get('[role=tooltip]').click();
49             cy.get('@sharingDialog').contains('Save').click();
50         });
51
52         cy.createGroup(adminUser.token, {
53             name: `my-shared-readonly-project ${Math.floor(Math.random() * 999999)}`,
54             group_class: 'project',
55         }).as('mySharedReadonlyProject').then(function (mySharedReadonlyProject) {
56             cy.contains('Refresh').click();
57             cy.get('main').contains(mySharedReadonlyProject.name).rightclick();
58             cy.get('[data-cy=context-menu]').within(() => {
59                 cy.contains('Share').click();
60             });
61             cy.get('.sharing-dialog').as('sharingDialog');
62             cy.get('[data-cy=invite-people-field]').find('input').type(activeUser.user.email);
63             cy.get('[role=tooltip]').click();
64             cy.get('@sharingDialog').contains('Save').click();
65         });
66
67         cy.getAll('@mySharedWritableProject', '@mySharedReadonlyProject')
68             .then(function ([mySharedWritableProject, mySharedReadonlyProject]) {
69                 cy.loginAs(activeUser);
70
71                 cy.contains('Shared with me').click();
72
73                 cy.get('main').contains(mySharedWritableProject.name).rightclick();
74                 cy.get('[data-cy=context-menu]').should('contain', 'Move to trash');
75                 cy.get('[data-cy=context-menu]').contains('Move to trash').click();
76
77                 // GUARD: Let's wait for the above removed project to disappear
78                 // before continuing, to avoid intermittent failures.
79                 cy.get('main').should('not.contain', mySharedWritableProject.name);
80
81                 cy.get('main').contains(mySharedReadonlyProject.name).rightclick();
82                 cy.get('[data-cy=context-menu]').should('not.contain', 'Move to trash');
83             });
84     });
85
86     it('can edit project in shared with me', () => {
87         cy.createProject({
88             owningUser: adminUser,
89             targetUser: activeUser,
90             projectName: 'mySharedWritableProject',
91             canWrite: true,
92             addToFavorites: true
93         });
94
95         cy.getAll('@mySharedWritableProject')
96             .then(function ([mySharedWritableProject]) {
97                 cy.loginAs(activeUser);
98                 
99                 cy.get('[data-cy=side-panel-tree]').contains('Shared with me').click();
100
101                 const newProjectName = `New project name ${mySharedWritableProject.name}`;
102                 const newProjectDescription = `New project description ${mySharedWritableProject.name}`;
103
104                 cy.testEditProjectOrCollection('main', mySharedWritableProject.name, newProjectName, newProjectDescription);
105             });
106     });
107 });