15814: Remove .only
[arvados.git] / services / workbench2 / cypress / e2e / sharing.cy.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         cy.getUser('collectionuser1', 'Collection', 'User', false, true)
19             .as('activeUser').then(function () {
20                 activeUser = this.activeUser;
21             });
22     })
23
24     it('can create and delete sharing URLs on collections', () => {
25         const collName = 'shared-collection ' + new Date().getTime();
26         cy.createCollection(adminUser.token, {
27             name: collName,
28             owner_uuid: adminUser.uuid,
29         }).as('sharedCollection').then(function (sharedCollection) {
30             cy.loginAs(adminUser);
31
32             cy.get('main').contains(sharedCollection.name).rightclick();
33             cy.get('[data-cy=context-menu]').within(() => {
34                 cy.contains('Share').click({ waitForAnimations: false });
35             });
36             cy.get('.sharing-dialog').within(() => {
37                 cy.contains('Sharing URLs').click();
38                 cy.contains('Create sharing URL');
39                 cy.contains('No sharing URLs');
40                 cy.should('not.contain', 'Token');
41                 cy.should('not.contain', 'expiring at:');
42
43                 cy.contains('Create sharing URL').click();
44                 cy.should('not.contain', 'No sharing URLs');
45                 cy.contains('Token');
46                 cy.contains('expiring at:');
47
48                 cy.get('[data-cy=remove-url-btn]').find('button').click();
49                 cy.contains('No sharing URLs');
50                 cy.should('not.contain', 'Token');
51                 cy.should('not.contain', 'expiring at:');
52             })
53         })
54     });
55
56     it('can share projects to other users', () => {
57         cy.loginAs(adminUser);
58
59         cy.createGroup(adminUser.token, {
60             name: `my-shared-writable-project ${Math.floor(Math.random() * 999999)}`,
61             group_class: 'project',
62         }).as('mySharedWritableProject').then(function (mySharedWritableProject) {
63             cy.contains('Refresh').click();
64             cy.get('main').contains(mySharedWritableProject.name).rightclick();
65             cy.get('[data-cy=context-menu]').within(() => {
66                 cy.contains('Share').click({ waitForAnimations: false });
67             });
68             cy.get('[id="select-permissions"]').as('selectPermissions');
69             cy.get('@selectPermissions').click();
70             cy.contains('Write').click();
71             cy.get('.sharing-dialog').as('sharingDialog');
72             cy.get('[data-cy=invite-people-field]').find('input').type(activeUser.user.email);
73             cy.get('[role=tooltip]').click();
74             cy.get('@sharingDialog').within(() => {
75                 cy.get('[data-cy=add-invited-people]').click();
76                 cy.contains('Close').click({ waitForAnimations: false });
77             });
78         });
79
80         cy.createGroup(adminUser.token, {
81             name: `my-shared-readonly-project ${Math.floor(Math.random() * 999999)}`,
82             group_class: 'project',
83         }).as('mySharedReadonlyProject').then(function (mySharedReadonlyProject) {
84             cy.contains('Refresh').click();
85             cy.get('main').contains(mySharedReadonlyProject.name).rightclick();
86             cy.get('[data-cy=context-menu]').within(() => {
87                 cy.contains('Share').click({ waitForAnimations: false });
88             });
89             cy.get('.sharing-dialog').as('sharingDialog');
90             cy.get('[data-cy=invite-people-field]').find('input').type(activeUser.user.email);
91             cy.get('[role=tooltip]').click();
92             cy.get('@sharingDialog').within(() => {
93                 cy.get('[data-cy=add-invited-people]').click();
94                 cy.contains('Close').click({ waitForAnimations: false });
95             });
96         });
97
98         cy.getAll('@mySharedWritableProject', '@mySharedReadonlyProject')
99             .then(function ([mySharedWritableProject, mySharedReadonlyProject]) {
100                 cy.loginAs(activeUser);
101
102                 cy.contains('Shared with me').click();
103
104                 // Test search
105                 cy.get('[data-cy=search-input] input').type('readonly');
106                 cy.get('main').should('not.contain', mySharedWritableProject.name);
107                 cy.get('main').should('contain', mySharedReadonlyProject.name);
108                 cy.get('[data-cy=search-input] input').clear();
109
110                 // Test filter
111                 cy.waitForDom().get('th').contains('Type').click();
112                 cy.get('div[role=presentation]').contains('Project').click();
113                 cy.waitForDom().get('main table tr td').contains('Project').should('not.exist');
114                 cy.get('div[role=presentation]').contains('Project').click();
115                 cy.waitForDom().get('div[role=presentation] button').contains('Close').click();
116
117                 // Test move to trash
118                 cy.get('main').contains(mySharedWritableProject.name).rightclick();
119                 cy.get('[data-cy=context-menu]').should('contain', 'Move to trash');
120                 cy.get('[data-cy=context-menu]').contains('Move to trash').click({ waitForAnimations: false });
121
122                 // GUARD: Let's wait for the above removed project to disappear
123                 // before continuing, to avoid intermittent failures.
124                 cy.get('main').should('not.contain', mySharedWritableProject.name);
125
126                 cy.get('main').contains(mySharedReadonlyProject.name).rightclick();
127                 cy.get('[data-cy=context-menu]').should('not.contain', 'Move to trash');
128             });
129     });
130
131     it('can edit project in shared with me', () => {
132         cy.createProject({
133             owningUser: adminUser,
134             targetUser: activeUser,
135             projectName: 'mySharedWritableProject',
136             canWrite: true,
137             addToFavorites: true
138         });
139
140         cy.getAll('@mySharedWritableProject')
141             .then(function ([mySharedWritableProject]) {
142                 cy.loginAs(activeUser);
143
144                 cy.get('[data-cy=side-panel-tree]').contains('Shared with me').click();
145
146                 const newProjectName = `New project name ${mySharedWritableProject.name}`;
147                 const newProjectDescription = `New project description ${mySharedWritableProject.name}`;
148
149                 cy.testEditProjectOrCollection('main', mySharedWritableProject.name, newProjectName, newProjectDescription);
150             });
151     });
152
153     it('can share only when target users are present', () => {
154         const collName = `mySharedCollectionForUsers-${new Date().getTime()}`;
155         cy.createCollection(adminUser.token, {
156             name: collName,
157             owner_uuid: adminUser.uuid,
158         }).as('mySharedCollectionForUsers')
159
160         cy.getAll('@mySharedCollectionForUsers')
161             .then(function ([]) {
162                 cy.loginAs(adminUser);
163                 cy.get('[data-cy=project-panel]').contains(collName).rightclick();
164                 cy.get('[data-cy=context-menu]').contains('Share').click({ waitForAnimations: false });
165                 cy.get('button').get('[data-cy=add-invited-people]').should('be.disabled');
166                 cy.get('[data-cy=invite-people-field] input').type('Anonymous');
167                 cy.get('div[role=tooltip]').contains('anonymous').click();
168                 cy.get('button').get('[data-cy=add-invited-people]').should('not.be.disabled');
169                 cy.get('[data-cy=invite-people-field] div[role=button]').contains('anonymous').parent().find('svg').click();
170                 cy.get('button').get('[data-cy=add-invited-people]').should('be.disabled');
171             });
172     });
173 });