1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 describe('Project 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;
19 cy.getUser('user', 'Active', 'User', false, true)
20 .as('activeUser').then(function() {
21 activeUser = this.activeUser;
26 beforeEach(function() {
28 cy.clearLocalStorage();
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')
39 cy.get('[data-cy=name-field]').within(() => {
40 cy.get('input').type(projName);
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');
50 cy.get('[data-cy=property-field-value]').within(() => {
51 cy.get('input').type('Magenta');
54 cy.get('[data-cy=property-field-value]').within(() => {
55 cy.get('input').type('Pink');
58 cy.get('[data-cy=property-field-value]').within(() => {
59 cy.get('input').type('Yellow');
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');
68 cy.get('[data-cy=resource-properties-form]').within(() => {
69 cy.get('[data-cy=property-field-key]').within(() => {
70 cy.get('input').focus();
72 cy.get('[data-cy=property-field-key]').should('not.contain', 'Color');
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"]]`,
81 .its('body.items').as('projects')
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']});
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');
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');
104 cy.get('[data-cy=property-field-value]').within(() => {
105 cy.get('input').type('Dog');
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');
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')
130 cy.get('[data-cy=parent-field]').within(() => {
131 cy.get('input').invoke('val').then((val) => {
132 expect(val).to.include(parentName);
135 cy.get('[data-cy=name-field]').within(() => {
136 cy.get('input').type(name);
139 cy.get('[data-cy=form-submit-btn]').click();
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);
161 it('attempts to use a preexisting name creating a project', function() {
162 const name = `Test project ${Math.floor(Math.random() * 999999)}`;
163 cy.createGroup(activeUser.token, {
165 group_class: 'project',
167 cy.loginAs(activeUser);
168 cy.goToPath(`/projects/${activeUser.user.uuid}`);
170 // Attempt to create new collection with a duplicate name
171 cy.get('[data-cy=side-panel-button]').click();
172 cy.get('[data-cy=side-panel-new-project]').click();
173 cy.get('[data-cy=form-dialog]')
174 .should('contain', 'New Project')
176 cy.get('[data-cy=name-field]').within(() => {
177 cy.get('input').type(name);
179 cy.get('[data-cy=form-submit-btn]').click();
181 // Error message should display, allowing editing the name
182 cy.get('[data-cy=form-dialog]').should('exist')
183 .and('contain', 'Project with the same name already exists')
185 cy.get('[data-cy=name-field]').within(() => {
186 cy.get('input').type(' renamed');
188 cy.get('[data-cy=form-submit-btn]').click();
190 cy.get('[data-cy=form-dialog]').should('not.exist');
193 it('navigates to the parent project after trashing the one being displayed', function() {
194 cy.createGroup(activeUser.token, {
195 name: `Test root project ${Math.floor(Math.random() * 999999)}`,
196 group_class: 'project',
197 }).as('testRootProject').then(function() {
198 cy.createGroup(activeUser.token, {
199 name : `Test subproject ${Math.floor(Math.random() * 999999)}`,
200 group_class: 'project',
201 owner_uuid: this.testRootProject.uuid,
202 }).as('testSubProject');
204 cy.getAll('@testRootProject', '@testSubProject').then(function([testRootProject, testSubProject]) {
205 cy.loginAs(activeUser);
207 // Go to subproject and trash it.
208 cy.goToPath(`/projects/${testSubProject.uuid}`);
209 cy.get('[data-cy=side-panel-tree]').should('contain', testSubProject.name);
210 cy.get('[data-cy=breadcrumb-last]')
211 .should('contain', testSubProject.name)
213 cy.get('[data-cy=context-menu]').contains('Move to trash').click();
215 // Confirm that the parent project should be displayed.
216 cy.get('[data-cy=breadcrumb-last]').should('contain', testRootProject.name);
217 cy.url().should('contain', `/projects/${testRootProject.uuid}`);
218 cy.get('[data-cy=side-panel-tree]').should('not.contain', testSubProject.name);
220 // Checks for bugfix #17637.
221 cy.get('[data-cy=not-found-content]').should('not.exist');
222 cy.get('[data-cy=not-found-page]').should('not.exist');
226 it('resets the search box only when navigating out of the current project', function() {
227 const fooProjectNameA = `Test foo project ${Math.floor(Math.random() * 999999)}`;
228 const fooProjectNameB = `Test foo project ${Math.floor(Math.random() * 999999)}`;
229 const barProjectNameA = `Test bar project ${Math.floor(Math.random() * 999999)}`;
231 [fooProjectNameA, fooProjectNameB, barProjectNameA].forEach(projName => {
232 cy.createGroup(activeUser.token, {
234 group_class: 'project',
238 cy.loginAs(activeUser);
239 cy.get('[data-cy=project-panel]')
240 .should('contain', fooProjectNameA)
241 .and('contain', fooProjectNameB)
242 .and('contain', barProjectNameA);
244 cy.get('[data-cy=search-input]').type('foo');
245 cy.get('[data-cy=project-panel]')
246 .should('contain', fooProjectNameA)
247 .and('contain', fooProjectNameB)
248 .and('not.contain', barProjectNameA);
250 // Click on the table row to select it, search should remain the same.
251 cy.get(`p:contains(${fooProjectNameA})`)
252 .parent().parent().parent().parent().click();
253 cy.get('[data-cy=search-input] input').should('have.value', 'foo');
255 // Click to navigate to the project, search should be reset
256 cy.get(`p:contains(${fooProjectNameA})`).click();
257 cy.get('[data-cy=search-input] input').should('not.have.value', 'foo');
260 it('navigates to the root project after trashing the parent of the one being displayed', function() {
261 cy.createGroup(activeUser.token, {
262 name: `Test root project ${Math.floor(Math.random() * 999999)}`,
263 group_class: 'project',
264 }).as('testRootProject').then(function() {
265 cy.createGroup(activeUser.token, {
266 name : `Test subproject ${Math.floor(Math.random() * 999999)}`,
267 group_class: 'project',
268 owner_uuid: this.testRootProject.uuid,
269 }).as('testSubProject').then(function() {
270 cy.createGroup(activeUser.token, {
271 name : `Test sub subproject ${Math.floor(Math.random() * 999999)}`,
272 group_class: 'project',
273 owner_uuid: this.testSubProject.uuid,
274 }).as('testSubSubProject');
277 cy.getAll('@testRootProject', '@testSubProject', '@testSubSubProject').then(function([testRootProject, testSubProject, testSubSubProject]) {
278 cy.loginAs(activeUser);
280 // Go to innermost project and trash its parent.
281 cy.goToPath(`/projects/${testSubSubProject.uuid}`);
282 cy.get('[data-cy=side-panel-tree]').should('contain', testSubSubProject.name);
283 cy.get('[data-cy=breadcrumb-last]').should('contain', testSubSubProject.name);
284 cy.get('[data-cy=side-panel-tree]')
285 .contains(testSubProject.name)
287 cy.get('[data-cy=context-menu]').contains('Move to trash').click();
289 // Confirm that the trashed project's parent should be displayed.
290 cy.get('[data-cy=breadcrumb-last]').should('contain', testRootProject.name);
291 cy.url().should('contain', `/projects/${testRootProject.uuid}`);
292 cy.get('[data-cy=side-panel-tree]').should('not.contain', testSubProject.name);
293 cy.get('[data-cy=side-panel-tree]').should('not.contain', testSubSubProject.name);
295 // Checks for bugfix #17637.
296 cy.get('[data-cy=not-found-content]').should('not.exist');
297 cy.get('[data-cy=not-found-page]').should('not.exist');
301 it('shows details panel when clicking on the info icon', () => {
302 cy.createGroup(activeUser.token, {
303 name: `Test root project ${Math.floor(Math.random() * 999999)}`,
304 group_class: 'project',
305 }).as('testRootProject').then(function(testRootProject) {
306 cy.loginAs(activeUser);
308 cy.get('[data-cy=side-panel-tree]').contains(testRootProject.name).click();
310 cy.get('[data-cy=additional-info-icon]').click();
312 cy.contains(testRootProject.uuid).should('exist');
316 it('clears search input when changing project', () => {
317 cy.createGroup(activeUser.token, {
318 name: `Test root project ${Math.floor(Math.random() * 999999)}`,
319 group_class: 'project',
320 }).as('testProject1').then((testProject1) => {
321 cy.shareWith(adminUser.token, activeUser.user.uuid, testProject1.uuid, 'can_write');
324 cy.getAll('@testProject1').then(function([testProject1]) {
325 cy.loginAs(activeUser);
327 cy.get('[data-cy=side-panel-tree]').contains(testProject1.name).click();
329 cy.get('[data-cy=search-input] input').type('test123');
331 cy.get('[data-cy=side-panel-tree]').contains('Projects').click();
333 cy.get('[data-cy=search-input] input').should('not.have.value', 'test123');
337 it('opens advanced popup for project with username', () => {
338 const projectName = `Test project ${Math.floor(Math.random() * 999999)}`;
340 cy.createGroup(adminUser.token, {
342 group_class: 'project',
345 cy.getAll('@mainProject')
346 .then(function ([mainProject]) {
347 cy.loginAs(adminUser);
349 cy.get('[data-cy=side-panel-tree]').contains('Groups').click();
351 cy.get('[data-cy=uuid]').eq(0).invoke('text').then(uuid => {
352 cy.createLink(adminUser.token, {
354 link_class: 'permission',
355 head_uuid: mainProject.uuid,
359 cy.createLink(adminUser.token, {
361 link_class: 'permission',
362 head_uuid: mainProject.uuid,
363 tail_uuid: activeUser.user.uuid
366 cy.get('[data-cy=side-panel-tree]').contains('Projects').click();
368 cy.get('main').contains(projectName).rightclick();
370 cy.get('[data-cy=context-menu]').contains('API Details').click();
372 cy.get('[role=tablist]').contains('METADATA').click();
374 cy.get('td').contains(uuid).should('exist');
376 cy.get('td').contains(activeUser.user.uuid).should('exist');
381 describe('Frozen projects', () => {
383 cy.createGroup(activeUser.token, {
384 name: `Main project ${Math.floor(Math.random() * 999999)}`,
385 group_class: 'project',
386 }).as('mainProject');
388 cy.createGroup(adminUser.token, {
389 name: `Admin project ${Math.floor(Math.random() * 999999)}`,
390 group_class: 'project',
391 }).as('adminProject').then((mainProject) => {
392 cy.shareWith(adminUser.token, activeUser.user.uuid, mainProject.uuid, 'can_write');
395 cy.get('@mainProject').then((mainProject) => {
396 cy.createGroup(adminUser.token, {
397 name : `Sub project ${Math.floor(Math.random() * 999999)}`,
398 group_class: 'project',
399 owner_uuid: mainProject.uuid,
402 cy.createCollection(adminUser.token, {
403 name: `Main collection ${Math.floor(Math.random() * 999999)}`,
404 owner_uuid: mainProject.uuid,
405 manifest_text: "./subdir 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo\n. 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
406 }).as('mainCollection');
410 it('should be able to froze own project', () => {
411 cy.getAll('@mainProject').then(([mainProject]) => {
412 cy.loginAs(activeUser);
414 cy.get('[data-cy=project-panel]').contains(mainProject.name).rightclick();
416 cy.get('[data-cy=context-menu]').contains('Freeze').click();
418 cy.get('[data-cy=project-panel]').contains(mainProject.name).rightclick();
420 cy.get('[data-cy=context-menu]').contains('Freeze').should('not.exist');
424 it('should not be able to modify items within the frozen project', () => {
425 cy.getAll('@mainProject', '@mainCollection').then(([mainProject, mainCollection]) => {
426 cy.loginAs(activeUser);
428 cy.get('[data-cy=project-panel]').contains(mainProject.name).rightclick();
430 cy.get('[data-cy=context-menu]').contains('Freeze').click();
432 cy.get('[data-cy=project-panel]').contains(mainProject.name).click();
434 cy.get('[data-cy=project-panel]').contains(mainCollection.name).rightclick();
436 cy.get('[data-cy=context-menu]').contains('Move to trash').should('not.exist');
440 it('should be able to froze not owned project', () => {
441 cy.getAll('@adminProject').then(([adminProject]) => {
442 cy.loginAs(activeUser);
444 cy.get('[data-cy=side-panel-tree]').contains('Shared with me').click();
446 cy.get('main').contains(adminProject.name).rightclick();
448 cy.get('[data-cy=context-menu]').contains('Freeze').should('not.exist');
452 it('should be able to unfroze project if user is an admin', () => {
453 cy.getAll('@adminProject').then(([adminProject]) => {
454 cy.loginAs(adminUser);
456 cy.get('main').contains(adminProject.name).rightclick();
458 cy.get('[data-cy=context-menu]').contains('Freeze').click();
462 cy.get('main').contains(adminProject.name).rightclick();
464 cy.get('[data-cy=context-menu]').contains('Unfreeze').click();
466 cy.get('main').contains(adminProject.name).rightclick();
468 cy.get('[data-cy=context-menu]').contains('Freeze').should('exist');
473 it('copies project URL to clipboard', () => {
474 const projectName = `Test project (${Math.floor(999999 * Math.random())})`;
476 cy.loginAs(activeUser);
477 cy.get('[data-cy=side-panel-button]').click();
478 cy.get('[data-cy=side-panel-new-project]').click();
479 cy.get('[data-cy=form-dialog]')
480 .should('contain', 'New Project')
482 cy.get('[data-cy=name-field]').within(() => {
483 cy.get('input').type(projectName);
485 cy.get('[data-cy=form-submit-btn]').click();
488 cy.get('[data-cy=side-panel-tree]').contains('Projects').click();
489 cy.get('[data-cy=project-panel]').contains(projectName).rightclick();
490 cy.get('[data-cy=context-menu]').contains('Copy to clipboard').click();
491 cy.window().then((win) => (
492 win.navigator.clipboard.readText().then((text) => {
493 expect(text).to.match(/https\:\/\/localhost\:[0-9]+\/projects\/[a-z0-9]{5}-[a-z0-9]{5}-[a-z0-9]{15}/,);