0b06e53e1ab868fc71bec1b44c9425b3b168d0cd
[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.waitForDom().get('[data-cy=collection-files-panel]').within(() => {
255                             cy.get('[data-cy=collection-files-right-panel]', { timeout: 5000 })
256                                 .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();
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();
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.waitForDom().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();
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.get('[data-cy=collection-files-panel]').contains(subdir).click();
385
386                     // Rename 'subdir/foo' to 'bar'
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.get('[data-cy=collection-files-panel]')
403                         .contains('Home')
404                         .click();
405
406                     cy.wait(2000);
407                     cy.get('[data-cy=collection-files-panel]')
408                         .should('contain', subdir) // empty dir kept
409                         .and('contain', 'bar');
410
411                     cy.get('[data-cy=collection-files-panel]')
412                         .contains(subdir).rightclick();
413                     cy.get('[data-cy=context-menu]')
414                         .contains('Remove')
415                         .click();
416                     cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
417                 });
418             });
419     });
420
421     it('tries to rename a file with illegal names', function () {
422         // Creates the collection using the admin token so we can set up
423         // a bogus manifest text without block signatures.
424         cy.createCollection(adminUser.token, {
425             name: `Test collection ${Math.floor(Math.random() * 999999)}`,
426             owner_uuid: activeUser.user.uuid,
427             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
428         })
429             .as('testCollection').then(function () {
430                 cy.loginAs(activeUser);
431                 cy.goToPath(`/collections/${this.testCollection.uuid}`);
432
433                 const illegalNamesFromUI = [
434                     ['.', "Name cannot be '.' or '..'"],
435                     ['..', "Name cannot be '.' or '..'"],
436                     ['', 'This field is required'],
437                     [' ', 'Leading/trailing whitespaces not allowed'],
438                     [' foo', 'Leading/trailing whitespaces not allowed'],
439                     ['foo ', 'Leading/trailing whitespaces not allowed'],
440                     ['//foo', 'Empty dir name not allowed']
441                 ]
442                 illegalNamesFromUI.forEach(([name, errMsg]) => {
443                     cy.get('[data-cy=collection-files-panel]')
444                         .contains('bar').rightclick();
445                     cy.get('[data-cy=context-menu]')
446                         .contains('Rename')
447                         .click();
448                     cy.get('[data-cy=form-dialog]')
449                         .should('contain', 'Rename')
450                         .within(() => {
451                             cy.get('input').type(`{selectall}{backspace}${name}`);
452                         });
453                     cy.get('[data-cy=form-dialog]')
454                         .should('contain', 'Rename')
455                         .within(() => {
456                             cy.contains(`${errMsg}`);
457                         });
458                     cy.get('[data-cy=form-cancel-btn]').click();
459                 })
460             });
461     });
462
463     it('can correctly display old versions', function () {
464         const colName = `Versioned Collection ${Math.floor(Math.random() * 999999)}`;
465         let colUuid = '';
466         let oldVersionUuid = '';
467         // Make sure no other collections with this name exist
468         cy.doRequest('GET', '/arvados/v1/collections', null, {
469             filters: `[["name", "=", "${colName}"]]`,
470             include_old_versions: true
471         })
472             .its('body.items').as('collections')
473             .then(function () {
474                 expect(this.collections).to.be.empty;
475             });
476         // Creates the collection using the admin token so we can set up
477         // a bogus manifest text without block signatures.
478         cy.createCollection(adminUser.token, {
479             name: colName,
480             owner_uuid: activeUser.user.uuid,
481             preserve_version: true,
482             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
483         })
484             .as('originalVersion').then(function () {
485                 // Change the file name to create a new version.
486                 cy.updateCollection(adminUser.token, this.originalVersion.uuid, {
487                     manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo\n"
488                 })
489                 colUuid = this.originalVersion.uuid;
490             });
491         // Confirm that there are 2 versions of the collection
492         cy.doRequest('GET', '/arvados/v1/collections', null, {
493             filters: `[["name", "=", "${colName}"]]`,
494             include_old_versions: true
495         })
496             .its('body.items').as('collections')
497             .then(function () {
498                 expect(this.collections).to.have.lengthOf(2);
499                 this.collections.map(function (aCollection) {
500                     expect(aCollection.current_version_uuid).to.equal(colUuid);
501                     if (aCollection.uuid !== aCollection.current_version_uuid) {
502                         oldVersionUuid = aCollection.uuid;
503                     }
504                 });
505                 // Check the old version displays as what it is.
506                 cy.loginAs(activeUser)
507                 cy.goToPath(`/collections/${oldVersionUuid}`);
508
509                 cy.get('[data-cy=collection-info-panel]').should('contain', 'This is an old version');
510                 cy.get('[data-cy=read-only-icon]').should('exist');
511                 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
512                 cy.get('[data-cy=collection-files-panel]').should('contain', 'bar');
513             });
514     });
515
516     it('views & edits storage classes data', function () {
517         const colName= `Test Collection ${Math.floor(Math.random() * 999999)}`;
518         cy.createCollection(adminUser.token, {
519             name: colName,
520             owner_uuid: activeUser.user.uuid,
521             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:some-file\n",
522         }).as('collection').then(function () {
523             expect(this.collection.storage_classes_desired).to.deep.equal(['default'])
524
525             cy.loginAs(activeUser)
526             cy.goToPath(`/collections/${this.collection.uuid}`);
527
528             // Initial check: it should show the 'default' storage class
529             cy.get('[data-cy=collection-info-panel]')
530                 .should('contain', 'Storage classes')
531                 .and('contain', 'default')
532                 .and('not.contain', 'foo')
533                 .and('not.contain', 'bar');
534             // Edit collection: add storage class 'foo'
535             cy.get('[data-cy=collection-panel-options-btn]').click();
536             cy.get('[data-cy=context-menu]').contains('Edit collection').click();
537             cy.get('[data-cy=form-dialog]')
538                 .should('contain', 'Edit Collection')
539                 .and('contain', 'Storage classes')
540                 .and('contain', 'default')
541                 .and('contain', 'foo')
542                 .and('contain', 'bar')
543                 .within(() => {
544                     cy.get('[data-cy=checkbox-foo]').click();
545                 });
546             cy.get('[data-cy=form-submit-btn]').click();
547             cy.get('[data-cy=collection-info-panel]')
548                 .should('contain', 'default')
549                 .and('contain', 'foo')
550                 .and('not.contain', 'bar');
551             cy.doRequest('GET', `/arvados/v1/collections/${this.collection.uuid}`)
552                 .its('body').as('updatedCollection')
553                 .then(function () {
554                     expect(this.updatedCollection.storage_classes_desired).to.deep.equal(['default', 'foo']);
555                 });
556             // Edit collection: remove storage class 'default'
557             cy.get('[data-cy=collection-panel-options-btn]').click();
558             cy.get('[data-cy=context-menu]').contains('Edit collection').click();
559             cy.get('[data-cy=form-dialog]')
560                 .should('contain', 'Edit Collection')
561                 .and('contain', 'Storage classes')
562                 .and('contain', 'default')
563                 .and('contain', 'foo')
564                 .and('contain', 'bar')
565                 .within(() => {
566                     cy.get('[data-cy=checkbox-default]').click();
567                 });
568             cy.get('[data-cy=form-submit-btn]').click();
569             cy.get('[data-cy=collection-info-panel]')
570                 .should('not.contain', 'default')
571                 .and('contain', 'foo')
572                 .and('not.contain', 'bar');
573             cy.doRequest('GET', `/arvados/v1/collections/${this.collection.uuid}`)
574                 .its('body').as('updatedCollection')
575                 .then(function () {
576                     expect(this.updatedCollection.storage_classes_desired).to.deep.equal(['foo']);
577                 });
578         })
579     });
580
581     it('moves a collection to a different project', function () {
582         const collName = `Test Collection ${Math.floor(Math.random() * 999999)}`;
583         const projName = `Test Project ${Math.floor(Math.random() * 999999)}`;
584         const fileName = `Test_File_${Math.floor(Math.random() * 999999)}`;
585
586         cy.createCollection(adminUser.token, {
587             name: collName,
588             owner_uuid: activeUser.user.uuid,
589             manifest_text: `. 37b51d194a7513e45b56f6524f2d51f2+3 0:3:${fileName}\n`,
590         }).as('testCollection');
591         cy.createGroup(adminUser.token, {
592             name: projName,
593             group_class: 'project',
594             owner_uuid: activeUser.user.uuid,
595         }).as('testProject');
596
597         cy.getAll('@testCollection', '@testProject')
598             .then(function ([testCollection, testProject]) {
599                 cy.loginAs(activeUser);
600                 cy.goToPath(`/collections/${testCollection.uuid}`);
601                 cy.get('[data-cy=collection-files-panel]').should('contain', fileName);
602                 cy.get('[data-cy=collection-info-panel]')
603                     .should('not.contain', projName)
604                     .and('not.contain', testProject.uuid);
605                 cy.get('[data-cy=collection-panel-options-btn]').click();
606                 cy.get('[data-cy=context-menu]').contains('Move to').click();
607                 cy.get('[data-cy=form-dialog]')
608                     .should('contain', 'Move to')
609                     .within(() => {
610                         cy.get('[data-cy=projects-tree-home-tree-picker]')
611                             .find('i')
612                             .click();
613                         cy.get('[data-cy=projects-tree-home-tree-picker]')
614                             .contains(projName)
615                             .click();
616                     });
617                 cy.get('[data-cy=form-submit-btn]').click();
618                 cy.get('[data-cy=snackbar]')
619                     .contains('Collection has been moved')
620                 cy.get('[data-cy=collection-info-panel]')
621                     .contains(projName).and('contain', testProject.uuid);
622                 // Double check that the collection is in the project
623                 cy.goToPath(`/projects/${testProject.uuid}`);
624                 cy.get('[data-cy=project-panel]').should('contain', collName);
625             });
626     });
627
628     it('automatically updates the collection UI contents without using the Refresh button', function () {
629         const collName = `Test Collection ${Math.floor(Math.random() * 999999)}`;
630         const fileName = 'foobar'
631
632         cy.createCollection(adminUser.token, {
633             name: collName,
634             owner_uuid: activeUser.user.uuid,
635         }).as('testCollection');
636
637         cy.getAll('@testCollection').then(function ([testCollection]) {
638             cy.loginAs(activeUser);
639             cy.goToPath(`/collections/${testCollection.uuid}`);
640             cy.get('[data-cy=collection-files-panel]').should('contain', 'This collection is empty');
641             cy.get('[data-cy=collection-files-panel]').should('not.contain', fileName);
642             cy.get('[data-cy=collection-info-panel]').should('contain', collName);
643
644             cy.updateCollection(adminUser.token, testCollection.uuid, {
645                 name: `${collName + ' updated'}`,
646                 manifest_text: `. 37b51d194a7513e45b56f6524f2d51f2+3 0:3:${fileName}\n`,
647             }).as('updatedCollection');
648             cy.getAll('@updatedCollection').then(function ([updatedCollection]) {
649                 expect(updatedCollection.name).to.equal(`${collName + ' updated'}`);
650                 cy.get('[data-cy=collection-info-panel]').should('contain', updatedCollection.name);
651                 cy.get('[data-cy=collection-files-panel]').should('contain', fileName);
652             });
653         });
654     })
655
656     it('makes a copy of an existing collection', function() {
657         const collName = `Test Collection ${Math.floor(Math.random() * 999999)}`;
658         const copyName = `Copy of: ${collName}`;
659
660         cy.createCollection(adminUser.token, {
661             name: collName,
662             owner_uuid: activeUser.user.uuid,
663             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:some-file\n",
664         }).as('collection').then(function () {
665             cy.loginAs(activeUser)
666             cy.goToPath(`/collections/${this.collection.uuid}`);
667             cy.get('[data-cy=collection-files-panel]')
668                 .should('contain', 'some-file');
669             cy.get('[data-cy=collection-panel-options-btn]').click();
670             cy.get('[data-cy=context-menu]').contains('Make a copy').click();
671             cy.get('[data-cy=form-dialog]')
672                 .should('contain', 'Make a copy')
673                 .within(() => {
674                     cy.get('[data-cy=projects-tree-home-tree-picker]')
675                         .contains('Projects')
676                         .click();
677                     cy.get('[data-cy=form-submit-btn]').click();
678                 });
679             cy.get('[data-cy=snackbar]')
680                 .contains('Collection has been copied.')
681             cy.get('[data-cy=snackbar-goto-action]').click();
682             cy.get('[data-cy=project-panel]')
683                 .contains(copyName).click();
684             cy.get('[data-cy=collection-files-panel]')
685                 .should('contain', 'some-file');
686         });
687     });
688
689     it('uses the collection version browser to view a previous version', function () {
690         const colName = `Test Collection ${Math.floor(Math.random() * 999999)}`;
691
692         // Creates the collection using the admin token so we can set up
693         // a bogus manifest text without block signatures.
694         cy.createCollection(adminUser.token, {
695             name: colName,
696             owner_uuid: activeUser.user.uuid,
697             preserve_version: true,
698             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo 0:3:bar\n"
699         })
700             .as('collection').then(function () {
701                 // Visit collection, check basic information
702                 cy.loginAs(activeUser)
703                 cy.goToPath(`/collections/${this.collection.uuid}`);
704
705                 cy.get('[data-cy=collection-info-panel]').should('not.contain', 'This is an old version');
706                 cy.get('[data-cy=read-only-icon]').should('not.exist');
707                 cy.get('[data-cy=collection-version-number]').should('contain', '1');
708                 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
709                 cy.get('[data-cy=collection-files-panel]').should('contain', 'foo').and('contain', 'bar');
710
711                 // Modify collection, expect version number change
712                 cy.get('[data-cy=collection-files-panel]').contains('foo').rightclick();
713                 cy.get('[data-cy=context-menu]').contains('Remove').click();
714                 cy.get('[data-cy=confirmation-dialog]').should('contain', 'Removing file');
715                 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
716                 cy.get('[data-cy=collection-version-number]').should('contain', '2');
717                 cy.get('[data-cy=collection-files-panel]').should('not.contain', 'foo').and('contain', 'bar');
718
719                 // Click on version number, check version browser. Click on past version.
720                 cy.get('[data-cy=collection-version-browser]').should('not.exist');
721                 cy.get('[data-cy=collection-version-number]').contains('2').click();
722                 cy.get('[data-cy=collection-version-browser]')
723                     .should('contain', 'Nr').and('contain', 'Size').and('contain', 'Date')
724                     .within(() => {
725                         // Version 1: 6 bytes in size
726                         cy.get('[data-cy=collection-version-browser-select-1]')
727                             .should('contain', '1')
728                             .and('contain', '6 B')
729                             .and('contain', adminUser.user.uuid);
730                         // Version 2: 3 bytes in size (one file removed)
731                         cy.get('[data-cy=collection-version-browser-select-2]')
732                             .should('contain', '2')
733                             .and('contain', '3 B')
734                             .and('contain', activeUser.user.full_name);
735                         cy.get('[data-cy=collection-version-browser-select-3]')
736                             .should('not.exist');
737                         cy.get('[data-cy=collection-version-browser-select-1]')
738                             .click();
739                     });
740                 cy.get('[data-cy=collection-info-panel]').should('contain', 'This is an old version');
741                 cy.get('[data-cy=read-only-icon]').should('exist');
742                 cy.get('[data-cy=collection-version-number]').should('contain', '1');
743                 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
744                 cy.get('[data-cy=collection-files-panel]')
745                     .should('contain', 'foo').and('contain', 'bar');
746
747                 // Check that only old collection action are available on context menu
748                 cy.get('[data-cy=collection-panel-options-btn]').click();
749                 cy.get('[data-cy=context-menu]')
750                     .should('contain', 'Restore version')
751                     .and('not.contain', 'Add to favorites');
752                 cy.get('body').click(); // Collapse the menu avoiding details panel expansion
753
754                 // Click on "head version" link, confirm that it's the latest version.
755                 cy.get('[data-cy=collection-info-panel]').contains('head version').click();
756                 cy.get('[data-cy=collection-info-panel]')
757                     .should('not.contain', 'This is an old version');
758                 cy.get('[data-cy=read-only-icon]').should('not.exist');
759                 cy.get('[data-cy=collection-version-number]').should('contain', '2');
760                 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
761                 cy.get('[data-cy=collection-files-panel]').
762                     should('not.contain', 'foo').and('contain', 'bar');
763
764                 // Check that old collection action isn't available on context menu
765                 cy.get('[data-cy=collection-panel-options-btn]').click()
766                 cy.get('[data-cy=context-menu]').should('not.contain', 'Restore version')
767                 cy.get('body').click(); // Collapse the menu avoiding details panel expansion
768
769                 // Make another change, confirm new version.
770                 cy.get('[data-cy=collection-panel-options-btn]').click();
771                 cy.get('[data-cy=context-menu]').contains('Edit collection').click();
772                 cy.get('[data-cy=form-dialog]')
773                     .should('contain', 'Edit Collection')
774                     .within(() => {
775                         // appends some text
776                         cy.get('input').first().type(' renamed');
777                     });
778                 cy.get('[data-cy=form-submit-btn]').click();
779                 cy.get('[data-cy=collection-info-panel]')
780                     .should('not.contain', 'This is an old version');
781                 cy.get('[data-cy=read-only-icon]').should('not.exist');
782                 cy.get('[data-cy=collection-version-number]').should('contain', '3');
783                 cy.get('[data-cy=collection-info-panel]').should('contain', colName + ' renamed');
784                 cy.get('[data-cy=collection-files-panel]')
785                     .should('not.contain', 'foo').and('contain', 'bar');
786                 cy.get('[data-cy=collection-version-browser-select-3]')
787                     .should('contain', '3').and('contain', '3 B');
788
789                 // Check context menus on version browser
790                 cy.get('[data-cy=collection-version-browser-select-3]').rightclick()
791                 cy.get('[data-cy=context-menu]')
792                     .should('contain', 'Add to favorites')
793                     .and('contain', 'Make a copy')
794                     .and('contain', 'Edit collection');
795                 cy.get('body').click();
796                 // (and now an old version...)
797                 cy.get('[data-cy=collection-version-browser-select-1]').rightclick()
798                 cy.get('[data-cy=context-menu]')
799                     .should('not.contain', 'Add to favorites')
800                     .and('contain', 'Make a copy')
801                     .and('not.contain', 'Edit collection');
802                 cy.get('body').click();
803
804                 // Restore first version
805                 cy.get('[data-cy=collection-version-browser]').within(() => {
806                     cy.get('[data-cy=collection-version-browser-select-1]').click();
807                 });
808                 cy.get('[data-cy=collection-panel-options-btn]').click()
809                 cy.get('[data-cy=context-menu]').contains('Restore version').click();
810                 cy.get('[data-cy=confirmation-dialog]').should('contain', 'Restore version');
811                 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
812                 cy.get('[data-cy=collection-info-panel]')
813                     .should('not.contain', 'This is an old version');
814                 cy.get('[data-cy=collection-version-number]').should('contain', '4');
815                 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
816                 cy.get('[data-cy=collection-files-panel]')
817                     .should('contain', 'foo').and('contain', 'bar');
818             });
819     });
820
821     it('creates collection from selected files of another collection', () => {
822         cy.createCollection(adminUser.token, {
823             name: `Test Collection ${Math.floor(Math.random() * 999999)}`,
824             owner_uuid: activeUser.user.uuid,
825             preserve_version: true,
826             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo 0:3:bar\n"
827         })
828             .as('collection').then(function () {
829                 // Visit collection, check basic information
830                 cy.loginAs(activeUser)
831                 cy.goToPath(`/collections/${this.collection.uuid}`);
832
833                 cy.get('[data-cy=collection-files-panel]').within(() => {
834                     cy.get('input[type=checkbox]').first().click();
835                 });
836
837                 cy.get('[data-cy=collection-files-panel-options-btn]').click();
838                 cy.get('[data-cy=context-menu]').contains('Create a new collection with selected').click();
839
840                 cy.get('[data-cy=form-dialog]').contains('Projects').click();
841
842                 cy.get('[data-cy=form-submit-btn]').click();
843
844                 cy.waitForDom().get('.layout-pane-primary', { timeout: 12000 }).contains('Projects').click();
845
846                 cy.get('main').contains(`Files extracted from: ${this.collection.name}`).should('exist');
847             });
848     });
849
850     it('creates new collection with properties on home project', function () {
851         cy.loginAs(activeUser);
852         cy.goToPath(`/projects/${activeUser.user.uuid}`);
853         cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
854         cy.get('[data-cy=breadcrumb-last]').should('not.exist');
855         // Create new collection
856         cy.get('[data-cy=side-panel-button]').click();
857         cy.get('[data-cy=side-panel-new-collection]').click();
858         // Name between brackets tests bugfix #17582
859         const collName = `[Test collection (${Math.floor(999999 * Math.random())})]`;
860
861         // Select a storage class.
862         cy.get('[data-cy=form-dialog]')
863             .should('contain', 'New collection')
864             .and('contain', 'Storage classes')
865             .and('contain', 'default')
866             .and('contain', 'foo')
867             .and('contain', 'bar')
868             .within(() => {
869                 cy.get('[data-cy=parent-field]').within(() => {
870                     cy.get('input').should('have.value', 'Home project');
871                 });
872                 cy.get('[data-cy=name-field]').within(() => {
873                     cy.get('input').type(collName);
874                 });
875                 cy.get('[data-cy=checkbox-foo]').click();
876             })
877
878         // Add a property.
879         // Key: Color (IDTAGCOLORS) - Value: Magenta (IDVALCOLORS3)
880         cy.get('[data-cy=form-dialog]').should('not.contain', 'Color: Magenta');
881         cy.get('[data-cy=resource-properties-form]').within(() => {
882             cy.get('[data-cy=property-field-key]').within(() => {
883                 cy.get('input').type('Color');
884             });
885             cy.get('[data-cy=property-field-value]').within(() => {
886                 cy.get('input').type('Magenta');
887             });
888             cy.root().submit();
889         });
890         // Confirm proper vocabulary labels are displayed on the UI.
891         cy.get('[data-cy=form-dialog]').should('contain', 'Color: Magenta');
892
893         cy.get('[data-cy=form-submit-btn]').click();
894         // Confirm that the user was taken to the newly created collection
895         cy.get('[data-cy=form-dialog]').should('not.exist');
896         cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
897         cy.get('[data-cy=breadcrumb-last]').should('contain', collName);
898         cy.get('[data-cy=collection-info-panel]')
899             .should('contain', 'default')
900             .and('contain', 'foo')
901             .and('contain', 'Color: Magenta')
902             .and('not.contain', 'bar');
903         // Confirm that the collection's properties has the real values.
904         cy.doRequest('GET', '/arvados/v1/collections', null, {
905             filters: `[["name", "=", "${collName}"]]`,
906         })
907         .its('body.items').as('collections')
908         .then(function() {
909             expect(this.collections).to.have.lengthOf(1);
910             expect(this.collections[0].properties).to.have.property(
911                 'IDTAGCOLORS', 'IDVALCOLORS3');
912         });
913     });
914
915     it('shows responsible person for collection if available', () => {
916         cy.createCollection(adminUser.token, {
917             name: `Test collection ${Math.floor(Math.random() * 999999)}`,
918             owner_uuid: activeUser.user.uuid,
919             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
920         }).as('testCollection1');
921
922         cy.createCollection(adminUser.token, {
923             name: `Test collection ${Math.floor(Math.random() * 999999)}`,
924             owner_uuid: adminUser.user.uuid,
925             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
926         }).as('testCollection2').then(function (testCollection2) {
927             cy.shareWith(adminUser.token, activeUser.user.uuid, testCollection2.uuid, 'can_write');
928         });
929
930         cy.getAll('@testCollection1', '@testCollection2')
931             .then(function ([testCollection1, testCollection2]) {
932                 cy.loginAs(activeUser);
933
934                 cy.goToPath(`/collections/${testCollection1.uuid}`);
935                 cy.get('[data-cy=responsible-person-wrapper]')
936                     .contains(activeUser.user.uuid);
937
938                 cy.goToPath(`/collections/${testCollection2.uuid}`);
939                 cy.get('[data-cy=responsible-person-wrapper]')
940                     .contains(adminUser.user.uuid);
941             });
942     });
943
944     describe('file upload', () => {
945         beforeEach(() => {
946             cy.createCollection(adminUser.token, {
947                 name: `Test collection ${Math.floor(Math.random() * 999999)}`,
948                 owner_uuid: activeUser.user.uuid,
949                 manifest_text: "./subdir 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo\n. 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
950             }).as('testCollection1');
951         });
952
953         it('uploads a file and checks the collection UI to be fresh', () => {
954             cy.getAll('@testCollection1')
955                 .then(function([testCollection1]) {
956                     cy.loginAs(activeUser);
957                     cy.goToPath(`/collections/${testCollection1.uuid}`);
958                     cy.get('[data-cy=upload-button]').click();
959                     cy.get('[data-cy=collection-files-panel]')
960                         .contains('5mb_a.bin').should('not.exist');
961                     cy.get('[data-cy=collection-file-count]').should('contain', '2');
962                     cy.fixture('files/5mb.bin', 'base64').then(content => {
963                         cy.get('[data-cy=drag-and-drop]').upload(content, '5mb_a.bin');
964                         cy.get('[data-cy=form-submit-btn]').click();
965                         cy.get('[data-cy=form-submit-btn]').should('not.exist');
966                         cy.get('[data-cy=collection-files-panel]')
967                             .contains('5mb_a.bin').should('exist');
968                         cy.get('[data-cy=collection-file-count]').should('contain', '3');
969
970                         cy.get('[data-cy=collection-files-panel]').contains('subdir').click();
971                         cy.get('[data-cy=upload-button]').click();
972                         cy.fixture('files/5mb.bin', 'base64').then(content => {
973                             cy.get('[data-cy=drag-and-drop]').upload(content, '5mb_b.bin');
974                             cy.get('[data-cy=form-submit-btn]').click();
975                             cy.get('[data-cy=form-submit-btn]').should('not.exist');
976                             cy.get('[data-cy=collection-files-right-panel]')
977                                  .contains('5mb_b.bin').should('exist');
978                         });
979                     });
980                 });
981         });
982
983         it('allows to cancel running upload', () => {
984             cy.getAll('@testCollection1')
985                 .then(function([testCollection1]) {
986                     cy.loginAs(activeUser);
987
988                     cy.goToPath(`/collections/${testCollection1.uuid}`);
989
990                     cy.get('[data-cy=upload-button]').click();
991
992                     cy.fixture('files/5mb.bin', 'base64').then(content => {
993                         cy.get('[data-cy=drag-and-drop]').upload(content, '5mb_a.bin');
994                         cy.get('[data-cy=drag-and-drop]').upload(content, '5mb_b.bin');
995
996                         cy.get('[data-cy=form-submit-btn]').click();
997
998                         cy.get('button').contains('Cancel').click();
999
1000                         cy.get('[data-cy=form-submit-btn]').should('not.exist');
1001                     });
1002                 });
1003         });
1004
1005         it('allows to cancel single file from the running upload', () => {
1006             cy.getAll('@testCollection1')
1007                 .then(function([testCollection1]) {
1008                     cy.loginAs(activeUser);
1009
1010                     cy.goToPath(`/collections/${testCollection1.uuid}`);
1011
1012                     cy.get('[data-cy=upload-button]').click();
1013
1014                     cy.fixture('files/5mb.bin', 'base64').then(content => {
1015                         cy.get('[data-cy=drag-and-drop]').upload(content, '5mb_a.bin');
1016                         cy.get('[data-cy=drag-and-drop]').upload(content, '5mb_b.bin');
1017
1018                         cy.get('[data-cy=form-submit-btn]').click();
1019
1020                         cy.get('button[aria-label=Remove]').eq(1).click();
1021
1022                         cy.get('[data-cy=form-submit-btn]').should('not.exist');
1023
1024                         cy.get('[data-cy=collection-files-panel]').contains('5mb_a.bin').should('exist');
1025                     });
1026                 });
1027         });
1028
1029         it('allows to cancel all files from the running upload', () => {
1030             cy.getAll('@testCollection1')
1031                 .then(function([testCollection1]) {
1032                     cy.loginAs(activeUser);
1033
1034                     cy.goToPath(`/collections/${testCollection1.uuid}`);
1035
1036                     // Confirm initial collection state.
1037                     cy.get('[data-cy=collection-files-panel]')
1038                         .contains('bar').should('exist');
1039                     cy.get('[data-cy=collection-files-panel]')
1040                         .contains('5mb_a.bin').should('not.exist');
1041                     cy.get('[data-cy=collection-files-panel]')
1042                         .contains('5mb_b.bin').should('not.exist');
1043
1044                     cy.get('[data-cy=upload-button]').click();
1045
1046                     cy.fixture('files/5mb.bin', 'base64').then(content => {
1047                         cy.get('[data-cy=drag-and-drop]').upload(content, '5mb_a.bin');
1048                         cy.get('[data-cy=drag-and-drop]').upload(content, '5mb_b.bin');
1049
1050                         cy.get('[data-cy=form-submit-btn]').click();
1051
1052                         cy.get('button[aria-label=Remove]').should('exist');
1053                         cy.get('button[aria-label=Remove]')
1054                             .click({ multiple: true, force: true });
1055
1056                         cy.get('[data-cy=form-submit-btn]').should('not.exist');
1057
1058                         // Confirm final collection state.
1059                         cy.get('[data-cy=collection-files-panel]')
1060                             .contains('bar').should('exist');
1061                         // The following fails, but doesn't seem to happen
1062                         // in the real world. Maybe there's a race between
1063                         // the PUT request finishing and the 'Remove' button
1064                         // dissapearing, because sometimes just one of the 2
1065                         // files gets uploaded.
1066                         // Maybe this will be needed to simulate a slow network:
1067                         // https://docs.cypress.io/api/commands/intercept#Convenience-functions-1
1068                         // cy.get('[data-cy=collection-files-panel]')
1069                         //     .contains('5mb_a.bin').should('not.exist');
1070                         // cy.get('[data-cy=collection-files-panel]')
1071                         //     .contains('5mb_b.bin').should('not.exist');
1072                     });
1073                 });
1074         });
1075     });
1076 })