1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 describe('Sharing tests', 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;
19 cy.getUser('collectionuser1', 'Collection', 'User', false, true)
20 .as('activeUser').then(function () {
21 activeUser = this.activeUser;
26 beforeEach(function () {
28 cy.clearLocalStorage()
31 it('can share projects to other users', () => {
32 cy.loginAs(adminUser);
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();
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 changes').click();
50 cy.get('@sharingDialog').contains('Close').click();
53 cy.createGroup(adminUser.token, {
54 name: `my-shared-readonly-project ${Math.floor(Math.random() * 999999)}`,
55 group_class: 'project',
56 }).as('mySharedReadonlyProject').then(function (mySharedReadonlyProject) {
57 cy.contains('Refresh').click();
58 cy.get('main').contains(mySharedReadonlyProject.name).rightclick();
59 cy.get('[data-cy=context-menu]').within(() => {
60 cy.contains('Share').click();
62 cy.get('.sharing-dialog').as('sharingDialog');
63 cy.get('[data-cy=invite-people-field]').find('input').type(activeUser.user.email);
64 cy.get('[role=tooltip]').click();
65 cy.get('@sharingDialog').contains('Save changes').click();
66 cy.get('@sharingDialog').contains('Close').click();
69 cy.getAll('@mySharedWritableProject', '@mySharedReadonlyProject')
70 .then(function ([mySharedWritableProject, mySharedReadonlyProject]) {
71 cy.loginAs(activeUser);
73 cy.contains('Shared with me').click();
75 cy.get('main').contains(mySharedWritableProject.name).rightclick();
76 cy.get('[data-cy=context-menu]').should('contain', 'Move to trash');
77 cy.get('[data-cy=context-menu]').contains('Move to trash').click();
79 // GUARD: Let's wait for the above removed project to disappear
80 // before continuing, to avoid intermittent failures.
81 cy.get('main').should('not.contain', mySharedWritableProject.name);
83 cy.get('main').contains(mySharedReadonlyProject.name).rightclick();
84 cy.get('[data-cy=context-menu]').should('not.contain', 'Move to trash');
88 it('can edit project in shared with me', () => {
90 owningUser: adminUser,
91 targetUser: activeUser,
92 projectName: 'mySharedWritableProject',
97 cy.getAll('@mySharedWritableProject')
98 .then(function ([mySharedWritableProject]) {
99 cy.loginAs(activeUser);
101 cy.get('[data-cy=side-panel-tree]').contains('Shared with me').click();
103 const newProjectName = `New project name ${mySharedWritableProject.name}`;
104 const newProjectDescription = `New project description ${mySharedWritableProject.name}`;
106 cy.testEditProjectOrCollection('main', mySharedWritableProject.name, newProjectName, newProjectDescription);