17637: Takes the user to the recently untrashed project.
[arvados.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('adds creates a new project with 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=resource-properties-form]').within(() => {
46             cy.get('[data-cy=property-field-key]').within(() => {
47                 cy.get('input').type('Color');
48             });
49             cy.get('[data-cy=property-field-value]').within(() => {
50                 cy.get('input').type('Magenta');
51             });
52             cy.root().submit();
53         });
54         // Confirm proper vocabulary labels are displayed on the UI.
55         cy.get('[data-cy=form-dialog]').should('contain', 'Color: Magenta');
56
57         // Create project and confirm the properties' real values.
58         cy.get('[data-cy=form-submit-btn]').click();
59         cy.get('[data-cy=breadcrumb-last]').should('contain', projName);
60         cy.doRequest('GET', '/arvados/v1/groups', null, {
61             filters: `[["name", "=", "${projName}"], ["group_class", "=", "project"]]`,
62         })
63         .its('body.items').as('projects')
64         .then(function() {
65             expect(this.projects).to.have.lengthOf(1);
66             expect(this.projects[0].properties).to.deep.equal(
67                 {IDTAGCOLORS: 'IDVALCOLORS3'});
68         });
69     });
70
71     it('creates new project on home project and then a subproject inside it', function() {
72         const createProject = function(name, parentName) {
73             cy.get('[data-cy=side-panel-button]').click();
74             cy.get('[data-cy=side-panel-new-project]').click();
75             cy.get('[data-cy=form-dialog]')
76                 .should('contain', 'New project')
77                 .within(() => {
78                     cy.get('[data-cy=parent-field]').within(() => {
79                         cy.get('input').invoke('val').then((val) => {
80                             expect(val).to.include(parentName);
81                         });
82                     });
83                     cy.get('[data-cy=name-field]').within(() => {
84                         cy.get('input').type(name);
85                     });
86                 });
87             cy.get('[data-cy=form-submit-btn]').click();
88         }
89
90         cy.loginAs(activeUser);
91         cy.goToPath(`/projects/${activeUser.user.uuid}`);
92         cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
93         cy.get('[data-cy=breadcrumb-last]').should('not.exist');
94         // Create new project
95         const projName = `Test project (${Math.floor(999999 * Math.random())})`;
96         createProject(projName, 'Home project');
97         // Confirm that the user was taken to the newly created thing
98         cy.get('[data-cy=form-dialog]').should('not.exist');
99         cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
100         cy.get('[data-cy=breadcrumb-last]').should('contain', projName);
101         // Create a subproject
102         const subProjName = `Test project (${Math.floor(999999 * Math.random())})`;
103         createProject(subProjName, projName);
104         cy.get('[data-cy=form-dialog]').should('not.exist');
105         cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
106         cy.get('[data-cy=breadcrumb-last]').should('contain', subProjName);
107     });
108
109     it('navigates to the parent project after trashing the one being displayed', function() {
110         cy.createGroup(activeUser.token, {
111             name: `Test root project ${Math.floor(Math.random() * 999999)}`,
112             group_class: 'project',
113         }).as('testRootProject').then(function() {
114             cy.createGroup(activeUser.token, {
115                 name : `Test subproject ${Math.floor(Math.random() * 999999)}`,
116                 group_class: 'project',
117                 owner_uuid: this.testRootProject.uuid,
118             }).as('testSubProject');
119         });
120         cy.getAll('@testRootProject', '@testSubProject').then(function([testRootProject, testSubProject]) {
121             cy.loginAs(activeUser);
122
123             // Go to subproject and trash it.
124             cy.goToPath(`/projects/${testSubProject.uuid}`);
125             cy.get('[data-cy=breadcrumb-last]').should('contain', testSubProject.name);
126             cy.get('[data-cy=breadcrumb-last]').rightclick();
127             cy.get('[data-cy=context-menu]').contains('Move to trash').click();
128
129             // Confirm that the parent project should be displayed.
130             cy.get('[data-cy=breadcrumb-last]').should('contain', testRootProject.name);
131             cy.url().should('contain', `/projects/${testRootProject.uuid}`);
132
133             // Checks for bugfix #17637.
134             cy.get('[data-cy=not-found-content]').should('not.exist');
135             cy.get('[data-cy=not-found-page]').should('not.exist');
136         });
137     });
138 })