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