Merge branch '16439-objects-creation-placement-fix-tests'
[arvados-workbench2.git] / cypress / integration / side-panel.spec.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     beforeEach(function() {
27         cy.clearCookies()
28         cy.clearLocalStorage()
29     })
30
31     it('enables the +NEW side panel button on users home project', function() {
32         cy.loginAs(activeUser);
33         cy.visit(`/projects/${activeUser.user.uuid}`);
34         cy.get('[data-cy=side-panel-button]')
35             .should('exist')
36             .and('not.be.disabled');
37     })
38
39     it('disables or enables the +NEW side panel button on depending on project permissions', function() {
40         cy.loginAs(activeUser);
41         [true, false].map(function(isWritable) {
42             cy.createGroup(adminUser.token, {
43                 name: `Test ${isWritable ? 'writable' : 'read-only'} project`,
44                 group_class: 'project',
45             }).as('sharedGroup').then(function() {
46                 cy.createLink(adminUser.token, {
47                     name: isWritable ? 'can_write' : 'can_read',
48                     link_class: 'permission',
49                     head_uuid: this.sharedGroup.uuid,
50                     tail_uuid: activeUser.user.uuid
51                 })
52                 cy.visit(`/projects/${this.sharedGroup.uuid}`);
53                 cy.get('[data-cy=side-panel-button]')
54                     .should('exist')
55                     .and(`${isWritable ? 'not.' : ''}be.disabled`);
56             })
57         })
58     })
59
60     it('disables the +NEW side panel button on appropriate sections', function() {
61         cy.loginAs(activeUser);
62         [
63             {url: '/shared-with-me', label: 'Shared with me'},
64             {url: '/public-favorites', label: 'Public Favorites'},
65             {url: '/favorites', label: 'My Favorites'},
66             {url: '/workflows', label: 'Workflows'},
67             {url: '/all_processes', label: 'All Processes'},
68             {url: '/trash', label: 'Trash'},
69         ].map(function(section) {
70             cy.visit(section.url);
71             cy.get('[data-cy=breadcrumb-first]')
72                 .should('contain', section.label);
73             cy.get('[data-cy=side-panel-button]')
74                 .should('exist')
75                 .and('be.disabled');
76         })
77     })
78
79     it('creates new collection on home project', function() {
80         cy.loginAs(activeUser);
81         cy.visit(`/projects/${activeUser.user.uuid}`);
82         cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
83         cy.get('[data-cy=breadcrumb-last]').should('not.exist');
84         // Create new collection
85         cy.get('[data-cy=side-panel-button]').click();
86         cy.get('[data-cy=side-panel-new-collection]').click();
87         const collName = `Test collection (${Math.floor(999999 * Math.random())})`;
88         cy.get('[data-cy=form-dialog]')
89             .should('contain', 'New collection')
90             .within(() => {
91                 cy.get('[data-cy=parent-field]').within(() => {
92                     cy.get('input').should('have.value', 'Home project');
93                 })
94                 cy.get('[data-cy=name-field]').within(() => {
95                     cy.get('input').type(collName);
96                 })
97             })
98         cy.get('[data-cy=form-submit-btn]').click();
99         // Confirm that the user was taken to the newly created thing
100         cy.get('[data-cy=form-dialog]').should('not.exist');
101         cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
102         cy.get('[data-cy=breadcrumb-last]').should('contain', collName);
103     })
104
105     it('creates new project on home project and then a subproject inside it', function() {
106         const createProject = function(name, parentName) {
107             cy.get('[data-cy=side-panel-button]').click();
108             cy.get('[data-cy=side-panel-new-project]').click();
109             cy.get('[data-cy=form-dialog]')
110                 .should('contain', 'New project')
111                 .within(() => {
112                     cy.get('[data-cy=parent-field]').within(() => {
113                         cy.get('input').invoke('val').then((val) => {
114                             expect(val).to.include(parentName);
115                         })
116                     })
117                     cy.get('[data-cy=name-field]').within(() => {
118                         cy.get('input').type(name);
119                     })
120                 })
121             cy.get('[data-cy=form-submit-btn]').click();
122         }
123
124         cy.loginAs(activeUser);
125         cy.visit(`/projects/${activeUser.user.uuid}`);
126         cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
127         cy.get('[data-cy=breadcrumb-last]').should('not.exist');
128         // Create new project
129         const projName = `Test project (${Math.floor(999999 * Math.random())})`;
130         createProject(projName, 'Home project');
131         // Confirm that the user was taken to the newly created thing
132         cy.get('[data-cy=form-dialog]').should('not.exist');
133         cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
134         cy.get('[data-cy=breadcrumb-last]').should('contain', projName);
135         // Create a subproject
136         const subProjName = `Test project (${Math.floor(999999 * Math.random())})`;
137         createProject(subProjName, projName);
138         cy.get('[data-cy=form-dialog]').should('not.exist');
139         cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
140         cy.get('[data-cy=breadcrumb-last]').should('contain', subProjName);
141     })
142 })