21702: Merge branch 'main' into 21702-keep-web-replace_files
[arvados.git] / services / workbench2 / cypress / e2e / side-panel.cy.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     it('enables the +NEW side panel button on users home project', function() {
27         cy.loginAs(activeUser);
28         cy.get('[data-cy=side-panel-button]')
29             .should('exist')
30             .and('not.be.disabled');
31     })
32
33     it('disables or enables the +NEW side panel button depending on project permissions', function() {
34         cy.loginAs(activeUser);
35         [true, false].map(function(isWritable) {
36             cy.createGroup(adminUser.token, {
37                 name: `Test ${isWritable ? 'writable' : 'read-only'} project`,
38                 group_class: 'project',
39             }).as('sharedGroup').then(function() {
40                 cy.createLink(adminUser.token, {
41                     name: isWritable ? 'can_write' : 'can_read',
42                     link_class: 'permission',
43                     head_uuid: this.sharedGroup.uuid,
44                     tail_uuid: activeUser.user.uuid
45                 })
46                 cy.goToPath(`/projects/${this.sharedGroup.uuid}`);
47                 cy.get('[data-cy=side-panel-button]')
48                     .should('exist')
49                     .and(`${isWritable ? 'not.' : ''}be.disabled`);
50             })
51         })
52     })
53
54     it('disables the +NEW side panel button on appropriate sections', function() {
55         cy.loginAs(activeUser);
56         [
57             {url: '/shared-with-me', label: 'Shared with me'},
58             {url: '/public-favorites', label: 'Public Favorites'},
59             {url: '/favorites', label: 'My Favorites'},
60             {url: '/all_processes', label: 'All Processes'},
61             {url: '/trash', label: 'Trash'},
62         ].map(function(section) {
63             cy.waitForDom().goToPath(section.url);
64             cy.get('[data-cy=breadcrumb-first]')
65                 .should('contain', section.label);
66             cy.get('[data-cy=side-panel-button]')
67                 .should('exist')
68                 .and('be.disabled');
69         })
70     })
71
72     it('disables the +NEW side panel button when viewing filter group', function() {
73         cy.loginAs(adminUser);
74         cy.createGroup(adminUser.token, {
75             name: `my-favorite-filter-group`,
76             group_class: 'filter',
77             properties: {filters: []},
78         }).as('myFavoriteFilterGroup').then(function (myFavoriteFilterGroup) {
79             cy.goToPath(`/projects/${myFavoriteFilterGroup.uuid}`);
80             cy.waitForDom();
81             cy.get("[data-cy=breadcrumb-last]").should('exist', { timeout: 10000 });
82             cy.get('[data-cy=breadcrumb-last]').should('contain', 'my-favorite-filter-group');
83
84             cy.get('[data-cy=side-panel-button]')
85                     .should('exist')
86                     .and(`be.disabled`);
87         })
88     })
89
90     it('can edit project in side panel', () => {
91         cy.createProject({
92             owningUser: activeUser,
93             targetUser: activeUser,
94             projectName: 'mySharedWritableProject',
95             canWrite: true,
96             addToFavorites: false
97         });
98
99         cy.getAll('@mySharedWritableProject')
100             .then(function ([mySharedWritableProject]) {
101                 cy.loginAs(activeUser);
102
103                 cy.get('[data-cy=side-panel-tree]').contains('Projects').click();
104
105                 const newProjectName = `New project name ${mySharedWritableProject.name}`;
106                 const newProjectDescription = `New project description ${mySharedWritableProject.name}`;
107
108                 cy.testEditProjectOrCollection('[data-cy=side-panel-tree]', mySharedWritableProject.name, newProjectName, newProjectDescription);
109             });
110     });
111
112     it('side panel react to refresh when project data changes', () => {
113         const project = 'writableProject';
114
115         cy.createProject({
116             owningUser: activeUser,
117             targetUser: activeUser,
118             projectName: project,
119             canWrite: true,
120             addToFavorites: false
121         });
122
123         cy.getAll('@writableProject').then(function ([writableProject]) {
124             cy.loginAs(activeUser);
125             cy.get('[data-cy=side-panel-tree]')
126                 .contains('Projects').click();
127             cy.get('[data-cy=side-panel-tree]')
128                 .contains(writableProject.name).should('exist');
129             cy.trashGroup(activeUser.token, writableProject.uuid).then(() => {
130                 cy.contains('Refresh').click();
131                 cy.contains(writableProject.name).should('not.exist');
132             });
133         });
134     });
135
136     it('collapses and un-collapses', () => {
137
138         cy.loginAs(activeUser)
139         cy.get('[data-cy=side-panel-tree]').should('exist')
140         cy.get('[data-cy=side-panel-toggle]').click()
141         cy.get('[data-cy=side-panel-tree]').should('not.exist')
142         cy.get('[data-cy=side-panel-collapsed]').should('exist')
143         cy.get('[data-cy=side-panel-toggle]').click()
144         cy.get('[data-cy=side-panel-tree]').should('exist')
145         cy.get('[data-cy=side-panel-collapsed]').should('not.exist')
146     })
147
148     it('can navigate from collapsed panel', () => {
149
150         const collapsedCategories = {
151             'shared-with-me': '/shared-with-me',
152             'public-favorites': '/public-favorites',
153             'my-favorites': '/favorites',
154             'groups': '/groups',
155             'all-processes': '/all_processes',
156             'trash': '/trash',
157             'shell-access': '/virtual-machines-user',
158             'home-projects': `/projects/${activeUser.user.uuid}`,
159         }
160
161         cy.loginAs(activeUser)
162         cy.get('[data-cy=side-panel-tree]').should('exist')
163         cy.get('[data-cy=side-panel-toggle]').click()
164         cy.get('[data-cy=side-panel-collapsed]').should('exist')
165
166         for (const cat in collapsedCategories) {
167             cy.get(`[data-cy=collapsed-${cat}]`).should('exist').click()
168             cy.url().should('include', collapsedCategories[cat])
169         }
170     })
171 })
172