18584: Adds Cypress test for collection copy action.
[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('makes a copy of an existing collection', function() {
599         const collName = `Test Collection ${Math.floor(Math.random() * 999999)}`;
600         const copyName = `Copy of: ${collName}`;
601
602         cy.createCollection(adminUser.token, {
603             name: collName,
604             owner_uuid: activeUser.user.uuid,
605             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:some-file\n",
606         }).as('collection').then(function () {
607             cy.loginAs(activeUser)
608             cy.goToPath(`/collections/${this.collection.uuid}`);
609             cy.get('[data-cy=collection-files-panel]')
610                 .should('contain', 'some-file');
611             cy.get('[data-cy=collection-panel-options-btn]').click();
612             cy.get('[data-cy=context-menu]').contains('Make a copy').click();
613             cy.get('[data-cy=form-dialog]')
614                 .should('contain', 'Make a copy')
615                 .within(() => {
616                     cy.get('[data-cy=projects-tree-home-tree-picker]')
617                         .contains('Projects')
618                         .click();
619                     cy.get('[data-cy=form-submit-btn]').click();
620                 });
621             cy.get('[data-cy=snackbar]')
622                 .contains('Collection has been copied.')
623             cy.get('[data-cy=snackbar-goto-action]').click();
624             cy.get('[data-cy=project-panel]')
625                 .contains(copyName).click();
626             cy.get('[data-cy=collection-files-panel]')
627                 .should('contain', 'some-file');
628         });
629     });
630
631     it('uses the collection version browser to view a previous version', function () {
632         const colName = `Test Collection ${Math.floor(Math.random() * 999999)}`;
633
634         // Creates the collection using the admin token so we can set up
635         // a bogus manifest text without block signatures.
636         cy.createCollection(adminUser.token, {
637             name: colName,
638             owner_uuid: activeUser.user.uuid,
639             preserve_version: true,
640             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo 0:3:bar\n"
641         })
642             .as('collection').then(function () {
643                 // Visit collection, check basic information
644                 cy.loginAs(activeUser)
645                 cy.goToPath(`/collections/${this.collection.uuid}`);
646
647                 cy.get('[data-cy=collection-info-panel]').should('not.contain', 'This is an old version');
648                 cy.get('[data-cy=read-only-icon]').should('not.exist');
649                 cy.get('[data-cy=collection-version-number]').should('contain', '1');
650                 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
651                 cy.get('[data-cy=collection-files-panel]').should('contain', 'foo').and('contain', 'bar');
652
653                 // Modify collection, expect version number change
654                 cy.get('[data-cy=collection-files-panel]').contains('foo').rightclick();
655                 cy.get('[data-cy=context-menu]').contains('Remove').click();
656                 cy.get('[data-cy=confirmation-dialog]').should('contain', 'Removing file');
657                 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
658                 cy.get('[data-cy=collection-version-number]').should('contain', '2');
659                 cy.get('[data-cy=collection-files-panel]').should('not.contain', 'foo').and('contain', 'bar');
660
661                 // Click on version number, check version browser. Click on past version.
662                 cy.get('[data-cy=collection-version-browser]').should('not.exist');
663                 cy.get('[data-cy=collection-version-number]').contains('2').click();
664                 cy.get('[data-cy=collection-version-browser]')
665                     .should('contain', 'Nr').and('contain', 'Size').and('contain', 'Date')
666                     .within(() => {
667                         // Version 1: 6 bytes in size
668                         cy.get('[data-cy=collection-version-browser-select-1]')
669                             .should('contain', '1')
670                             .and('contain', '6 B')
671                             .and('contain', adminUser.user.uuid);
672                         // Version 2: 3 bytes in size (one file removed)
673                         cy.get('[data-cy=collection-version-browser-select-2]')
674                             .should('contain', '2')
675                             .and('contain', '3 B')
676                             .and('contain', activeUser.user.full_name);
677                         cy.get('[data-cy=collection-version-browser-select-3]')
678                             .should('not.exist');
679                         cy.get('[data-cy=collection-version-browser-select-1]')
680                             .click();
681                     });
682                 cy.get('[data-cy=collection-info-panel]').should('contain', 'This is an old version');
683                 cy.get('[data-cy=read-only-icon]').should('exist');
684                 cy.get('[data-cy=collection-version-number]').should('contain', '1');
685                 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
686                 cy.get('[data-cy=collection-files-panel]')
687                     .should('contain', 'foo').and('contain', 'bar');
688
689                 // Check that only old collection action are available on context menu
690                 cy.get('[data-cy=collection-panel-options-btn]').click();
691                 cy.get('[data-cy=context-menu]')
692                     .should('contain', 'Restore version')
693                     .and('not.contain', 'Add to favorites');
694                 cy.get('body').click(); // Collapse the menu avoiding details panel expansion
695
696                 // Click on "head version" link, confirm that it's the latest version.
697                 cy.get('[data-cy=collection-info-panel]').contains('head version').click();
698                 cy.get('[data-cy=collection-info-panel]')
699                     .should('not.contain', 'This is an old version');
700                 cy.get('[data-cy=read-only-icon]').should('not.exist');
701                 cy.get('[data-cy=collection-version-number]').should('contain', '2');
702                 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
703                 cy.get('[data-cy=collection-files-panel]').
704                     should('not.contain', 'foo').and('contain', 'bar');
705
706                 // Check that old collection action isn't available on context menu
707                 cy.get('[data-cy=collection-panel-options-btn]').click()
708                 cy.get('[data-cy=context-menu]').should('not.contain', 'Restore version')
709                 cy.get('body').click(); // Collapse the menu avoiding details panel expansion
710
711                 // Make another change, confirm new version.
712                 cy.get('[data-cy=collection-panel-options-btn]').click();
713                 cy.get('[data-cy=context-menu]').contains('Edit collection').click();
714                 cy.get('[data-cy=form-dialog]')
715                     .should('contain', 'Edit Collection')
716                     .within(() => {
717                         // appends some text
718                         cy.get('input').first().type(' renamed');
719                     });
720                 cy.get('[data-cy=form-submit-btn]').click();
721                 cy.get('[data-cy=collection-info-panel]')
722                     .should('not.contain', 'This is an old version');
723                 cy.get('[data-cy=read-only-icon]').should('not.exist');
724                 cy.get('[data-cy=collection-version-number]').should('contain', '3');
725                 cy.get('[data-cy=collection-info-panel]').should('contain', colName + ' renamed');
726                 cy.get('[data-cy=collection-files-panel]')
727                     .should('not.contain', 'foo').and('contain', 'bar');
728                 cy.get('[data-cy=collection-version-browser-select-3]')
729                     .should('contain', '3').and('contain', '3 B');
730
731                 // Check context menus on version browser
732                 cy.get('[data-cy=collection-version-browser-select-3]').rightclick()
733                 cy.get('[data-cy=context-menu]')
734                     .should('contain', 'Add to favorites')
735                     .and('contain', 'Make a copy')
736                     .and('contain', 'Edit collection');
737                 cy.get('body').click();
738                 // (and now an old version...)
739                 cy.get('[data-cy=collection-version-browser-select-1]').rightclick()
740                 cy.get('[data-cy=context-menu]')
741                     .should('not.contain', 'Add to favorites')
742                     .and('contain', 'Make a copy')
743                     .and('not.contain', 'Edit collection');
744                 cy.get('body').click();
745
746                 // Restore first version
747                 cy.get('[data-cy=collection-version-browser]').within(() => {
748                     cy.get('[data-cy=collection-version-browser-select-1]').click();
749                 });
750                 cy.get('[data-cy=collection-panel-options-btn]').click()
751                 cy.get('[data-cy=context-menu]').contains('Restore version').click();
752                 cy.get('[data-cy=confirmation-dialog]').should('contain', 'Restore version');
753                 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
754                 cy.get('[data-cy=collection-info-panel]')
755                     .should('not.contain', 'This is an old version');
756                 cy.get('[data-cy=collection-version-number]').should('contain', '4');
757                 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
758                 cy.get('[data-cy=collection-files-panel]')
759                     .should('contain', 'foo').and('contain', 'bar');
760             });
761     });
762
763     it('creates new collection on home project', function () {
764         cy.loginAs(activeUser);
765         cy.goToPath(`/projects/${activeUser.user.uuid}`);
766         cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
767         cy.get('[data-cy=breadcrumb-last]').should('not.exist');
768         // Create new collection
769         cy.get('[data-cy=side-panel-button]').click();
770         cy.get('[data-cy=side-panel-new-collection]').click();
771         // Name between brackets tests bugfix #17582
772         const collName = `[Test collection (${Math.floor(999999 * Math.random())})]`;
773         cy.get('[data-cy=form-dialog]')
774             .should('contain', 'New collection')
775             .and('contain', 'Storage classes')
776             .and('contain', 'default')
777             .and('contain', 'foo')
778             .and('contain', 'bar')
779             .within(() => {
780                 cy.get('[data-cy=parent-field]').within(() => {
781                     cy.get('input').should('have.value', 'Home project');
782                 });
783                 cy.get('[data-cy=name-field]').within(() => {
784                     cy.get('input').type(collName);
785                 });
786                 cy.get('[data-cy=checkbox-foo]').click();
787             })
788         cy.get('[data-cy=form-submit-btn]').click();
789         // Confirm that the user was taken to the newly created thing
790         cy.get('[data-cy=form-dialog]').should('not.exist');
791         cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
792         cy.get('[data-cy=breadcrumb-last]').should('contain', collName);
793         cy.get('[data-cy=collection-info-panel]')
794             .should('contain', 'default')
795             .and('contain', 'foo')
796             .and('not.contain', 'bar');
797     });
798
799     it('shows responsible person for collection if available', () => {
800         cy.createCollection(adminUser.token, {
801             name: `Test collection ${Math.floor(Math.random() * 999999)}`,
802             owner_uuid: activeUser.user.uuid,
803             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
804         })
805             .as('testCollection1');
806
807         cy.createCollection(adminUser.token, {
808             name: `Test collection ${Math.floor(Math.random() * 999999)}`,
809             owner_uuid: adminUser.user.uuid,
810             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
811         })
812             .as('testCollection2').then(function (testCollection2) {
813                 cy.shareWith(adminUser.token, activeUser.user.uuid, testCollection2.uuid, 'can_write');
814             });
815
816         cy.getAll('@testCollection1', '@testCollection2')
817             .then(function ([testCollection1, testCollection2]) {
818                 cy.loginAs(activeUser);
819
820                 cy.goToPath(`/collections/${testCollection1.uuid}`);
821                 cy.get('[data-cy=responsible-person-wrapper]')
822                     .contains(activeUser.user.uuid);
823
824                 cy.goToPath(`/collections/${testCollection2.uuid}`);
825                 cy.get('[data-cy=responsible-person-wrapper]')
826                     .contains(adminUser.user.uuid);
827             });
828     });
829
830     describe('file upload', () => {
831         beforeEach(() => {
832             cy.createCollection(adminUser.token, {
833                 name: `Test collection ${Math.floor(Math.random() * 999999)}`,
834                 owner_uuid: activeUser.user.uuid,
835                 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
836             })
837                 .as('testCollection1');
838         });
839
840         it('allows to cancel running upload', () => {
841             cy.getAll('@testCollection1')
842                 .then(function([testCollection1]) {
843                     cy.loginAs(activeUser);
844
845                     cy.goToPath(`/collections/${testCollection1.uuid}`);
846
847                     cy.get('[data-cy=upload-button]').click();
848
849                     cy.fixture('files/5mb.bin', 'base64').then(content => {
850                         cy.get('[data-cy=drag-and-drop]').upload(content, '5mb_a.bin');
851                         cy.get('[data-cy=drag-and-drop]').upload(content, '5mb_b.bin');
852
853                         cy.get('[data-cy=form-submit-btn]').click();
854
855                         cy.get('button').contains('Cancel').click();
856
857                         cy.get('[data-cy=form-submit-btn]').should('not.exist');
858                     });
859                 });
860         });
861
862         it('allows to cancel single file from the running upload', () => {
863             cy.getAll('@testCollection1')
864                 .then(function([testCollection1]) {
865                     cy.loginAs(activeUser);
866
867                     cy.goToPath(`/collections/${testCollection1.uuid}`);
868
869                     cy.get('[data-cy=upload-button]').click();
870
871                     cy.fixture('files/5mb.bin', 'base64').then(content => {
872                         cy.get('[data-cy=drag-and-drop]').upload(content, '5mb_a.bin');
873                         cy.get('[data-cy=drag-and-drop]').upload(content, '5mb_b.bin');
874
875                         cy.get('[data-cy=form-submit-btn]').click();
876
877                         cy.get('button[aria-label=Remove]').eq(1).click();
878
879                         cy.get('[data-cy=form-submit-btn]').should('not.exist');
880
881                         cy.get('[data-cy=collection-files-panel]').contains('5mb_a.bin').should('exist');
882                     });
883                 });
884         });
885
886         it('allows to cancel all files from the running upload', () => {
887             cy.getAll('@testCollection1')
888                 .then(function([testCollection1]) {
889                     cy.loginAs(activeUser);
890
891                     cy.goToPath(`/collections/${testCollection1.uuid}`);
892
893                     cy.get('[data-cy=upload-button]').click();
894
895                     cy.fixture('files/5mb.bin', 'base64').then(content => {
896                         cy.get('[data-cy=drag-and-drop]').upload(content, '5mb_a.bin');
897                         cy.get('[data-cy=drag-and-drop]').upload(content, '5mb_b.bin');
898
899                         cy.get('[data-cy=form-submit-btn]').click();
900
901                         cy.get('button[aria-label=Remove]').click({ multiple: true });
902
903                         cy.get('[data-cy=form-submit-btn]').should('not.exist');
904                     });
905                 });
906         });
907     });
908 })