Merge branch '19930-saving-empty-project-descriptions' into main. Closes #19930
[arvados.git] / cypress / integration / side-panel.spec.js
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 describe('Side panel 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('enables the +NEW side panel button on users home project', function() {
32         cy.loginAs(activeUser);
33         cy.get('[data-cy=side-panel-button]')
34             .should('exist')
35             .and('not.be.disabled');
36     })
37
38     it('disables or enables the +NEW side panel button depending on project permissions', function() {
39         cy.loginAs(activeUser);
40         [true, false].map(function(isWritable) {
41             cy.createGroup(adminUser.token, {
42                 name: `Test ${isWritable ? 'writable' : 'read-only'} project`,
43                 group_class: 'project',
44             }).as('sharedGroup').then(function() {
45                 cy.createLink(adminUser.token, {
46                     name: isWritable ? 'can_write' : 'can_read',
47                     link_class: 'permission',
48                     head_uuid: this.sharedGroup.uuid,
49                     tail_uuid: activeUser.user.uuid
50                 })
51                 cy.goToPath(`/projects/${this.sharedGroup.uuid}`);
52                 cy.get('[data-cy=side-panel-button]')
53                     .should('exist')
54                     .and(`${isWritable ? 'not.' : ''}be.disabled`);
55             })
56         })
57     })
58
59     it('disables the +NEW side panel button on appropriate sections', function() {
60         cy.loginAs(activeUser);
61         [
62             {url: '/shared-with-me', label: 'Shared with me'},
63             {url: '/public-favorites', label: 'Public Favorites'},
64             {url: '/favorites', label: 'My Favorites'},
65             {url: '/all_processes', label: 'All Processes'},
66             {url: '/trash', label: 'Trash'},
67         ].map(function(section) {
68             cy.goToPath(section.url);
69             cy.get('[data-cy=breadcrumb-first]')
70                 .should('contain', section.label);
71             cy.get('[data-cy=side-panel-button]')
72                 .should('exist')
73                 .and('be.disabled');
74         })
75     })
76
77     it('disables the +NEW side panel button when viewing filter group', function() {
78         cy.loginAs(adminUser);
79         cy.createGroup(adminUser.token, {
80             name: `my-favorite-filter-group`,
81             group_class: 'filter',
82             properties: {filters: []},
83         }).as('myFavoriteFilterGroup').then(function (myFavoriteFilterGroup) {
84             cy.goToPath(`/projects/${myFavoriteFilterGroup.uuid}`);
85             cy.get('[data-cy=breadcrumb-last]').should('contain', 'my-favorite-filter-group');
86
87             cy.get('[data-cy=side-panel-button]')
88                     .should('exist')
89                     .and(`be.disabled`);
90         })
91     })
92
93     it('can edit project in side panel', () => {
94         cy.createProject({
95             owningUser: activeUser,
96             targetUser: activeUser,
97             projectName: 'mySharedWritableProject',
98             canWrite: true,
99             addToFavorites: false
100         });
101
102         cy.getAll('@mySharedWritableProject')
103             .then(function ([mySharedWritableProject]) {
104                 cy.loginAs(activeUser);
105
106                 cy.get('[data-cy=side-panel-tree]').contains('Projects').click();
107
108                 const newProjectName = `New project name ${mySharedWritableProject.name}`;
109                 const newProjectDescription = `New project description ${mySharedWritableProject.name}`;
110
111                 cy.testEditProjectOrCollection('[data-cy=side-panel-tree]', mySharedWritableProject.name, newProjectName, newProjectDescription);
112             });
113     });
114
115     it('side panel react to refresh when project data changes', () => {
116         const project = 'writableProject';
117
118         cy.createProject({
119             owningUser: activeUser,
120             targetUser: activeUser,
121             projectName: project,
122             canWrite: true,
123             addToFavorites: false
124         });
125
126         cy.getAll('@writableProject').then(function ([writableProject]) {
127             cy.loginAs(activeUser);
128             cy.get('[data-cy=side-panel-tree]')
129                 .contains('Projects').click();
130             cy.get('[data-cy=side-panel-tree]')
131                 .contains(writableProject.name).should('exist');
132             cy.trashGroup(activeUser.token, writableProject.uuid).then(() => {
133                 cy.contains('Refresh').click();
134                 cy.contains(writableProject.name).should('not.exist');
135             });
136         });
137     });
138 })