21461: Makes properties' test behave better on Firefox.
[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.get('[data-cy=breadcrumb-last]').should('contain', 'my-favorite-filter-group');
81
82             cy.get('[data-cy=side-panel-button]')
83                     .should('exist')
84                     .and(`be.disabled`);
85         })
86     })
87
88     it('can edit project in side panel', () => {
89         cy.createProject({
90             owningUser: activeUser,
91             targetUser: activeUser,
92             projectName: 'mySharedWritableProject',
93             canWrite: true,
94             addToFavorites: false
95         });
96
97         cy.getAll('@mySharedWritableProject')
98             .then(function ([mySharedWritableProject]) {
99                 cy.loginAs(activeUser);
100
101                 cy.get('[data-cy=side-panel-tree]').contains('Projects').click();
102
103                 const newProjectName = `New project name ${mySharedWritableProject.name}`;
104                 const newProjectDescription = `New project description ${mySharedWritableProject.name}`;
105
106                 cy.testEditProjectOrCollection('[data-cy=side-panel-tree]', mySharedWritableProject.name, newProjectName, newProjectDescription);
107             });
108     });
109
110     it('side panel react to refresh when project data changes', () => {
111         const project = 'writableProject';
112
113         cy.createProject({
114             owningUser: activeUser,
115             targetUser: activeUser,
116             projectName: project,
117             canWrite: true,
118             addToFavorites: false
119         });
120
121         cy.getAll('@writableProject').then(function ([writableProject]) {
122             cy.loginAs(activeUser);
123             cy.get('[data-cy=side-panel-tree]')
124                 .contains('Projects').click();
125             cy.get('[data-cy=side-panel-tree]')
126                 .contains(writableProject.name).should('exist');
127             cy.trashGroup(activeUser.token, writableProject.uuid).then(() => {
128                 cy.contains('Refresh').click();
129                 cy.contains(writableProject.name).should('not.exist');
130             });
131         });
132     });
133
134     it('collapses and un-collapses', () => {
135
136         cy.loginAs(activeUser)
137         cy.get('[data-cy=side-panel-tree]').should('exist')
138         cy.get('[data-cy=side-panel-toggle]').click()
139         cy.get('[data-cy=side-panel-tree]').should('not.exist')
140         cy.get('[data-cy=side-panel-collapsed]').should('exist')
141         cy.get('[data-cy=side-panel-toggle]').click()
142         cy.get('[data-cy=side-panel-tree]').should('exist')
143         cy.get('[data-cy=side-panel-collapsed]').should('not.exist')
144     })
145
146     it('can navigate from collapsed panel', () => {
147
148         const collapsedCategories = {
149             'shared-with-me': '/shared-with-me',
150             'public-favorites': '/public-favorites',
151             'my-favorites': '/favorites',
152             'groups': '/groups',
153             'all-processes': '/all_processes',
154             'trash': '/trash',
155             'shell-access': '/virtual-machines-user',
156             'home-projects': `/projects/${activeUser.user.uuid}`,
157         }
158
159         cy.loginAs(activeUser)
160         cy.get('[data-cy=side-panel-tree]').should('exist')
161         cy.get('[data-cy=side-panel-toggle]').click()
162         cy.get('[data-cy=side-panel-collapsed]').should('exist')
163
164         for (const cat in collapsedCategories) {
165             cy.get(`[data-cy=collapsed-${cat}]`).should('exist').click()
166             cy.url().should('include', collapsedCategories[cat])
167         }
168     })
169 })
170