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