19305: Add cypress tests for edit project via breadcrumbs
[arvados-workbench2.git] / cypress / integration / project.spec.js
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 describe('Project 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('creates a new project with multiple properties', function() {
32         const projName = `Test project (${Math.floor(999999 * Math.random())})`;
33         cy.loginAs(activeUser);
34         cy.get('[data-cy=side-panel-button]').click();
35         cy.get('[data-cy=side-panel-new-project]').click();
36         cy.get('[data-cy=form-dialog]')
37             .should('contain', 'New Project')
38             .within(() => {
39                 cy.get('[data-cy=name-field]').within(() => {
40                     cy.get('input').type(projName);
41                 });
42
43             });
44         // Key: Color (IDTAGCOLORS) - Value: Magenta (IDVALCOLORS3)
45         cy.get('[data-cy=form-dialog]').should('not.contain', 'Color: Magenta');
46         cy.get('[data-cy=resource-properties-form]').within(() => {
47             cy.get('[data-cy=property-field-key]').within(() => {
48                 cy.get('input').type('Color');
49             });
50             cy.get('[data-cy=property-field-value]').within(() => {
51                 cy.get('input').type('Magenta');
52             });
53             cy.root().submit();
54             cy.get('[data-cy=property-field-value]').within(() => {
55                 cy.get('input').type('Pink');
56             });
57             cy.root().submit();
58             cy.get('[data-cy=property-field-value]').within(() => {
59                 cy.get('input').type('Yellow');
60             });
61             cy.root().submit();
62         });
63         // Confirm proper vocabulary labels are displayed on the UI.
64         cy.get('[data-cy=form-dialog]').should('contain', 'Color: Magenta');
65         cy.get('[data-cy=form-dialog]').should('contain', 'Color: Pink');
66         cy.get('[data-cy=form-dialog]').should('contain', 'Color: Yellow');
67
68         cy.get('[data-cy=resource-properties-form]').within(() => {
69             cy.get('[data-cy=property-field-key]').within(() => {
70                 cy.get('input').focus();
71             });
72             cy.get('[data-cy=property-field-key]').should('not.contain', 'Color');
73         });
74
75         // Create project and confirm the properties' real values.
76         cy.get('[data-cy=form-submit-btn]').click();
77         cy.get('[data-cy=breadcrumb-last]').should('contain', projName);
78         cy.doRequest('GET', '/arvados/v1/groups', null, {
79             filters: `[["name", "=", "${projName}"], ["group_class", "=", "project"]]`,
80         })
81         .its('body.items').as('projects')
82         .then(function() {
83             expect(this.projects).to.have.lengthOf(1);
84             expect(this.projects[0].properties).to.deep.equal(
85                 // Pink is not in the test vocab
86                 {IDTAGCOLORS: ['IDVALCOLORS3', 'Pink', 'IDVALCOLORS1']});
87         });
88
89         // Open project edit via breadcrumbs
90         cy.get('[data-cy=breadcrumbs]').contains(projName).rightclick();
91         cy.get('[data-cy=context-menu]').contains('Edit').click();
92         cy.get('[data-cy=form-dialog]').within(() => {
93             cy.get('[data-cy=resource-properties-list]').within(() => {
94                 cy.get('div[role=button]').contains('Color: Magenta');
95                 cy.get('div[role=button]').contains('Color: Pink');
96                 cy.get('div[role=button]').contains('Color: Yellow');
97             });
98         });
99         // Add another property
100         cy.get('[data-cy=resource-properties-form]').within(() => {
101             cy.get('[data-cy=property-field-key]').within(() => {
102                 cy.get('input').type('Animal');
103             });
104             cy.get('[data-cy=property-field-value]').within(() => {
105                 cy.get('input').type('Dog');
106             });
107             cy.root().submit();
108         });
109         cy.get('[data-cy=form-submit-btn]').click();
110         // Reopen edit via breadcrumbs and verify properties
111         cy.get('[data-cy=breadcrumbs]').contains(projName).rightclick();
112         cy.get('[data-cy=context-menu]').contains('Edit').click();
113         cy.get('[data-cy=form-dialog]').within(() => {
114             cy.get('[data-cy=resource-properties-list]').within(() => {
115                 cy.get('div[role=button]').contains('Color: Magenta');
116                 cy.get('div[role=button]').contains('Color: Pink');
117                 cy.get('div[role=button]').contains('Color: Yellow');
118                 cy.get('div[role=button]').contains('Animal: Dog');
119             });
120         });
121     });
122
123     it('creates new project on home project and then a subproject inside it', function() {
124         const createProject = function(name, parentName) {
125             cy.get('[data-cy=side-panel-button]').click();
126             cy.get('[data-cy=side-panel-new-project]').click();
127             cy.get('[data-cy=form-dialog]')
128                 .should('contain', 'New Project')
129                 .within(() => {
130                     cy.get('[data-cy=parent-field]').within(() => {
131                         cy.get('input').invoke('val').then((val) => {
132                             expect(val).to.include(parentName);
133                         });
134                     });
135                     cy.get('[data-cy=name-field]').within(() => {
136                         cy.get('input').type(name);
137                     });
138                 });
139             cy.get('[data-cy=form-submit-btn]').click();
140         }
141
142         cy.loginAs(activeUser);
143         cy.goToPath(`/projects/${activeUser.user.uuid}`);
144         cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
145         cy.get('[data-cy=breadcrumb-last]').should('not.exist');
146         // Create new project
147         const projName = `Test project (${Math.floor(999999 * Math.random())})`;
148         createProject(projName, 'Home project');
149         // Confirm that the user was taken to the newly created thing
150         cy.get('[data-cy=form-dialog]').should('not.exist');
151         cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
152         cy.get('[data-cy=breadcrumb-last]').should('contain', projName);
153         // Create a subproject
154         const subProjName = `Test project (${Math.floor(999999 * Math.random())})`;
155         createProject(subProjName, projName);
156         cy.get('[data-cy=form-dialog]').should('not.exist');
157         cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
158         cy.get('[data-cy=breadcrumb-last]').should('contain', subProjName);
159     });
160
161     it('navigates to the parent project after trashing the one being displayed', function() {
162         cy.createGroup(activeUser.token, {
163             name: `Test root project ${Math.floor(Math.random() * 999999)}`,
164             group_class: 'project',
165         }).as('testRootProject').then(function() {
166             cy.createGroup(activeUser.token, {
167                 name : `Test subproject ${Math.floor(Math.random() * 999999)}`,
168                 group_class: 'project',
169                 owner_uuid: this.testRootProject.uuid,
170             }).as('testSubProject');
171         });
172         cy.getAll('@testRootProject', '@testSubProject').then(function([testRootProject, testSubProject]) {
173             cy.loginAs(activeUser);
174
175             // Go to subproject and trash it.
176             cy.goToPath(`/projects/${testSubProject.uuid}`);
177             cy.get('[data-cy=side-panel-tree]').should('contain', testSubProject.name);
178             cy.get('[data-cy=breadcrumb-last]')
179                 .should('contain', testSubProject.name)
180                 .rightclick();
181             cy.get('[data-cy=context-menu]').contains('Move to trash').click();
182
183             // Confirm that the parent project should be displayed.
184             cy.get('[data-cy=breadcrumb-last]').should('contain', testRootProject.name);
185             cy.url().should('contain', `/projects/${testRootProject.uuid}`);
186             cy.get('[data-cy=side-panel-tree]').should('not.contain', testSubProject.name);
187
188             // Checks for bugfix #17637.
189             cy.get('[data-cy=not-found-content]').should('not.exist');
190             cy.get('[data-cy=not-found-page]').should('not.exist');
191         });
192     });
193
194     it('navigates to the root project after trashing the parent of the one being displayed', function() {
195         cy.createGroup(activeUser.token, {
196             name: `Test root project ${Math.floor(Math.random() * 999999)}`,
197             group_class: 'project',
198         }).as('testRootProject').then(function() {
199             cy.createGroup(activeUser.token, {
200                 name : `Test subproject ${Math.floor(Math.random() * 999999)}`,
201                 group_class: 'project',
202                 owner_uuid: this.testRootProject.uuid,
203             }).as('testSubProject').then(function() {
204                 cy.createGroup(activeUser.token, {
205                     name : `Test sub subproject ${Math.floor(Math.random() * 999999)}`,
206                     group_class: 'project',
207                     owner_uuid: this.testSubProject.uuid,
208                 }).as('testSubSubProject');
209             });
210         });
211         cy.getAll('@testRootProject', '@testSubProject', '@testSubSubProject').then(function([testRootProject, testSubProject, testSubSubProject]) {
212             cy.loginAs(activeUser);
213
214             // Go to innermost project and trash its parent.
215             cy.goToPath(`/projects/${testSubSubProject.uuid}`);
216             cy.get('[data-cy=side-panel-tree]').should('contain', testSubSubProject.name);
217             cy.get('[data-cy=breadcrumb-last]').should('contain', testSubSubProject.name);
218             cy.get('[data-cy=side-panel-tree]')
219                 .contains(testSubProject.name)
220                 .rightclick();
221             cy.get('[data-cy=context-menu]').contains('Move to trash').click();
222
223             // Confirm that the trashed project's parent should be displayed.
224             cy.get('[data-cy=breadcrumb-last]').should('contain', testRootProject.name);
225             cy.url().should('contain', `/projects/${testRootProject.uuid}`);
226             cy.get('[data-cy=side-panel-tree]').should('not.contain', testSubProject.name);
227             cy.get('[data-cy=side-panel-tree]').should('not.contain', testSubSubProject.name);
228
229             // Checks for bugfix #17637.
230             cy.get('[data-cy=not-found-content]').should('not.exist');
231             cy.get('[data-cy=not-found-page]').should('not.exist');
232         });
233     });
234
235     it('shows details panel when clicking on the info icon', () => {
236         cy.createGroup(activeUser.token, {
237             name: `Test root project ${Math.floor(Math.random() * 999999)}`,
238             group_class: 'project',
239         }).as('testRootProject').then(function(testRootProject) {
240             cy.loginAs(activeUser);
241
242             cy.get('[data-cy=side-panel-tree]').contains(testRootProject.name).click();
243
244             cy.get('[data-cy=additional-info-icon]').click();
245
246             cy.contains(testRootProject.uuid).should('exist');
247         });
248     });
249
250     it('clears search input when changing project', () => {
251         cy.createGroup(activeUser.token, {
252             name: `Test root project ${Math.floor(Math.random() * 999999)}`,
253             group_class: 'project',
254         }).as('testProject1').then((testProject1) => {
255             cy.shareWith(adminUser.token, activeUser.user.uuid, testProject1.uuid, 'can_write');
256         });
257
258         cy.getAll('@testProject1').then(function([testProject1]) {
259             cy.loginAs(activeUser);
260
261             cy.get('[data-cy=side-panel-tree]').contains(testProject1.name).click();
262
263             cy.get('[data-cy=search-input] input').type('test123');
264
265             cy.get('[data-cy=side-panel-tree]').contains('Projects').click();
266
267             cy.get('[data-cy=search-input] input').should('not.have.value', 'test123');
268         });
269     });
270
271     it('opens advanced popup for project with username', () => {
272         const projectName = `Test project ${Math.floor(Math.random() * 999999)}`;
273
274         cy.createGroup(adminUser.token, {
275             name: projectName,
276             group_class: 'project',
277         }).as('mainProject')
278
279         cy.getAll('@mainProject')
280             .then(function ([mainProject]) {
281                 cy.loginAs(adminUser);
282
283                 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
284
285                 cy.get('[data-cy=uuid]').eq(0).invoke('text').then(uuid => {
286                     cy.createLink(adminUser.token, {
287                         name: 'can_write',
288                         link_class: 'permission',
289                         head_uuid: mainProject.uuid,
290                         tail_uuid: uuid
291                     });
292
293                     cy.createLink(adminUser.token, {
294                         name: 'can_write',
295                         link_class: 'permission',
296                         head_uuid: mainProject.uuid,
297                         tail_uuid: activeUser.user.uuid
298                     });
299
300                     cy.get('[data-cy=side-panel-tree]').contains('Projects').click();
301
302                     cy.get('main').contains(projectName).rightclick();
303
304                     cy.get('[data-cy=context-menu]').contains('Advanced').click();
305
306                     cy.get('[role=tablist]').contains('METADATA').click();
307
308                     cy.get('td').contains(uuid).should('exist');
309
310                     cy.get('td').contains(activeUser.user.uuid).should('exist');
311                 });
312         });
313     });
314 });