Merge remote-tracking branch 'origin/main' into 18207-Workbench2-is-not-clearing...
[arvados-workbench2.git] / cypress / integration / collection.spec.js
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 const path = require('path');
6
7 describe('Collection panel tests', function () {
8     let activeUser;
9     let adminUser;
10     let downloadsFolder;
11
12     before(function () {
13         // Only set up common users once. These aren't set up as aliases because
14         // aliases are cleaned up after every test. Also it doesn't make sense
15         // to set the same users on beforeEach() over and over again, so we
16         // separate a little from Cypress' 'Best Practices' here.
17         cy.getUser('admin', 'Admin', 'User', true, true)
18             .as('adminUser').then(function () {
19                 adminUser = this.adminUser;
20             }
21             );
22         cy.getUser('collectionuser1', 'Collection', 'User', false, true)
23             .as('activeUser').then(function () {
24                 activeUser = this.activeUser;
25             }
26             );
27         downloadsFolder = Cypress.config('downloadsFolder');
28     });
29
30     beforeEach(function () {
31         cy.clearCookies();
32         cy.clearLocalStorage();
33     });
34
35     it('allows to download mountain duck config for a collection', () => {
36         cy.createCollection(adminUser.token, {
37             name: `Test collection ${Math.floor(Math.random() * 999999)}`,
38             owner_uuid: activeUser.user.uuid,
39             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
40         })
41         .as('testCollection').then(function (testCollection) {
42             cy.loginAs(activeUser);
43             cy.goToPath(`/collections/${testCollection.uuid}`);
44
45             cy.get('[data-cy=collection-panel-options-btn]').click();
46             cy.get('[data-cy=context-menu]').contains('Open with 3rd party client').click();
47             cy.get('[data-cy=download-button').click();
48
49             const filename = path.join(downloadsFolder, `${testCollection.name}.duck`);
50
51             cy.readFile(filename, { timeout: 15000 })
52                 .then((body) => {
53                     const childrenCollection = Array.prototype.slice.call(Cypress.$(body).find('dict')[0].children);
54                     const map = {};
55                     let i, j = 2;
56
57                     for (i=0; i < childrenCollection.length; i += j) {
58                       map[childrenCollection[i].outerText] = childrenCollection[i + 1].outerText;
59                     }
60
61                     cy.get('#simple-tabpanel-0').find('a')
62                         .then((a) => {
63                             const [host, port] = a.text().split('@')[1].split('/')[0].split(':');
64                             expect(map['Protocol']).to.equal('davs');
65                             expect(map['UUID']).to.equal(testCollection.uuid);
66                             expect(map['Username']).to.equal(activeUser.user.username);
67                             expect(map['Port']).to.equal(port);
68                             expect(map['Hostname']).to.equal(host);
69                             if (map['Path']) {
70                                 expect(map['Path']).to.equal(`/c=${testCollection.uuid}`);
71                             }
72                         });
73                 })
74                 .then(() => cy.task('clearDownload', { filename }));
75         });
76     });
77
78     it('uses the property editor with vocabulary terms', function () {
79         cy.createCollection(adminUser.token, {
80             name: `Test collection ${Math.floor(Math.random() * 999999)}`,
81             owner_uuid: activeUser.user.uuid,
82             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
83         })
84             .as('testCollection').then(function () {
85                 cy.loginAs(activeUser);
86                 cy.goToPath(`/collections/${this.testCollection.uuid}`);
87
88                 // Key: Color (IDTAGCOLORS) - Value: Magenta (IDVALCOLORS3)
89                 cy.get('[data-cy=resource-properties-form]').within(() => {
90                     cy.get('[data-cy=property-field-key]').within(() => {
91                         cy.get('input').type('Color');
92                     });
93                     cy.get('[data-cy=property-field-value]').within(() => {
94                         cy.get('input').type('Magenta');
95                     });
96                     cy.root().submit();
97                 });
98                 // Confirm proper vocabulary labels are displayed on the UI.
99                 cy.get('[data-cy=collection-properties-panel]')
100                     .should('contain', 'Color: Magenta');
101                 // Confirm proper vocabulary IDs were saved on the backend.
102                 cy.doRequest('GET', `/arvados/v1/collections/${this.testCollection.uuid}`)
103                     .its('body').as('collection')
104                     .then(function () {
105                         expect(this.collection.properties.IDTAGCOLORS).to.equal('IDVALCOLORS3');
106                     });
107
108                 // Case-insensitive on-blur auto-selection test
109                 // Key: Size (IDTAGSIZES) - Value: Small (IDVALSIZES2)
110                 cy.get('[data-cy=resource-properties-form]').within(() => {
111                     cy.get('[data-cy=property-field-key]').within(() => {
112                         cy.get('input').type('sIzE');
113                     });
114                     cy.get('[data-cy=property-field-value]').within(() => {
115                         cy.get('input').type('sMaLL');
116                     });
117                     // Cannot "type()" TAB on Cypress so let's click another field
118                     // to trigger the onBlur event.
119                     cy.get('[data-cy=property-field-key]').click();
120                     cy.root().submit();
121                 });
122                 // Confirm proper vocabulary labels are displayed on the UI.
123                 cy.get('[data-cy=collection-properties-panel]')
124                     .should('contain', 'Size: S');
125                 // Confirm proper vocabulary IDs were saved on the backend.
126                 cy.doRequest('GET', `/arvados/v1/collections/${this.testCollection.uuid}`)
127                     .its('body').as('collection')
128                     .then(function () {
129                         expect(this.collection.properties.IDTAGSIZES).to.equal('IDVALSIZES2');
130                     });
131             });
132     });
133
134     it('shows collection by URL', function () {
135         cy.loginAs(activeUser);
136         [true, false].map(function (isWritable) {
137             // Using different file names to avoid test flakyness: the second iteration
138             // on this loop may pass an assertion from the first iteration by looking
139             // for the same file name.
140             const fileName = isWritable ? 'bar' : 'foo';
141             const subDirName = 'subdir';
142             cy.createGroup(adminUser.token, {
143                 name: 'Shared project',
144                 group_class: 'project',
145             }).as('sharedGroup').then(function () {
146                 // Creates the collection using the admin token so we can set up
147                 // a bogus manifest text without block signatures.
148                 cy.doRequest('GET', '/arvados/v1/config', null, null)
149                     .its('body').should((clusterConfig) => {
150                       expect(clusterConfig.Collections, "clusterConfig").to.have.property("TrustAllContent", false);
151                       expect(clusterConfig.Services, "clusterConfig").to.have.property("WebDAV").have.property("ExternalURL");
152                       expect(clusterConfig.Services, "clusterConfig").to.have.property("WebDAVDownload").have.property("ExternalURL");
153                       const inlineUrl = clusterConfig.Services.WebDAV.ExternalURL !== ""
154                           ? clusterConfig.Services.WebDAV.ExternalURL
155                           : clusterConfig.Services.WebDAVDownload.ExternalURL;
156                       expect(inlineUrl).to.not.contain("*");
157                     })
158                     .createCollection(adminUser.token, {
159                       name: 'Test collection',
160                       owner_uuid: this.sharedGroup.uuid,
161                       properties: { someKey: 'someValue' },
162                       manifest_text: `. 37b51d194a7513e45b56f6524f2d51f2+3 0:3:${fileName}\n./${subDirName} 37b51d194a7513e45b56f6524f2d51f2+3 0:3:${fileName}\n`
163                     })
164                     .as('testCollection').then(function () {
165                         // Share the group with active user.
166                         cy.createLink(adminUser.token, {
167                             name: isWritable ? 'can_write' : 'can_read',
168                             link_class: 'permission',
169                             head_uuid: this.sharedGroup.uuid,
170                             tail_uuid: activeUser.user.uuid
171                         })
172                         cy.goToPath(`/collections/${this.testCollection.uuid}`);
173
174                         // Check that name & uuid are correct.
175                         cy.get('[data-cy=collection-info-panel]')
176                             .should('contain', this.testCollection.name)
177                             .and('contain', this.testCollection.uuid)
178                             .and('not.contain', 'This is an old version');
179                         // Check for the read-only icon
180                         cy.get('[data-cy=read-only-icon]').should(`${isWritable ? 'not.' : ''}exist`);
181                         // Check that both read and write operations are available on
182                         // the 'More options' menu.
183                         cy.get('[data-cy=collection-panel-options-btn]')
184                             .click()
185                         cy.get('[data-cy=context-menu]')
186                             .should('contain', 'Add to favorites')
187                             .and(`${isWritable ? '' : 'not.'}contain`, 'Edit collection');
188                         cy.get('body').click(); // Collapse the menu avoiding details panel expansion
189                         cy.get('[data-cy=collection-properties-panel]')
190                             .should('contain', 'someKey')
191                             .and('contain', 'someValue')
192                             .and('not.contain', 'anotherKey')
193                             .and('not.contain', 'anotherValue')
194                         if (isWritable === true) {
195                             // Check that properties can be added.
196                             cy.get('[data-cy=resource-properties-form]').within(() => {
197                                 cy.get('[data-cy=property-field-key]').within(() => {
198                                     cy.get('input').type('anotherKey');
199                                 });
200                                 cy.get('[data-cy=property-field-value]').within(() => {
201                                     cy.get('input').type('anotherValue');
202                                 });
203                                 cy.root().submit();
204                             })
205                             cy.get('[data-cy=collection-properties-panel]')
206                                 .should('contain', 'anotherKey')
207                                 .and('contain', 'anotherValue')
208                         } else {
209                             // Properties form shouldn't be displayed.
210                             cy.get('[data-cy=resource-properties-form]').should('not.exist');
211                         }
212                         // Check that the file listing show both read & write operations
213                         cy.get('[data-cy=collection-files-panel]').within(() => {
214                             cy.wait(1000);
215                             cy.root().should('contain', fileName);
216                             if (isWritable) {
217                                 cy.get('[data-cy=upload-button]')
218                                     .should(`${isWritable ? '' : 'not.'}contain`, 'Upload data');
219                             }
220                         });
221                         // Test context menus
222                         cy.get('[data-cy=collection-files-panel]')
223                             .contains(fileName).rightclick({ force: true });
224                         cy.get('[data-cy=context-menu]')
225                             .should('contain', 'Download')
226                             .and('not.contain', 'Open in new tab')
227                             .and('contain', 'Copy to clipboard')
228                             .and(`${isWritable ? '' : 'not.'}contain`, 'Rename')
229                             .and(`${isWritable ? '' : 'not.'}contain`, 'Remove');
230                         cy.get('body').click(); // Collapse the menu
231                         cy.get('[data-cy=collection-files-panel]')
232                             .contains(subDirName).rightclick({ force: true });
233                         cy.get('[data-cy=context-menu]')
234                             .should('not.contain', 'Download')
235                             .and('not.contain', 'Open in new tab')
236                             .and('contain', 'Copy to clipboard')
237                             .and(`${isWritable ? '' : 'not.'}contain`, 'Rename')
238                             .and(`${isWritable ? '' : 'not.'}contain`, 'Remove');
239                         cy.get('body').click(); // Collapse the menu
240                         // Hamburger 'more options' menu button
241                         cy.get('[data-cy=collection-files-panel-options-btn]')
242                             .click()
243                         cy.get('[data-cy=context-menu]')
244                             .should('contain', 'Select all')
245                             .click()
246                         cy.get('[data-cy=collection-files-panel-options-btn]')
247                             .click()
248                         cy.get('[data-cy=context-menu]')
249                             .should(`${isWritable ? '' : 'not.'}contain`, 'Remove selected')
250                         cy.get('body').click(); // Collapse the menu
251                     })
252             })
253         })
254     })
255
256     it('renames a file using valid names', function () {
257         function eachPair(lst, func){
258             for(var i=0; i < lst.length - 1; i++){
259                 func(lst[i], lst[i + 1])
260             }
261         }
262         // Creates the collection using the admin token so we can set up
263         // a bogus manifest text without block signatures.
264         cy.createCollection(adminUser.token, {
265             name: `Test collection ${Math.floor(Math.random() * 999999)}`,
266             owner_uuid: activeUser.user.uuid,
267             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
268         })
269             .as('testCollection').then(function () {
270                 cy.loginAs(activeUser);
271                 cy.goToPath(`/collections/${this.testCollection.uuid}`);
272
273                 const names = [
274                     'bar', // initial name already set
275                     '&',
276                     'foo',
277                     '&amp;',
278                     'I ❤️ ⛵️',
279                     '...',
280                     '#..',
281                     'some name with whitespaces',
282                     'some name with #2',
283                     'is this name legal? I hope it is',
284                     'some_file.pdf#',
285                     'some_file.pdf?',
286                     '?some_file.pdf',
287                     'some%file.pdf',
288                     'some%2Ffile.pdf',
289                     'some%22file.pdf',
290                     'some%20file.pdf',
291                     "G%C3%BCnter's%20file.pdf",
292                     'table%&?*2',
293                     'bar' // make sure we can go back to the original name as a last step
294                 ];
295                 eachPair(names, (from, to) => {
296                     cy.get('[data-cy=collection-files-panel]')
297                         .contains(`${from}`).rightclick();
298                     cy.get('[data-cy=context-menu]')
299                         .contains('Rename')
300                         .click();
301                     cy.get('[data-cy=form-dialog]')
302                         .should('contain', 'Rename')
303                         .within(() => {
304                             cy.get('input')
305                                 .type('{selectall}{backspace}')
306                                 .type(to, { parseSpecialCharSequences: false });
307                         });
308                     cy.get('[data-cy=form-submit-btn]').click();
309                     cy.get('[data-cy=collection-files-panel]')
310                         .should('not.contain', `${from}`)
311                         .and('contain', `${to}`);
312                 })
313             });
314     });
315
316     it.skip('renames a file to a different directory', function () {
317         // Creates the collection using the admin token so we can set up
318         // a bogus manifest text without block signatures.
319         cy.createCollection(adminUser.token, {
320             name: `Test collection ${Math.floor(Math.random() * 999999)}`,
321             owner_uuid: activeUser.user.uuid,
322             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
323         })
324             .as('testCollection').then(function () {
325                 cy.loginAs(activeUser);
326                 cy.goToPath(`/collections/${this.testCollection.uuid}`);
327
328                 ['subdir', 'G%C3%BCnter\'s%20file', 'table%&?*2'].forEach((subdir) => {
329                     cy.get('[data-cy=collection-files-panel]')
330                         .contains('bar').rightclick({force: true});
331                     cy.get('[data-cy=context-menu]')
332                         .contains('Rename')
333                         .click();
334                     cy.get('[data-cy=form-dialog]')
335                         .should('contain', 'Rename')
336                         .within(() => {
337                             cy.get('input').type(`{selectall}{backspace}${subdir}/foo`);
338                         });
339                     cy.get('[data-cy=form-submit-btn]').click();
340                     cy.get('[data-cy=collection-files-panel]')
341                         .should('not.contain', 'bar')
342                         .and('contain', subdir);
343                     // Look for the "arrow icon" and expand the "subdir" directory.
344                     cy.get('[data-cy=virtual-file-tree] > div > i').click();
345                     // Rename 'subdir/foo' to 'foo'
346                     cy.get('[data-cy=collection-files-panel]')
347                         .contains('foo').rightclick();
348                     cy.get('[data-cy=context-menu]')
349                         .contains('Rename')
350                         .click();
351                     cy.get('[data-cy=form-dialog]')
352                         .should('contain', 'Rename')
353                         .within(() => {
354                             cy.get('input')
355                                 .should('have.value', `${subdir}/foo`)
356                                 .type(`{selectall}{backspace}bar`);
357                         });
358                     cy.get('[data-cy=form-submit-btn]').click();
359                     cy.get('[data-cy=collection-files-panel]')
360                         .should('contain', subdir) // empty dir kept
361                         .and('contain', 'bar');
362
363                     cy.get('[data-cy=collection-files-panel]')
364                         .contains(subdir).rightclick();
365                     cy.get('[data-cy=context-menu]')
366                         .contains('Remove')
367                         .click();
368                     cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
369                 });
370             });
371     });
372
373     it('renames a file to a different directory', function () {
374         // Creates the collection using the admin token so we can set up
375         // a bogus manifest text without block signatures.
376         cy.createCollection(adminUser.token, {
377             name: `Test collection ${Math.floor(Math.random() * 999999)}`,
378             owner_uuid: activeUser.user.uuid,
379             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
380         })
381             .as('testCollection').then(function () {
382                 cy.loginAs(activeUser);
383                 cy.goToPath(`/collections/${this.testCollection.uuid}`);
384
385                 ['subdir', 'G%C3%BCnter\'s%20file', 'table%&?*2'].forEach((subdir) => {
386                     cy.get('[data-cy=collection-files-panel]')
387                         .contains('bar').rightclick({force: true});
388                     cy.get('[data-cy=context-menu]')
389                         .contains('Rename')
390                         .click();
391                     cy.get('[data-cy=form-dialog]')
392                         .should('contain', 'Rename')
393                         .within(() => {
394                             cy.get('input').type(`{selectall}{backspace}${subdir}/foo`);
395                         });
396                     cy.get('[data-cy=form-submit-btn]').click();
397                     cy.get('[data-cy=collection-files-panel]')
398                         .should('not.contain', 'bar')
399                         .and('contain', subdir);
400                     cy.wait(1000);
401                     cy.get('[data-cy=collection-files-panel]').contains(subdir).click();
402                     // Rename 'subdir/foo' to 'foo'
403                     cy.wait(1000);
404                     cy.get('[data-cy=collection-files-panel]')
405                         .contains('foo').rightclick();
406                     cy.get('[data-cy=context-menu]')
407                         .contains('Rename')
408                         .click();
409                     cy.get('[data-cy=form-dialog]')
410                         .should('contain', 'Rename')
411                         .within(() => {
412                             cy.get('input')
413                                 .should('have.value', `${subdir}/foo`)
414                                 .type(`{selectall}{backspace}bar`);
415                         });
416                     cy.get('[data-cy=form-submit-btn]').click();
417
418                     cy.wait(1000);
419                     cy.get('[data-cy=collection-files-panel]')
420                         .contains('Home')
421                         .click();
422
423                     cy.wait(2000);
424                     cy.get('[data-cy=collection-files-panel]')
425                         .should('contain', subdir) // empty dir kept
426                         .and('contain', 'bar');
427
428                     cy.get('[data-cy=collection-files-panel]')
429                         .contains(subdir).rightclick();
430                     cy.get('[data-cy=context-menu]')
431                         .contains('Remove')
432                         .click();
433                     cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
434                 });
435             });
436     });
437
438     it('tries to rename a file with illegal names', function () {
439         // Creates the collection using the admin token so we can set up
440         // a bogus manifest text without block signatures.
441         cy.createCollection(adminUser.token, {
442             name: `Test collection ${Math.floor(Math.random() * 999999)}`,
443             owner_uuid: activeUser.user.uuid,
444             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
445         })
446             .as('testCollection').then(function () {
447                 cy.loginAs(activeUser);
448                 cy.goToPath(`/collections/${this.testCollection.uuid}`);
449
450                 const illegalNamesFromUI = [
451                     ['.', "Name cannot be '.' or '..'"],
452                     ['..', "Name cannot be '.' or '..'"],
453                     ['', 'This field is required'],
454                     [' ', 'Leading/trailing whitespaces not allowed'],
455                     [' foo', 'Leading/trailing whitespaces not allowed'],
456                     ['foo ', 'Leading/trailing whitespaces not allowed'],
457                     ['//foo', 'Empty dir name not allowed']
458                 ]
459                 illegalNamesFromUI.forEach(([name, errMsg]) => {
460                     cy.get('[data-cy=collection-files-panel]')
461                         .contains('bar').rightclick();
462                     cy.get('[data-cy=context-menu]')
463                         .contains('Rename')
464                         .click();
465                     cy.get('[data-cy=form-dialog]')
466                         .should('contain', 'Rename')
467                         .within(() => {
468                             cy.get('input').type(`{selectall}{backspace}${name}`);
469                         });
470                     cy.get('[data-cy=form-dialog]')
471                         .should('contain', 'Rename')
472                         .within(() => {
473                             cy.contains(`${errMsg}`);
474                         });
475                     cy.get('[data-cy=form-cancel-btn]').click();
476                 })
477             });
478     });
479
480     it('can correctly display old versions', function () {
481         const colName = `Versioned Collection ${Math.floor(Math.random() * 999999)}`;
482         let colUuid = '';
483         let oldVersionUuid = '';
484         // Make sure no other collections with this name exist
485         cy.doRequest('GET', '/arvados/v1/collections', null, {
486             filters: `[["name", "=", "${colName}"]]`,
487             include_old_versions: true
488         })
489             .its('body.items').as('collections')
490             .then(function () {
491                 expect(this.collections).to.be.empty;
492             });
493         // Creates the collection using the admin token so we can set up
494         // a bogus manifest text without block signatures.
495         cy.createCollection(adminUser.token, {
496             name: colName,
497             owner_uuid: activeUser.user.uuid,
498             preserve_version: true,
499             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
500         })
501             .as('originalVersion').then(function () {
502                 // Change the file name to create a new version.
503                 cy.updateCollection(adminUser.token, this.originalVersion.uuid, {
504                     manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo\n"
505                 })
506                 colUuid = this.originalVersion.uuid;
507             });
508         // Confirm that there are 2 versions of the collection
509         cy.doRequest('GET', '/arvados/v1/collections', null, {
510             filters: `[["name", "=", "${colName}"]]`,
511             include_old_versions: true
512         })
513             .its('body.items').as('collections')
514             .then(function () {
515                 expect(this.collections).to.have.lengthOf(2);
516                 this.collections.map(function (aCollection) {
517                     expect(aCollection.current_version_uuid).to.equal(colUuid);
518                     if (aCollection.uuid !== aCollection.current_version_uuid) {
519                         oldVersionUuid = aCollection.uuid;
520                     }
521                 });
522                 // Check the old version displays as what it is.
523                 cy.loginAs(activeUser)
524                 cy.goToPath(`/collections/${oldVersionUuid}`);
525
526                 cy.get('[data-cy=collection-info-panel]').should('contain', 'This is an old version');
527                 cy.get('[data-cy=read-only-icon]').should('exist');
528                 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
529                 cy.get('[data-cy=collection-files-panel]').should('contain', 'bar');
530             });
531     });
532
533     it('views & edits storage classes data', function () {
534         const colName= `Test Collection ${Math.floor(Math.random() * 999999)}`;
535         cy.createCollection(adminUser.token, {
536             name: colName,
537             owner_uuid: activeUser.user.uuid,
538             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:some-file\n",
539         }).as('collection').then(function () {
540             expect(this.collection.storage_classes_desired).to.deep.equal(['default'])
541
542             cy.loginAs(activeUser)
543             cy.goToPath(`/collections/${this.collection.uuid}`);
544
545             // Initial check: it should show the 'default' storage class
546             cy.get('[data-cy=collection-info-panel]')
547                 .should('contain', 'Storage classes')
548                 .and('contain', 'default')
549                 .and('not.contain', 'foo')
550                 .and('not.contain', 'bar');
551             // Edit collection: add storage class 'foo'
552             cy.get('[data-cy=collection-panel-options-btn]').click();
553             cy.get('[data-cy=context-menu]').contains('Edit collection').click();
554             cy.get('[data-cy=form-dialog]')
555                 .should('contain', 'Edit Collection')
556                 .and('contain', 'Storage classes')
557                 .and('contain', 'default')
558                 .and('contain', 'foo')
559                 .and('contain', 'bar')
560                 .within(() => {
561                     cy.get('[data-cy=checkbox-foo]').click();
562                 });
563             cy.get('[data-cy=form-submit-btn]').click();
564             cy.get('[data-cy=collection-info-panel]')
565                 .should('contain', 'default')
566                 .and('contain', 'foo')
567                 .and('not.contain', 'bar');
568             cy.doRequest('GET', `/arvados/v1/collections/${this.collection.uuid}`)
569                 .its('body').as('updatedCollection')
570                 .then(function () {
571                     expect(this.updatedCollection.storage_classes_desired).to.deep.equal(['default', 'foo']);
572                 });
573             // Edit collection: remove storage class 'default'
574             cy.get('[data-cy=collection-panel-options-btn]').click();
575             cy.get('[data-cy=context-menu]').contains('Edit collection').click();
576             cy.get('[data-cy=form-dialog]')
577                 .should('contain', 'Edit Collection')
578                 .and('contain', 'Storage classes')
579                 .and('contain', 'default')
580                 .and('contain', 'foo')
581                 .and('contain', 'bar')
582                 .within(() => {
583                     cy.get('[data-cy=checkbox-default]').click();
584                 });
585             cy.get('[data-cy=form-submit-btn]').click();
586             cy.get('[data-cy=collection-info-panel]')
587                 .should('not.contain', 'default')
588                 .and('contain', 'foo')
589                 .and('not.contain', 'bar');
590             cy.doRequest('GET', `/arvados/v1/collections/${this.collection.uuid}`)
591                 .its('body').as('updatedCollection')
592                 .then(function () {
593                     expect(this.updatedCollection.storage_classes_desired).to.deep.equal(['foo']);
594                 });
595         })
596     });
597
598     it('moves a collection to a different project', function () {
599         const collName = `Test Collection ${Math.floor(Math.random() * 999999)}`;
600         const projName = `Test Project ${Math.floor(Math.random() * 999999)}`;
601         const fileName = `Test_File_${Math.floor(Math.random() * 999999)}`;
602
603         cy.createCollection(adminUser.token, {
604             name: collName,
605             owner_uuid: activeUser.user.uuid,
606             manifest_text: `. 37b51d194a7513e45b56f6524f2d51f2+3 0:3:${fileName}\n`,
607         }).as('testCollection');
608         cy.createGroup(adminUser.token, {
609             name: projName,
610             group_class: 'project',
611             owner_uuid: activeUser.user.uuid,
612         }).as('testProject');
613
614         cy.getAll('@testCollection', '@testProject')
615             .then(function ([testCollection, testProject]) {
616                 cy.loginAs(activeUser);
617                 cy.goToPath(`/collections/${testCollection.uuid}`);
618                 cy.get('[data-cy=collection-files-panel]').should('contain', fileName);
619                 cy.get('[data-cy=collection-info-panel]')
620                     .should('not.contain', projName)
621                     .and('not.contain', testProject.uuid);
622                 cy.get('[data-cy=collection-panel-options-btn]').click();
623                 cy.get('[data-cy=context-menu]').contains('Move to').click();
624                 cy.get('[data-cy=form-dialog]')
625                     .should('contain', 'Move to')
626                     .within(() => {
627                         cy.get('[data-cy=projects-tree-home-tree-picker]')
628                             .find('i')
629                             .click();
630                         cy.get('[data-cy=projects-tree-home-tree-picker]')
631                             .contains(projName)
632                             .click();
633                     });
634                 cy.get('[data-cy=form-submit-btn]').click();
635                 cy.get('[data-cy=snackbar]')
636                     .contains('Collection has been moved')
637                 cy.get('[data-cy=collection-info-panel]')
638                     .contains(projName).and('contain', testProject.uuid);
639                 // Double check that the collection is in the project
640                 cy.goToPath(`/projects/${testProject.uuid}`);
641                 cy.get('[data-cy=project-panel]').should('contain', collName);
642             });
643     });
644
645     it('makes a copy of an existing collection', function() {
646         const collName = `Test Collection ${Math.floor(Math.random() * 999999)}`;
647         const copyName = `Copy of: ${collName}`;
648
649         cy.createCollection(adminUser.token, {
650             name: collName,
651             owner_uuid: activeUser.user.uuid,
652             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:some-file\n",
653         }).as('collection').then(function () {
654             cy.loginAs(activeUser)
655             cy.goToPath(`/collections/${this.collection.uuid}`);
656             cy.get('[data-cy=collection-files-panel]')
657                 .should('contain', 'some-file');
658             cy.get('[data-cy=collection-panel-options-btn]').click();
659             cy.get('[data-cy=context-menu]').contains('Make a copy').click();
660             cy.get('[data-cy=form-dialog]')
661                 .should('contain', 'Make a copy')
662                 .within(() => {
663                     cy.get('[data-cy=projects-tree-home-tree-picker]')
664                         .contains('Projects')
665                         .click();
666                     cy.get('[data-cy=form-submit-btn]').click();
667                 });
668             cy.get('[data-cy=snackbar]')
669                 .contains('Collection has been copied.')
670             cy.get('[data-cy=snackbar-goto-action]').click();
671             cy.get('[data-cy=project-panel]')
672                 .contains(copyName).click();
673             cy.get('[data-cy=collection-files-panel]')
674                 .should('contain', 'some-file');
675         });
676     });
677
678     it('uses the collection version browser to view a previous version', function () {
679         const colName = `Test Collection ${Math.floor(Math.random() * 999999)}`;
680
681         // Creates the collection using the admin token so we can set up
682         // a bogus manifest text without block signatures.
683         cy.createCollection(adminUser.token, {
684             name: colName,
685             owner_uuid: activeUser.user.uuid,
686             preserve_version: true,
687             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo 0:3:bar\n"
688         })
689             .as('collection').then(function () {
690                 // Visit collection, check basic information
691                 cy.loginAs(activeUser)
692                 cy.goToPath(`/collections/${this.collection.uuid}`);
693
694                 cy.get('[data-cy=collection-info-panel]').should('not.contain', 'This is an old version');
695                 cy.get('[data-cy=read-only-icon]').should('not.exist');
696                 cy.get('[data-cy=collection-version-number]').should('contain', '1');
697                 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
698                 cy.get('[data-cy=collection-files-panel]').should('contain', 'foo').and('contain', 'bar');
699
700                 // Modify collection, expect version number change
701                 cy.get('[data-cy=collection-files-panel]').contains('foo').rightclick();
702                 cy.get('[data-cy=context-menu]').contains('Remove').click();
703                 cy.get('[data-cy=confirmation-dialog]').should('contain', 'Removing file');
704                 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
705                 cy.get('[data-cy=collection-version-number]').should('contain', '2');
706                 cy.get('[data-cy=collection-files-panel]').should('not.contain', 'foo').and('contain', 'bar');
707
708                 // Click on version number, check version browser. Click on past version.
709                 cy.get('[data-cy=collection-version-browser]').should('not.exist');
710                 cy.get('[data-cy=collection-version-number]').contains('2').click();
711                 cy.get('[data-cy=collection-version-browser]')
712                     .should('contain', 'Nr').and('contain', 'Size').and('contain', 'Date')
713                     .within(() => {
714                         // Version 1: 6 bytes in size
715                         cy.get('[data-cy=collection-version-browser-select-1]')
716                             .should('contain', '1')
717                             .and('contain', '6 B')
718                             .and('contain', adminUser.user.uuid);
719                         // Version 2: 3 bytes in size (one file removed)
720                         cy.get('[data-cy=collection-version-browser-select-2]')
721                             .should('contain', '2')
722                             .and('contain', '3 B')
723                             .and('contain', activeUser.user.full_name);
724                         cy.get('[data-cy=collection-version-browser-select-3]')
725                             .should('not.exist');
726                         cy.get('[data-cy=collection-version-browser-select-1]')
727                             .click();
728                     });
729                 cy.get('[data-cy=collection-info-panel]').should('contain', 'This is an old version');
730                 cy.get('[data-cy=read-only-icon]').should('exist');
731                 cy.get('[data-cy=collection-version-number]').should('contain', '1');
732                 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
733                 cy.get('[data-cy=collection-files-panel]')
734                     .should('contain', 'foo').and('contain', 'bar');
735
736                 // Check that only old collection action are available on context menu
737                 cy.get('[data-cy=collection-panel-options-btn]').click();
738                 cy.get('[data-cy=context-menu]')
739                     .should('contain', 'Restore version')
740                     .and('not.contain', 'Add to favorites');
741                 cy.get('body').click(); // Collapse the menu avoiding details panel expansion
742
743                 // Click on "head version" link, confirm that it's the latest version.
744                 cy.get('[data-cy=collection-info-panel]').contains('head version').click();
745                 cy.get('[data-cy=collection-info-panel]')
746                     .should('not.contain', 'This is an old version');
747                 cy.get('[data-cy=read-only-icon]').should('not.exist');
748                 cy.get('[data-cy=collection-version-number]').should('contain', '2');
749                 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
750                 cy.get('[data-cy=collection-files-panel]').
751                     should('not.contain', 'foo').and('contain', 'bar');
752
753                 // Check that old collection action isn't available on context menu
754                 cy.get('[data-cy=collection-panel-options-btn]').click()
755                 cy.get('[data-cy=context-menu]').should('not.contain', 'Restore version')
756                 cy.get('body').click(); // Collapse the menu avoiding details panel expansion
757
758                 // Make another change, confirm new version.
759                 cy.get('[data-cy=collection-panel-options-btn]').click();
760                 cy.get('[data-cy=context-menu]').contains('Edit collection').click();
761                 cy.get('[data-cy=form-dialog]')
762                     .should('contain', 'Edit Collection')
763                     .within(() => {
764                         // appends some text
765                         cy.get('input').first().type(' renamed');
766                     });
767                 cy.get('[data-cy=form-submit-btn]').click();
768                 cy.get('[data-cy=collection-info-panel]')
769                     .should('not.contain', 'This is an old version');
770                 cy.get('[data-cy=read-only-icon]').should('not.exist');
771                 cy.get('[data-cy=collection-version-number]').should('contain', '3');
772                 cy.get('[data-cy=collection-info-panel]').should('contain', colName + ' renamed');
773                 cy.get('[data-cy=collection-files-panel]')
774                     .should('not.contain', 'foo').and('contain', 'bar');
775                 cy.get('[data-cy=collection-version-browser-select-3]')
776                     .should('contain', '3').and('contain', '3 B');
777
778                 // Check context menus on version browser
779                 cy.get('[data-cy=collection-version-browser-select-3]').rightclick()
780                 cy.get('[data-cy=context-menu]')
781                     .should('contain', 'Add to favorites')
782                     .and('contain', 'Make a copy')
783                     .and('contain', 'Edit collection');
784                 cy.get('body').click();
785                 // (and now an old version...)
786                 cy.get('[data-cy=collection-version-browser-select-1]').rightclick()
787                 cy.get('[data-cy=context-menu]')
788                     .should('not.contain', 'Add to favorites')
789                     .and('contain', 'Make a copy')
790                     .and('not.contain', 'Edit collection');
791                 cy.get('body').click();
792
793                 // Restore first version
794                 cy.get('[data-cy=collection-version-browser]').within(() => {
795                     cy.get('[data-cy=collection-version-browser-select-1]').click();
796                 });
797                 cy.get('[data-cy=collection-panel-options-btn]').click()
798                 cy.get('[data-cy=context-menu]').contains('Restore version').click();
799                 cy.get('[data-cy=confirmation-dialog]').should('contain', 'Restore version');
800                 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
801                 cy.get('[data-cy=collection-info-panel]')
802                     .should('not.contain', 'This is an old version');
803                 cy.get('[data-cy=collection-version-number]').should('contain', '4');
804                 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
805                 cy.get('[data-cy=collection-files-panel]')
806                     .should('contain', 'foo').and('contain', 'bar');
807             });
808     });
809
810     it('creates new collection on home project', function () {
811         cy.loginAs(activeUser);
812         cy.goToPath(`/projects/${activeUser.user.uuid}`);
813         cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
814         cy.get('[data-cy=breadcrumb-last]').should('not.exist');
815         // Create new collection
816         cy.get('[data-cy=side-panel-button]').click();
817         cy.get('[data-cy=side-panel-new-collection]').click();
818         // Name between brackets tests bugfix #17582
819         const collName = `[Test collection (${Math.floor(999999 * Math.random())})]`;
820         cy.get('[data-cy=form-dialog]')
821             .should('contain', 'New collection')
822             .and('contain', 'Storage classes')
823             .and('contain', 'default')
824             .and('contain', 'foo')
825             .and('contain', 'bar')
826             .within(() => {
827                 cy.get('[data-cy=parent-field]').within(() => {
828                     cy.get('input').should('have.value', 'Home project');
829                 });
830                 cy.get('[data-cy=name-field]').within(() => {
831                     cy.get('input').type(collName);
832                 });
833                 cy.get('[data-cy=checkbox-foo]').click();
834             })
835         cy.get('[data-cy=form-submit-btn]').click();
836         // Confirm that the user was taken to the newly created thing
837         cy.get('[data-cy=form-dialog]').should('not.exist');
838         cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
839         cy.get('[data-cy=breadcrumb-last]').should('contain', collName);
840         cy.get('[data-cy=collection-info-panel]')
841             .should('contain', 'default')
842             .and('contain', 'foo')
843             .and('not.contain', 'bar');
844     });
845
846     it('shows responsible person for collection if available', () => {
847         cy.createCollection(adminUser.token, {
848             name: `Test collection ${Math.floor(Math.random() * 999999)}`,
849             owner_uuid: activeUser.user.uuid,
850             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
851         })
852             .as('testCollection1');
853
854         cy.createCollection(adminUser.token, {
855             name: `Test collection ${Math.floor(Math.random() * 999999)}`,
856             owner_uuid: adminUser.user.uuid,
857             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
858         })
859             .as('testCollection2').then(function (testCollection2) {
860                 cy.shareWith(adminUser.token, activeUser.user.uuid, testCollection2.uuid, 'can_write');
861             });
862
863         cy.getAll('@testCollection1', '@testCollection2')
864             .then(function ([testCollection1, testCollection2]) {
865                 cy.loginAs(activeUser);
866
867                 cy.goToPath(`/collections/${testCollection1.uuid}`);
868                 cy.get('[data-cy=responsible-person-wrapper]')
869                     .contains(activeUser.user.uuid);
870
871                 cy.goToPath(`/collections/${testCollection2.uuid}`);
872                 cy.get('[data-cy=responsible-person-wrapper]')
873                     .contains(adminUser.user.uuid);
874             });
875     });
876
877     describe('file upload', () => {
878         beforeEach(() => {
879             cy.createCollection(adminUser.token, {
880                 name: `Test collection ${Math.floor(Math.random() * 999999)}`,
881                 owner_uuid: activeUser.user.uuid,
882                 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
883             })
884                 .as('testCollection1');
885         });
886
887         it('allows to cancel running upload', () => {
888             cy.getAll('@testCollection1')
889                 .then(function([testCollection1]) {
890                     cy.loginAs(activeUser);
891
892                     cy.goToPath(`/collections/${testCollection1.uuid}`);
893
894                     cy.get('[data-cy=upload-button]').click();
895
896                     cy.fixture('files/5mb.bin', 'base64').then(content => {
897                         cy.get('[data-cy=drag-and-drop]').upload(content, '5mb_a.bin');
898                         cy.get('[data-cy=drag-and-drop]').upload(content, '5mb_b.bin');
899
900                         cy.get('[data-cy=form-submit-btn]').click();
901
902                         cy.get('button').contains('Cancel').click();
903
904                         cy.get('[data-cy=form-submit-btn]').should('not.exist');
905                     });
906                 });
907         });
908
909         it('allows to cancel single file from the running upload', () => {
910             cy.getAll('@testCollection1')
911                 .then(function([testCollection1]) {
912                     cy.loginAs(activeUser);
913
914                     cy.goToPath(`/collections/${testCollection1.uuid}`);
915
916                     cy.get('[data-cy=upload-button]').click();
917
918                     cy.fixture('files/5mb.bin', 'base64').then(content => {
919                         cy.get('[data-cy=drag-and-drop]').upload(content, '5mb_a.bin');
920                         cy.get('[data-cy=drag-and-drop]').upload(content, '5mb_b.bin');
921
922                         cy.get('[data-cy=form-submit-btn]').click();
923
924                         cy.get('button[aria-label=Remove]').eq(1).click();
925
926                         cy.get('[data-cy=form-submit-btn]').should('not.exist');
927
928                         cy.get('[data-cy=collection-files-panel]').contains('5mb_a.bin').should('exist');
929                     });
930                 });
931         });
932
933         it('allows to cancel all files from the running upload', () => {
934             cy.getAll('@testCollection1')
935                 .then(function([testCollection1]) {
936                     cy.loginAs(activeUser);
937
938                     cy.goToPath(`/collections/${testCollection1.uuid}`);
939
940                     cy.get('[data-cy=upload-button]').click();
941
942                     cy.fixture('files/5mb.bin', 'base64').then(content => {
943                         cy.get('[data-cy=drag-and-drop]').upload(content, '5mb_a.bin');
944                         cy.get('[data-cy=drag-and-drop]').upload(content, '5mb_b.bin');
945
946                         cy.get('[data-cy=form-submit-btn]').click();
947
948                         cy.get('button[aria-label=Remove]').should('exist');
949                         cy.get('button[aria-label=Remove]').click({ multiple: true, force: true });
950
951                         cy.get('[data-cy=form-submit-btn]').should('not.exist');
952                     });
953                 });
954         });
955     });
956 })