15685: Avoids the webdav service to report server error responses as success.
[arvados-workbench2.git] / cypress / integration / collection-panel.spec.js
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 describe('Collection 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('collectionuser1', 'Collection', '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('shows collection by URL', function() {
32         cy.loginAs(activeUser);
33         [true, false].map(function(isWritable) {
34             cy.createGroup(adminUser.token, {
35                 name: 'Shared project',
36                 group_class: 'project',
37             }).as('sharedGroup').then(function() {
38                 // Creates the collection using the admin token so we can set up
39                 // a bogus manifest text without block signatures.
40                 cy.createCollection(adminUser.token, {
41                     name: 'Test collection',
42                     owner_uuid: this.sharedGroup.uuid,
43                     properties: {someKey: 'someValue'},
44                     manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"})
45                 .as('testCollection').then(function() {
46                     // Share the group with active user.
47                     cy.createLink(adminUser.token, {
48                         name: isWritable ? 'can_write' : 'can_read',
49                         link_class: 'permission',
50                         head_uuid: this.sharedGroup.uuid,
51                         tail_uuid: activeUser.user.uuid
52                     })
53                     cy.visit(`/collections/${this.testCollection.uuid}`);
54                     // Check that name & uuid are correct.
55                     cy.get('[data-cy=collection-info-panel]')
56                         .should('contain', this.testCollection.name)
57                         .and('contain', this.testCollection.uuid);
58                     // Check for the read-only icon
59                     cy.get('[data-cy=read-only-icon]').should(`${isWritable ? 'not.' : ''}exist`);
60                     // Check that both read and write operations are available on
61                     // the 'More options' menu.
62                     cy.get('[data-cy=collection-panel-options-btn]')
63                         .click()
64                     cy.get('[data-cy=context-menu]')
65                         .should('contain', 'Add to favorites')
66                         .and(`${isWritable ? '' : 'not.'}contain`, 'Edit collection')
67                         .type('{esc}'); // Collapse the options menu
68                     cy.get('[data-cy=collection-properties-panel]')
69                         .should('contain', 'someKey')
70                         .and('contain', 'someValue')
71                         .and('not.contain', 'anotherKey')
72                         .and('not.contain', 'anotherValue')
73                     if (isWritable === true) {
74                         // Check that properties can be added.
75                         cy.get('[data-cy=collection-properties-form]').within(() => {
76                             cy.get('[data-cy=property-field-key]').within(() => {
77                                 cy.get('input').type('anotherKey');
78                             });
79                             cy.get('[data-cy=property-field-value]').within(() => {
80                                 cy.get('input').type('anotherValue');
81                             });
82                             cy.root().submit();
83                         })
84                         cy.get('[data-cy=collection-properties-panel]')
85                             .should('contain', 'anotherKey')
86                             .and('contain', 'anotherValue')
87                     } else {
88                         // Properties form shouldn't be displayed.
89                         cy.get('[data-cy=collection-properties-form]').should('not.exist');
90                     }
91                     // Check that the file listing show both read & write operations
92                     cy.get('[data-cy=collection-files-panel]').within(() => {
93                         cy.root().should('contain', 'bar');
94                         cy.get('[data-cy=upload-button]')
95                             .should(`${isWritable ? '' : 'not.'}contain`, 'Upload data');
96                     });
97                     // Hamburger 'more options' menu button
98                     cy.get('[data-cy=collection-files-panel-options-btn]')
99                         .click()
100                     cy.get('[data-cy=context-menu]')
101                         .should('contain', 'Select all')
102                         .click()
103                     cy.get('[data-cy=collection-files-panel-options-btn]')
104                         .click()
105                     cy.get('[data-cy=context-menu]')
106                         // .should('contain', 'Download selected')
107                         .should(`${isWritable ? '' : 'not.'}contain`, 'Remove selected')
108                         .type('{esc}'); // Collapse the options menu
109                     // File item 'more options' button
110                     cy.get('[data-cy=file-item-options-btn')
111                         .click()
112                     cy.get('[data-cy=context-menu]')
113                         .should('contain', 'Download')
114                         .and(`${isWritable ? '' : 'not.'}contain`, 'Remove')
115                         .type('{esc}'); // Collapse
116                 })
117             })
118         })
119     })
120
121     it('renames a file', function() {
122         // Creates the collection using the admin token so we can set up
123         // a bogus manifest text without block signatures.
124         cy.createCollection(adminUser.token, {
125             name: `Test collection ${Math.floor(Math.random() * Math.floor(999999))}`,
126             owner_uuid: activeUser.user.uuid,
127             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"})
128         .as('testCollection').then(function() {
129             cy.loginAs(activeUser);
130             cy.visit(`/collections/${this.testCollection.uuid}`);
131             cy.get('[data-cy=collection-files-panel]')
132                 .contains('bar').rightclick();
133             cy.get('[data-cy=context-menu]')
134                 .contains('Rename')
135                 .click();
136             cy.get('[data-cy=form-dialog]')
137                 .should('contain', 'Rename')
138                 .within(() => {
139                     cy.get('input').type('{backspace}{backspace}{backspace}foo');
140                 });
141             cy.get('[data-cy=form-submit-btn]').click();
142             cy.get('[data-cy=collection-files-panel]')
143                 .should('not.contain', 'bar')
144                 .and('contain', 'foo');
145         });
146     });
147
148     it('tries to rename a file with an illegal name', function() {
149         // Creates the collection using the admin token so we can set up
150         // a bogus manifest text without block signatures.
151         cy.createCollection(adminUser.token, {
152             name: `Test collection ${Math.floor(Math.random() * Math.floor(999999))}`,
153             owner_uuid: activeUser.user.uuid,
154             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"})
155         .as('testCollection').then(function() {
156             cy.loginAs(activeUser);
157             cy.visit(`/collections/${this.testCollection.uuid}`);
158             cy.get('[data-cy=collection-files-panel]')
159                 .contains('bar').rightclick();
160             cy.get('[data-cy=context-menu]')
161                 .contains('Rename')
162                 .click();
163             cy.get('[data-cy=form-dialog]')
164                 .should('contain', 'Rename')
165                 .within(() => {
166                     cy.get('input').type('{backspace}{backspace}{backspace}');
167                 });
168             cy.get('[data-cy=form-submit-btn]').click();
169             cy.get('[data-cy=form-dialog]')
170                 .should('contain', 'Rename')
171                 .within(() => {
172                     cy.contains('Could not rename');
173                 });
174         });
175     });
176 })