Merge branch '20845-queued-process-filter' refs #20845
[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('attempts to use a preexisting name creating or updating a collection', function() {
79         const name = `Test collection ${Math.floor(Math.random() * 999999)}`;
80         cy.createCollection(adminUser.token, {
81             name: name,
82             owner_uuid: activeUser.user.uuid,
83             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
84         });
85         cy.loginAs(activeUser);
86         cy.goToPath(`/projects/${activeUser.user.uuid}`);
87         cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
88         cy.get('[data-cy=breadcrumb-last]').should('not.exist');
89         // Attempt to create new collection with a duplicate name
90         cy.get('[data-cy=side-panel-button]').click();
91         cy.get('[data-cy=side-panel-new-collection]').click();
92         cy.get('[data-cy=form-dialog]')
93             .should('contain', 'New collection')
94             .within(() => {
95                 cy.get('[data-cy=name-field]').within(() => {
96                     cy.get('input').type(name);
97                 });
98                 cy.get('[data-cy=form-submit-btn]').click();
99             });
100         // Error message should display, allowing editing the name
101         cy.get('[data-cy=form-dialog]').should('exist')
102             .and('contain', 'Collection with the same name already exists')
103             .within(() => {
104                 cy.get('[data-cy=name-field]').within(() => {
105                     cy.get('input').type(' renamed');
106                 });
107                 cy.get('[data-cy=form-submit-btn]').click();
108             });
109         cy.get('[data-cy=form-dialog]').should('not.exist');
110         // Attempt to rename the collection with the duplicate name
111         cy.get('[data-cy=collection-panel-options-btn]').click();
112         cy.get('[data-cy=context-menu]').contains('Edit collection').click();
113         cy.get('[data-cy=form-dialog]')
114             .should('contain', 'Edit Collection')
115             .within(() => {
116                 cy.get('[data-cy=name-field]').within(() => {
117                     cy.get('input')
118                         .type('{selectall}{backspace}')
119                         .type(name);
120                 });
121                 cy.get('[data-cy=form-submit-btn]').click();
122             });
123         cy.get('[data-cy=form-dialog]').should('exist')
124             .and('contain', 'Collection with the same name already exists');
125     });
126
127     it('uses the property editor (from edit dialog) with vocabulary terms', function () {
128         cy.createCollection(adminUser.token, {
129             name: `Test collection ${Math.floor(Math.random() * 999999)}`,
130             owner_uuid: activeUser.user.uuid,
131             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
132         })
133             .as('testCollection').then(function () {
134                 cy.loginAs(activeUser);
135                 cy.goToPath(`/collections/${this.testCollection.uuid}`);
136
137                 cy.get('[data-cy=collection-info-panel')
138                     .should('contain', this.testCollection.name)
139                     .and('not.contain', 'Color: Magenta');
140
141                 cy.get('[data-cy=collection-panel-options-btn]').click();
142                 cy.get('[data-cy=context-menu]').contains('Edit collection').click();
143                 cy.get('[data-cy=form-dialog]').should('contain', 'Properties');
144
145                 // Key: Color (IDTAGCOLORS) - Value: Magenta (IDVALCOLORS3)
146                 cy.get('[data-cy=resource-properties-form]').within(() => {
147                     cy.get('[data-cy=property-field-key]').within(() => {
148                         cy.get('input').type('Color');
149                     });
150                     cy.get('[data-cy=property-field-value]').within(() => {
151                         cy.get('input').type('Magenta');
152                     });
153                     cy.root().submit();
154                 });
155                 // Confirm proper vocabulary labels are displayed on the UI.
156                 cy.get('[data-cy=form-dialog]').should('contain', 'Color: Magenta');
157                 cy.get('[data-cy=form-dialog]').contains('Save').click();
158                 cy.get('[data-cy=form-dialog]').should('not.exist');
159                 // Confirm proper vocabulary IDs were saved on the backend.
160                 cy.doRequest('GET', `/arvados/v1/collections/${this.testCollection.uuid}`)
161                     .its('body').as('collection')
162                     .then(function () {
163                         expect(this.collection.properties.IDTAGCOLORS).to.equal('IDVALCOLORS3');
164                     });
165                 // Confirm the property is displayed on the UI.
166                 cy.get('[data-cy=collection-info-panel')
167                     .should('contain', this.testCollection.name)
168                     .and('contain', 'Color: Magenta');
169             });
170     });
171
172     it('uses the editor (from details panel) with vocabulary terms', function () {
173         cy.createCollection(adminUser.token, {
174             name: `Test collection ${Math.floor(Math.random() * 999999)}`,
175             owner_uuid: activeUser.user.uuid,
176             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
177         })
178             .as('testCollection').then(function () {
179                 cy.loginAs(activeUser);
180                 cy.goToPath(`/collections/${this.testCollection.uuid}`);
181
182                 cy.get('[data-cy=collection-info-panel')
183                     .should('contain', this.testCollection.name)
184                     .and('not.contain', 'Color: Magenta')
185                     .and('not.contain', 'Size: S');
186                 cy.get('[data-cy=additional-info-icon]').click();
187
188                 cy.get('[data-cy=details-panel]').within(() => {
189                     cy.get('[data-cy=details-panel-edit-btn]').click();
190                 });
191                 cy.get('[data-cy=form-dialog').contains('Edit Collection');
192
193                 // Key: Color (IDTAGCOLORS) - Value: Magenta (IDVALCOLORS3)
194                 cy.get('[data-cy=resource-properties-form]').within(() => {
195                     cy.get('[data-cy=property-field-key]').within(() => {
196                         cy.get('input').type('Color');
197                     });
198                     cy.get('[data-cy=property-field-value]').within(() => {
199                         cy.get('input').type('Magenta');
200                     });
201                     cy.root().submit();
202                 });
203                 // Confirm proper vocabulary labels are displayed on the UI.
204                 cy.get('[data-cy=form-dialog]')
205                     .should('contain', 'Color: Magenta');
206
207                 // Case-insensitive on-blur auto-selection test
208                 // Key: Size (IDTAGSIZES) - Value: Small (IDVALSIZES2)
209                 cy.get('[data-cy=resource-properties-form]').within(() => {
210                     cy.get('[data-cy=property-field-key]').within(() => {
211                         cy.get('input').type('sIzE');
212                     });
213                     cy.get('[data-cy=property-field-value]').within(() => {
214                         cy.get('input').type('sMaLL');
215                     });
216                     // Cannot "type()" TAB on Cypress so let's click another field
217                     // to trigger the onBlur event.
218                     cy.get('[data-cy=property-field-key]').click();
219                     cy.root().submit();
220                 });
221                 // Confirm proper vocabulary labels are displayed on the UI.
222                 cy.get('[data-cy=form-dialog]')
223                     .should('contain', 'Size: S');
224
225                 cy.get('[data-cy=form-dialog]').contains('Save').click();
226                 cy.get('[data-cy=form-dialog]').should('not.exist');
227
228                 // Confirm proper vocabulary IDs were saved on the backend.
229                 cy.doRequest('GET', `/arvados/v1/collections/${this.testCollection.uuid}`)
230                     .its('body').as('collection')
231                     .then(function () {
232                         expect(this.collection.properties.IDTAGCOLORS).to.equal('IDVALCOLORS3');
233                         expect(this.collection.properties.IDTAGSIZES).to.equal('IDVALSIZES2');
234                     });
235
236                 // Confirm properties display on the UI.
237                 cy.get('[data-cy=collection-info-panel')
238                     .should('contain', this.testCollection.name)
239                     .and('contain', 'Color: Magenta')
240                     .and('contain', 'Size: S');
241             });
242     });
243
244     it('shows collection by URL', function () {
245         cy.loginAs(activeUser);
246         [true, false].map(function (isWritable) {
247             // Using different file names to avoid test flakyness: the second iteration
248             // on this loop may pass an assertion from the first iteration by looking
249             // for the same file name.
250             const fileName = isWritable ? 'bar' : 'foo';
251             const subDirName = 'subdir';
252             cy.createGroup(adminUser.token, {
253                 name: 'Shared project',
254                 group_class: 'project',
255             }).as('sharedGroup').then(function () {
256                 // Creates the collection using the admin token so we can set up
257                 // a bogus manifest text without block signatures.
258                 cy.doRequest('GET', '/arvados/v1/config', null, null)
259                     .its('body').should((clusterConfig) => {
260                       expect(clusterConfig.Collections, "clusterConfig").to.have.property("TrustAllContent", true);
261                       expect(clusterConfig.Services, "clusterConfig").to.have.property("WebDAV").have.property("ExternalURL");
262                       expect(clusterConfig.Services, "clusterConfig").to.have.property("WebDAVDownload").have.property("ExternalURL");
263                       const inlineUrl = clusterConfig.Services.WebDAV.ExternalURL !== ""
264                           ? clusterConfig.Services.WebDAV.ExternalURL
265                           : clusterConfig.Services.WebDAVDownload.ExternalURL;
266                       expect(inlineUrl).to.not.contain("*");
267                     })
268                     .createCollection(adminUser.token, {
269                       name: 'Test collection',
270                       owner_uuid: this.sharedGroup.uuid,
271                       properties: { someKey: 'someValue' },
272                       manifest_text: `. 37b51d194a7513e45b56f6524f2d51f2+3 0:3:${fileName}\n./${subDirName} 37b51d194a7513e45b56f6524f2d51f2+3 0:3:${fileName}\n`
273                     })
274                     .as('testCollection').then(function () {
275                         // Share the group with active user.
276                         cy.createLink(adminUser.token, {
277                             name: isWritable ? 'can_write' : 'can_read',
278                             link_class: 'permission',
279                             head_uuid: this.sharedGroup.uuid,
280                             tail_uuid: activeUser.user.uuid
281                         })
282                         cy.goToPath(`/collections/${this.testCollection.uuid}`);
283
284                         // Check that name & uuid are correct.
285                         cy.get('[data-cy=collection-info-panel]')
286                             .should('contain', this.testCollection.name)
287                             .and('contain', this.testCollection.uuid)
288                             .and('not.contain', 'This is an old version');
289                         // Check for the read-only icon
290                         cy.get('[data-cy=read-only-icon]').should(`${isWritable ? 'not.' : ''}exist`);
291                         // Check that both read and write operations are available on
292                         // the 'More options' menu.
293                         cy.get('[data-cy=collection-panel-options-btn]')
294                             .click()
295                         cy.get('[data-cy=context-menu]')
296                             .should('contain', 'Add to favorites')
297                             .and(`${isWritable ? '' : 'not.'}contain`, 'Edit collection');
298                         cy.get('body').click(); // Collapse the menu avoiding details panel expansion
299                         cy.get('[data-cy=collection-info-panel]')
300                             .should('contain', 'someKey: someValue')
301                             .and('not.contain', 'anotherKey: anotherValue');
302                         // Check that the file listing show both read & write operations
303                         cy.waitForDom().get('[data-cy=collection-files-panel]').within(() => {
304                             cy.get('[data-cy=collection-files-right-panel]', { timeout: 5000 })
305                                 .should('contain', fileName);
306                             if (isWritable) {
307                                 cy.get('[data-cy=upload-button]')
308                                     .should(`${isWritable ? '' : 'not.'}contain`, 'Upload data');
309                             }
310                         });
311                         // Test context menus
312                         cy.get('[data-cy=collection-files-panel]')
313                             .contains(fileName).rightclick();
314                         cy.get('[data-cy=context-menu]')
315                             .should('contain', 'Download')
316                             .and('contain', 'Open in new tab')
317                             .and('contain', 'Copy to clipboard')
318                             .and(`${isWritable ? '' : 'not.'}contain`, 'Rename')
319                             .and(`${isWritable ? '' : 'not.'}contain`, 'Remove');
320                         cy.get('body').click(); // Collapse the menu
321                         cy.get('[data-cy=collection-files-panel]')
322                             .contains(subDirName).rightclick();
323                         cy.get('[data-cy=context-menu]')
324                             .should('not.contain', 'Download')
325                             .and('contain', 'Open in new tab')
326                             .and('contain', 'Copy to clipboard')
327                             .and(`${isWritable ? '' : 'not.'}contain`, 'Rename')
328                             .and(`${isWritable ? '' : 'not.'}contain`, 'Remove');
329                         cy.get('body').click(); // Collapse the menu
330                         // File/dir item 'more options' button
331                         cy.get('[data-cy=file-item-options-btn')
332                             .first()
333                             .click()
334                         cy.get('[data-cy=context-menu]')
335                             .should(`${isWritable ? '' : 'not.'}contain`, 'Remove');
336                         cy.get('body').click(); // Collapse the menu
337                         // Hamburger 'more options' menu button
338                         cy.get('[data-cy=collection-files-panel-options-btn]')
339                             .click()
340                         cy.get('[data-cy=context-menu]')
341                             .should('contain', 'Select all')
342                             .click()
343                         cy.get('[data-cy=collection-files-panel-options-btn]')
344                             .click()
345                         cy.get('[data-cy=context-menu]')
346                             .should(`${isWritable ? '' : 'not.'}contain`, 'Remove selected')
347                         cy.get('body').click(); // Collapse the menu
348                     })
349             })
350         })
351     })
352
353     it('renames a file using valid names', function () {
354         function eachPair(lst, func){
355             for(var i=0; i < lst.length - 1; i++){
356                 func(lst[i], lst[i + 1])
357             }
358         }
359         // Creates the collection using the admin token so we can set up
360         // a bogus manifest text without block signatures.
361         cy.createCollection(adminUser.token, {
362             name: `Test collection ${Math.floor(Math.random() * 999999)}`,
363             owner_uuid: activeUser.user.uuid,
364             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
365         })
366             .as('testCollection').then(function () {
367                 cy.loginAs(activeUser);
368                 cy.goToPath(`/collections/${this.testCollection.uuid}`);
369
370                 const names = [
371                     'bar', // initial name already set
372                     '&',
373                     'foo',
374                     '&amp;',
375                     'I ❤️ ⛵️',
376                     '...',
377                     '#..',
378                     'some name with whitespaces',
379                     'some name with #2',
380                     'is this name legal? I hope it is',
381                     'some_file.pdf#',
382                     'some_file.pdf?',
383                     '?some_file.pdf',
384                     'some%file.pdf',
385                     'some%2Ffile.pdf',
386                     'some%22file.pdf',
387                     'some%20file.pdf',
388                     "G%C3%BCnter's%20file.pdf",
389                     'table%&?*2',
390                     'bar' // make sure we can go back to the original name as a last step
391                 ];
392                 cy.intercept({method: 'PUT', url: '**/arvados/v1/collections/*'}).as('renameRequest');
393                 eachPair(names, (from, to) => {
394                     cy.waitForDom().get('[data-cy=collection-files-panel]')
395                         .contains(`${from}`).rightclick();
396                     cy.get('[data-cy=context-menu]')
397                         .contains('Rename')
398                         .click();
399                     cy.get('[data-cy=form-dialog]')
400                         .should('contain', 'Rename')
401                         .within(() => {
402                             cy.get('input')
403                                 .type('{selectall}{backspace}')
404                                 .type(to, { parseSpecialCharSequences: false });
405                         });
406                     cy.get('[data-cy=form-submit-btn]').click();
407                     cy.wait('@renameRequest');
408                     cy.get('[data-cy=collection-files-panel]')
409                         .should('not.contain', `${from}`)
410                         .and('contain', `${to}`);
411                 })
412             });
413     });
414
415     it('renames a file to a different directory', function () {
416         // Creates the collection using the admin token so we can set up
417         // a bogus manifest text without block signatures.
418         cy.createCollection(adminUser.token, {
419             name: `Test collection ${Math.floor(Math.random() * 999999)}`,
420             owner_uuid: activeUser.user.uuid,
421             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
422         })
423             .as('testCollection').then(function () {
424                 cy.loginAs(activeUser);
425                 cy.goToPath(`/collections/${this.testCollection.uuid}`);
426
427                 ['subdir', 'G%C3%BCnter\'s%20file', 'table%&?*2'].forEach((subdir) => {
428                     cy.waitForDom().get('[data-cy=collection-files-panel]')
429                         .contains('bar').rightclick();
430                     cy.get('[data-cy=context-menu]')
431                         .contains('Rename')
432                         .click();
433                     cy.get('[data-cy=form-dialog]')
434                         .should('contain', 'Rename')
435                         .within(() => {
436                             cy.get('input').type(`{selectall}{backspace}${subdir}/foo`);
437                         });
438                     cy.get('[data-cy=form-submit-btn]').click();
439                     cy.get('[data-cy=collection-files-panel]')
440                         .should('not.contain', 'bar')
441                         .and('contain', subdir);
442                     cy.get('[data-cy=collection-files-panel]').contains(subdir).click();
443
444                     // Rename 'subdir/foo' to 'bar'
445                     cy.wait(1000);
446                     cy.get('[data-cy=collection-files-panel]')
447                         .contains('foo').rightclick();
448                     cy.get('[data-cy=context-menu]')
449                         .contains('Rename')
450                         .click();
451                     cy.get('[data-cy=form-dialog]')
452                         .should('contain', 'Rename')
453                         .within(() => {
454                             cy.get('input')
455                                 .should('have.value', `${subdir}/foo`)
456                                 .type(`{selectall}{backspace}bar`);
457                         });
458                     cy.get('[data-cy=form-submit-btn]').click();
459
460                     // need to wait for dialog to dismiss
461                     cy.get('[data-cy=form-dialog]').should('not.exist');
462
463                     cy.waitForDom().get('[data-cy=collection-files-panel]')
464                         .contains('Home')
465                         .click();
466
467                     cy.wait(2000);
468                     cy.get('[data-cy=collection-files-panel]')
469                         .should('contain', subdir) // empty dir kept
470                         .and('contain', 'bar');
471
472                     cy.get('[data-cy=collection-files-panel]')
473                         .contains(subdir).rightclick();
474                     cy.get('[data-cy=context-menu]')
475                         .contains('Remove')
476                         .click();
477                     cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
478                     cy.get('[data-cy=form-dialog]').should('not.exist');
479                 });
480             });
481     });
482
483     it('shows collection owner', () => {
484         cy.createCollection(adminUser.token, {
485             name: `Test collection ${Math.floor(Math.random() * 999999)}`,
486             owner_uuid: activeUser.user.uuid,
487             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
488         })
489             .as('testCollection').then((testCollection) => {
490                 cy.loginAs(activeUser);
491                 cy.goToPath(`/collections/${testCollection.uuid}`);
492                 cy.wait(5000);
493                 cy.get('[data-cy=collection-info-panel]').contains(`Collection User`);
494             });
495     });
496
497     it('tries to rename a file with illegal names', function () {
498         // Creates the collection using the admin token so we can set up
499         // a bogus manifest text without block signatures.
500         cy.createCollection(adminUser.token, {
501             name: `Test collection ${Math.floor(Math.random() * 999999)}`,
502             owner_uuid: activeUser.user.uuid,
503             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
504         })
505             .as('testCollection').then(function () {
506                 cy.loginAs(activeUser);
507                 cy.goToPath(`/collections/${this.testCollection.uuid}`);
508
509                 const illegalNamesFromUI = [
510                     ['.', "Name cannot be '.' or '..'"],
511                     ['..', "Name cannot be '.' or '..'"],
512                     ['', 'This field is required'],
513                     [' ', 'Leading/trailing whitespaces not allowed'],
514                     [' foo', 'Leading/trailing whitespaces not allowed'],
515                     ['foo ', 'Leading/trailing whitespaces not allowed'],
516                     ['//foo', 'Empty dir name not allowed']
517                 ]
518                 illegalNamesFromUI.forEach(([name, errMsg]) => {
519                     cy.get('[data-cy=collection-files-panel]')
520                         .contains('bar').rightclick();
521                     cy.get('[data-cy=context-menu]')
522                         .contains('Rename')
523                         .click();
524                     cy.get('[data-cy=form-dialog]')
525                         .should('contain', 'Rename')
526                         .within(() => {
527                             cy.get('input').type(`{selectall}{backspace}${name}`);
528                         });
529                     cy.get('[data-cy=form-dialog]')
530                         .should('contain', 'Rename')
531                         .within(() => {
532                             cy.contains(`${errMsg}`);
533                         });
534                     cy.get('[data-cy=form-cancel-btn]').click();
535                 })
536             });
537     });
538
539     it('can correctly display old versions', function () {
540         const colName = `Versioned Collection ${Math.floor(Math.random() * 999999)}`;
541         let colUuid = '';
542         let oldVersionUuid = '';
543         // Make sure no other collections with this name exist
544         cy.doRequest('GET', '/arvados/v1/collections', null, {
545             filters: `[["name", "=", "${colName}"]]`,
546             include_old_versions: true
547         })
548             .its('body.items').as('collections')
549             .then(function () {
550                 expect(this.collections).to.be.empty;
551             });
552         // Creates the collection using the admin token so we can set up
553         // a bogus manifest text without block signatures.
554         cy.createCollection(adminUser.token, {
555             name: colName,
556             owner_uuid: activeUser.user.uuid,
557             preserve_version: true,
558             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
559         })
560             .as('originalVersion').then(function () {
561                 // Change the file name to create a new version.
562                 cy.updateCollection(adminUser.token, this.originalVersion.uuid, {
563                     manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo\n"
564                 })
565                 colUuid = this.originalVersion.uuid;
566             });
567         // Confirm that there are 2 versions of the collection
568         cy.doRequest('GET', '/arvados/v1/collections', null, {
569             filters: `[["name", "=", "${colName}"]]`,
570             include_old_versions: true
571         })
572             .its('body.items').as('collections')
573             .then(function () {
574                 expect(this.collections).to.have.lengthOf(2);
575                 this.collections.map(function (aCollection) {
576                     expect(aCollection.current_version_uuid).to.equal(colUuid);
577                     if (aCollection.uuid !== aCollection.current_version_uuid) {
578                         oldVersionUuid = aCollection.uuid;
579                     }
580                 });
581                 // Check the old version displays as what it is.
582                 cy.loginAs(activeUser)
583                 cy.goToPath(`/collections/${oldVersionUuid}`);
584
585                 cy.get('[data-cy=collection-info-panel]').should('contain', 'This is an old version');
586                 cy.get('[data-cy=read-only-icon]').should('exist');
587                 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
588                 cy.get('[data-cy=collection-files-panel]').should('contain', 'bar');
589             });
590     });
591
592     it('views & edits storage classes data', function () {
593         const colName= `Test Collection ${Math.floor(Math.random() * 999999)}`;
594         cy.createCollection(adminUser.token, {
595             name: colName,
596             owner_uuid: activeUser.user.uuid,
597             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:some-file\n",
598         }).as('collection').then(function () {
599             expect(this.collection.storage_classes_desired).to.deep.equal(['default'])
600
601             cy.loginAs(activeUser)
602             cy.goToPath(`/collections/${this.collection.uuid}`);
603
604             // Initial check: it should show the 'default' storage class
605             cy.get('[data-cy=collection-info-panel]')
606                 .should('contain', 'Storage classes')
607                 .and('contain', 'default')
608                 .and('not.contain', 'foo')
609                 .and('not.contain', 'bar');
610             // Edit collection: add storage class 'foo'
611             cy.get('[data-cy=collection-panel-options-btn]').click();
612             cy.get('[data-cy=context-menu]').contains('Edit collection').click();
613             cy.get('[data-cy=form-dialog]')
614                 .should('contain', 'Edit Collection')
615                 .and('contain', 'Storage classes')
616                 .and('contain', 'default')
617                 .and('contain', 'foo')
618                 .and('contain', 'bar')
619                 .within(() => {
620                     cy.get('[data-cy=checkbox-foo]').click();
621                 });
622             cy.get('[data-cy=form-submit-btn]').click();
623             cy.get('[data-cy=collection-info-panel]')
624                 .should('contain', 'default')
625                 .and('contain', 'foo')
626                 .and('not.contain', 'bar');
627             cy.doRequest('GET', `/arvados/v1/collections/${this.collection.uuid}`)
628                 .its('body').as('updatedCollection')
629                 .then(function () {
630                     expect(this.updatedCollection.storage_classes_desired).to.deep.equal(['default', 'foo']);
631                 });
632             // Edit collection: remove storage class 'default'
633             cy.get('[data-cy=collection-panel-options-btn]').click();
634             cy.get('[data-cy=context-menu]').contains('Edit collection').click();
635             cy.get('[data-cy=form-dialog]')
636                 .should('contain', 'Edit Collection')
637                 .and('contain', 'Storage classes')
638                 .and('contain', 'default')
639                 .and('contain', 'foo')
640                 .and('contain', 'bar')
641                 .within(() => {
642                     cy.get('[data-cy=checkbox-default]').click();
643                 });
644             cy.get('[data-cy=form-submit-btn]').click();
645             cy.get('[data-cy=collection-info-panel]')
646                 .should('not.contain', 'default')
647                 .and('contain', 'foo')
648                 .and('not.contain', 'bar');
649             cy.doRequest('GET', `/arvados/v1/collections/${this.collection.uuid}`)
650                 .its('body').as('updatedCollection')
651                 .then(function () {
652                     expect(this.updatedCollection.storage_classes_desired).to.deep.equal(['foo']);
653                 });
654         })
655     });
656
657     it('moves a collection to a different project', function () {
658         const collName = `Test Collection ${Math.floor(Math.random() * 999999)}`;
659         const projName = `Test Project ${Math.floor(Math.random() * 999999)}`;
660         const fileName = `Test_File_${Math.floor(Math.random() * 999999)}`;
661
662         cy.createCollection(adminUser.token, {
663             name: collName,
664             owner_uuid: activeUser.user.uuid,
665             manifest_text: `. 37b51d194a7513e45b56f6524f2d51f2+3 0:3:${fileName}\n`,
666         }).as('testCollection');
667         cy.createGroup(adminUser.token, {
668             name: projName,
669             group_class: 'project',
670             owner_uuid: activeUser.user.uuid,
671         }).as('testProject');
672
673         cy.getAll('@testCollection', '@testProject')
674             .then(function ([testCollection, testProject]) {
675                 cy.loginAs(activeUser);
676                 cy.goToPath(`/collections/${testCollection.uuid}`);
677                 cy.get('[data-cy=collection-files-panel]').should('contain', fileName);
678                 cy.get('[data-cy=collection-info-panel]')
679                     .should('not.contain', projName)
680                     .and('not.contain', testProject.uuid);
681                 cy.get('[data-cy=collection-panel-options-btn]').click();
682                 cy.get('[data-cy=context-menu]').contains('Move to').click();
683                 cy.get('[data-cy=form-dialog]')
684                     .should('contain', 'Move to')
685                     .within(() => {
686                         // must use .then to avoid selecting instead of expanding https://github.com/cypress-io/cypress/issues/5529
687                         cy.get('[data-cy=projects-tree-home-tree-picker]')
688                             .find('i')
689                             .then(el => el.click());
690                         cy.get('[data-cy=projects-tree-home-tree-picker]')
691                             .contains(projName)
692                             .click();
693                     });
694                 cy.get('[data-cy=form-submit-btn]').click();
695                 cy.get('[data-cy=snackbar]')
696                     .contains('Collection has been moved')
697                 cy.get('[data-cy=collection-info-panel]')
698                     .contains(projName).and('contain', testProject.uuid);
699                 // Double check that the collection is in the project
700                 cy.goToPath(`/projects/${testProject.uuid}`);
701                 cy.waitForDom().get('[data-cy=project-panel]').should('contain', collName);
702             });
703     });
704
705     it('automatically updates the collection UI contents without using the Refresh button', function () {
706         const collName = `Test Collection ${Math.floor(Math.random() * 999999)}`;
707
708         cy.createCollection(adminUser.token, {
709             name: collName,
710             owner_uuid: activeUser.user.uuid,
711         }).as('testCollection');
712
713         cy.getAll('@testCollection').then(function ([testCollection]) {
714             cy.loginAs(activeUser);
715
716             const files = [
717                 "foobar",
718                 "anotherFile",
719                 "",
720                 "finalName",
721             ];
722
723             cy.goToPath(`/collections/${testCollection.uuid}`);
724             cy.get('[data-cy=collection-files-panel]').should('contain', 'This collection is empty');
725             cy.get('[data-cy=collection-files-panel]').should('not.contain', files[0]);
726             cy.get('[data-cy=collection-info-panel]').should('contain', collName);
727
728             files.map((fileName, i, files) => {
729                 cy.updateCollection(adminUser.token, testCollection.uuid, {
730                     name: `${collName + ' updated'}`,
731                     manifest_text: fileName ? `. 37b51d194a7513e45b56f6524f2d51f2+3 0:3:${fileName}\n` : "",
732                 }).as('updatedCollection');
733                 cy.getAll('@updatedCollection').then(function ([updatedCollection]) {
734                     expect(updatedCollection.name).to.equal(`${collName + ' updated'}`);
735                     cy.get('[data-cy=collection-info-panel]').should('contain', updatedCollection.name);
736                     fileName
737                         ? cy.get('[data-cy=collection-files-panel]').should('contain', fileName)
738                         : cy.get('[data-cy=collection-files-panel]').should('not.contain', files[i-1]);;
739                 });
740             });
741
742         });
743     });
744
745     it('makes a copy of an existing collection', function() {
746         const collName = `Test Collection ${Math.floor(Math.random() * 999999)}`;
747         const copyName = `Copy of: ${collName}`;
748
749         cy.createCollection(adminUser.token, {
750             name: collName,
751             owner_uuid: activeUser.user.uuid,
752             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:some-file\n",
753         }).as('collection').then(function () {
754             cy.loginAs(activeUser)
755             cy.goToPath(`/collections/${this.collection.uuid}`);
756             cy.get('[data-cy=collection-files-panel]')
757                 .should('contain', 'some-file');
758             cy.get('[data-cy=collection-panel-options-btn]').click();
759             cy.get('[data-cy=context-menu]').contains('Make a copy').click();
760             cy.get('[data-cy=form-dialog]')
761                 .should('contain', 'Make a copy')
762                 .within(() => {
763                     cy.get('[data-cy=projects-tree-home-tree-picker]')
764                         .contains('Projects')
765                         .click();
766                     cy.get('[data-cy=form-submit-btn]').click();
767                 });
768             cy.get('[data-cy=snackbar]')
769                 .contains('Collection has been copied.')
770             cy.get('[data-cy=snackbar-goto-action]').click();
771             cy.get('[data-cy=project-panel]')
772                 .contains(copyName).click();
773             cy.get('[data-cy=collection-files-panel]')
774                 .should('contain', 'some-file');
775         });
776     });
777
778     it('uses the collection version browser to view a previous version', function () {
779         const colName = `Test Collection ${Math.floor(Math.random() * 999999)}`;
780
781         // Creates the collection using the admin token so we can set up
782         // a bogus manifest text without block signatures.
783         cy.createCollection(adminUser.token, {
784             name: colName,
785             owner_uuid: activeUser.user.uuid,
786             preserve_version: true,
787             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo 0:3:bar\n"
788         })
789             .as('collection').then(function () {
790                 // Visit collection, check basic information
791                 cy.loginAs(activeUser)
792                 cy.goToPath(`/collections/${this.collection.uuid}`);
793
794                 cy.get('[data-cy=collection-info-panel]').should('not.contain', 'This is an old version');
795                 cy.get('[data-cy=read-only-icon]').should('not.exist');
796                 cy.get('[data-cy=collection-version-number]').should('contain', '1');
797                 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
798                 cy.get('[data-cy=collection-files-panel]').should('contain', 'foo').and('contain', 'bar');
799
800                 // Modify collection, expect version number change
801                 cy.get('[data-cy=collection-files-panel]').contains('foo').rightclick();
802                 cy.get('[data-cy=context-menu]').contains('Remove').click();
803                 cy.get('[data-cy=confirmation-dialog]').should('contain', 'Removing file');
804                 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
805                 cy.get('[data-cy=collection-version-number]').should('contain', '2');
806                 cy.get('[data-cy=collection-files-panel]').should('not.contain', 'foo').and('contain', 'bar');
807
808                 // Click on version number, check version browser. Click on past version.
809                 cy.get('[data-cy=collection-version-browser]').should('not.exist');
810                 cy.get('[data-cy=collection-version-number]').contains('2').click();
811                 cy.get('[data-cy=collection-version-browser]')
812                     .should('contain', 'Nr').and('contain', 'Size').and('contain', 'Date')
813                     .within(() => {
814                         // Version 1: 6 bytes in size
815                         cy.get('[data-cy=collection-version-browser-select-1]')
816                             .should('contain', '1')
817                             .and('contain', '6 B')
818                             .and('contain', adminUser.user.full_name);
819                         // Version 2: 3 bytes in size (one file removed)
820                         cy.get('[data-cy=collection-version-browser-select-2]')
821                             .should('contain', '2')
822                             .and('contain', '3 B')
823                             .and('contain', activeUser.user.full_name);
824                         cy.get('[data-cy=collection-version-browser-select-3]')
825                             .should('not.exist');
826                         cy.get('[data-cy=collection-version-browser-select-1]')
827                             .click();
828                     });
829                 cy.get('[data-cy=collection-info-panel]').should('contain', 'This is an old version');
830                 cy.get('[data-cy=read-only-icon]').should('exist');
831                 cy.get('[data-cy=collection-version-number]').should('contain', '1');
832                 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
833                 cy.get('[data-cy=collection-files-panel]')
834                     .should('contain', 'foo').and('contain', 'bar');
835
836                 // Check that only old collection action are available on context menu
837                 cy.get('[data-cy=collection-panel-options-btn]').click();
838                 cy.get('[data-cy=context-menu]')
839                     .should('contain', 'Restore version')
840                     .and('not.contain', 'Add to favorites');
841                 cy.get('body').click(); // Collapse the menu avoiding details panel expansion
842
843                 // Click on "head version" link, confirm that it's the latest version.
844                 cy.get('[data-cy=collection-info-panel]').contains('head version').click();
845                 cy.get('[data-cy=collection-info-panel]')
846                     .should('not.contain', 'This is an old version');
847                 cy.get('[data-cy=read-only-icon]').should('not.exist');
848                 cy.get('[data-cy=collection-version-number]').should('contain', '2');
849                 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
850                 cy.get('[data-cy=collection-files-panel]').
851                     should('not.contain', 'foo').and('contain', 'bar');
852
853                 // Check that old collection action isn't available on context menu
854                 cy.get('[data-cy=collection-panel-options-btn]').click()
855                 cy.get('[data-cy=context-menu]').should('not.contain', 'Restore version')
856                 cy.get('body').click(); // Collapse the menu avoiding details panel expansion
857
858                 // Make another change, confirm new version.
859                 cy.get('[data-cy=collection-panel-options-btn]').click();
860                 cy.get('[data-cy=context-menu]').contains('Edit collection').click();
861                 cy.get('[data-cy=form-dialog]')
862                     .should('contain', 'Edit Collection')
863                     .within(() => {
864                         // appends some text
865                         cy.get('input').first().type(' renamed');
866                     });
867                 cy.get('[data-cy=form-submit-btn]').click();
868                 cy.get('[data-cy=collection-info-panel]')
869                     .should('not.contain', 'This is an old version');
870                 cy.get('[data-cy=read-only-icon]').should('not.exist');
871                 cy.get('[data-cy=collection-version-number]').should('contain', '3');
872                 cy.get('[data-cy=collection-info-panel]').should('contain', colName + ' renamed');
873                 cy.get('[data-cy=collection-files-panel]')
874                     .should('not.contain', 'foo').and('contain', 'bar');
875                 cy.get('[data-cy=collection-version-browser-select-3]')
876                     .should('contain', '3').and('contain', '3 B');
877
878                 // Check context menus on version browser
879                 cy.waitForDom();
880                 cy.get('[data-cy=collection-version-browser-select-3]').rightclick()
881                 cy.get('[data-cy=context-menu]')
882                     .should('contain', 'Add to favorites')
883                     .and('contain', 'Make a copy')
884                     .and('contain', 'Edit collection');
885                 cy.get('body').click();
886                 // (and now an old version...)
887                 cy.get('[data-cy=collection-version-browser-select-1]').rightclick()
888                 cy.get('[data-cy=context-menu]')
889                     .should('not.contain', 'Add to favorites')
890                     .and('contain', 'Make a copy')
891                     .and('not.contain', 'Edit collection');
892                 cy.get('body').click();
893
894                 // Restore first version
895                 cy.get('[data-cy=collection-version-browser]').within(() => {
896                     cy.get('[data-cy=collection-version-browser-select-1]').click();
897                 });
898                 cy.get('[data-cy=collection-panel-options-btn]').click()
899                 cy.get('[data-cy=context-menu]').contains('Restore version').click();
900                 cy.get('[data-cy=confirmation-dialog]').should('contain', 'Restore version');
901                 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
902                 cy.get('[data-cy=collection-info-panel]')
903                     .should('not.contain', 'This is an old version');
904                 cy.get('[data-cy=collection-version-number]').should('contain', '4');
905                 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
906                 cy.get('[data-cy=collection-files-panel]')
907                     .should('contain', 'foo').and('contain', 'bar');
908             });
909     });
910
911     it('copies selected files into new collection', () => {
912         cy.createCollection(adminUser.token, {
913             name: `Test Collection ${Math.floor(Math.random() * 999999)}`,
914             owner_uuid: activeUser.user.uuid,
915             preserve_version: true,
916             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo 0:3:bar\n"
917         })
918             .as('collection').then(function () {
919                 // Visit collection, check basic information
920                 cy.loginAs(activeUser)
921                 cy.goToPath(`/collections/${this.collection.uuid}`);
922
923                 cy.get('[data-cy=collection-files-panel]').within(() => {
924                     cy.get('input[type=checkbox]').first().click();
925                 });
926
927                 cy.get('[data-cy=collection-files-panel-options-btn]').click();
928                 cy.get('[data-cy=context-menu]').contains('Copy selected into new collection').click();
929
930                 cy.get('[data-cy=form-dialog]').contains('Projects').click();
931
932                 cy.get('[data-cy=form-submit-btn]').click();
933
934                 cy.waitForDom().get('.layout-pane-primary', { timeout: 12000 }).contains('Projects').click();
935
936                 cy.waitForDom().get('main').contains(`Files extracted from: ${this.collection.name}`).click();
937                 cy.get('[data-cy=collection-files-panel]')
938                         .and('contain', 'bar');
939             });
940     });
941
942     it('copies selected files into existing collection', () => {
943         cy.createCollection(adminUser.token, {
944             name: `Test Collection ${Math.floor(Math.random() * 999999)}`,
945             owner_uuid: activeUser.user.uuid,
946             preserve_version: true,
947             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo 0:3:bar\n"
948         }).as('sourceCollection')
949
950         cy.createCollection(adminUser.token, {
951             name: `Destination Collection ${Math.floor(Math.random() * 999999)}`,
952             owner_uuid: activeUser.user.uuid,
953             preserve_version: true,
954             manifest_text: ""
955         }).as('destinationCollection');
956
957         cy.getAll('@sourceCollection', '@destinationCollection').then(function ([sourceCollection, destinationCollection]) {
958                 // Visit collection, check basic information
959                 cy.loginAs(activeUser)
960                 cy.goToPath(`/collections/${sourceCollection.uuid}`);
961
962                 cy.get('[data-cy=collection-files-panel]').within(() => {
963                     cy.get('input[type=checkbox]').first().click();
964                 });
965
966                 cy.get('[data-cy=collection-files-panel-options-btn]').click();
967                 cy.get('[data-cy=context-menu]').contains('Copy selected into existing collection').click();
968
969                 cy.get('[data-cy=form-dialog]').contains(destinationCollection.name).click();
970
971                 cy.get('[data-cy=form-submit-btn]').click();
972                 cy.wait(2000);
973
974                 cy.goToPath(`/collections/${destinationCollection.uuid}`);
975
976                 cy.get('main').contains(destinationCollection.name).should('exist');
977                 cy.get('[data-cy=collection-files-panel]')
978                         .and('contain', 'bar');
979             });
980     });
981
982     it('copies selected files into separate collections', () => {
983         cy.createCollection(adminUser.token, {
984             name: `Test Collection ${Math.floor(Math.random() * 999999)}`,
985             owner_uuid: activeUser.user.uuid,
986             preserve_version: true,
987             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo 0:3:bar\n"
988         }).as('sourceCollection')
989
990         cy.getAll('@sourceCollection').then(function ([sourceCollection]) {
991                 // Visit collection, check basic information
992                 cy.loginAs(activeUser)
993                 cy.goToPath(`/collections/${sourceCollection.uuid}`);
994
995                 // Select both files
996                 cy.waitForDom().get('[data-cy=collection-files-panel]').within(() => {
997                     cy.get('input[type=checkbox]').first().click();
998                     cy.get('input[type=checkbox]').last().click();
999                 });
1000
1001                 // Copy to separate collections
1002                 cy.get('[data-cy=collection-files-panel-options-btn]').click();
1003                 cy.get('[data-cy=context-menu]').contains('Copy selected into separate collections').click();
1004                 cy.get('[data-cy=form-dialog]').contains('Projects').click();
1005                 cy.get('[data-cy=form-submit-btn]').click();
1006
1007                 // Verify created collections
1008                 cy.waitForDom().get('.layout-pane-primary', { timeout: 12000 }).contains('Projects').click();
1009                 cy.get('main').contains(`File copied from collection ${sourceCollection.name}/foo`).click();
1010                 cy.get('[data-cy=collection-files-panel]')
1011                         .and('contain', 'foo');
1012                 cy.get('.layout-pane-primary').contains('Projects').click();
1013                 cy.get('main').contains(`File copied from collection ${sourceCollection.name}/bar`).click();
1014                 cy.get('[data-cy=collection-files-panel]')
1015                         .and('contain', 'bar');
1016
1017                 // Verify separate collection menu items not present when single file selected
1018                 // Wait for dom for collection to re-render
1019                 cy.waitForDom().get('[data-cy=collection-files-panel]').within(() => {
1020                     cy.get('input[type=checkbox]').first().click();
1021                 });
1022                 cy.get('[data-cy=collection-files-panel-options-btn]').click();
1023                 cy.get('[data-cy=context-menu]').should('not.contain', 'Copy selected into separate collections');
1024                 cy.get('[data-cy=context-menu]').should('not.contain', 'Move selected into separate collections');
1025             });
1026     });
1027
1028     it('moves selected files into new collection', () => {
1029         cy.createCollection(adminUser.token, {
1030             name: `Test Collection ${Math.floor(Math.random() * 999999)}`,
1031             owner_uuid: activeUser.user.uuid,
1032             preserve_version: true,
1033             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo 0:3:bar\n"
1034         })
1035             .as('collection').then(function () {
1036                 // Visit collection, check basic information
1037                 cy.loginAs(activeUser)
1038                 cy.goToPath(`/collections/${this.collection.uuid}`);
1039
1040                 cy.get('[data-cy=collection-files-panel]').within(() => {
1041                     cy.get('input[type=checkbox]').first().click();
1042                 });
1043
1044                 cy.get('[data-cy=collection-files-panel-options-btn]').click();
1045                 cy.get('[data-cy=context-menu]').contains('Move selected into new collection').click();
1046
1047                 cy.get('[data-cy=form-dialog]').contains('Projects').click();
1048
1049                 cy.get('[data-cy=form-submit-btn]').click();
1050
1051                 cy.waitForDom().get('.layout-pane-primary', { timeout: 12000 }).contains('Projects').click();
1052
1053                 cy.get('main').contains(`Files moved from: ${this.collection.name}`).click();
1054                 cy.get('[data-cy=collection-files-panel]')
1055                         .and('contain', 'bar');
1056             });
1057     });
1058
1059     it('moves selected files into existing collection', () => {
1060         cy.createCollection(adminUser.token, {
1061             name: `Test Collection ${Math.floor(Math.random() * 999999)}`,
1062             owner_uuid: activeUser.user.uuid,
1063             preserve_version: true,
1064             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo 0:3:bar\n"
1065         }).as('sourceCollection')
1066
1067         cy.createCollection(adminUser.token, {
1068             name: `Destination Collection ${Math.floor(Math.random() * 999999)}`,
1069             owner_uuid: activeUser.user.uuid,
1070             preserve_version: true,
1071             manifest_text: ""
1072         }).as('destinationCollection');
1073
1074         cy.getAll('@sourceCollection', '@destinationCollection').then(function ([sourceCollection, destinationCollection]) {
1075                 // Visit collection, check basic information
1076                 cy.loginAs(activeUser)
1077                 cy.goToPath(`/collections/${sourceCollection.uuid}`);
1078
1079                 cy.get('[data-cy=collection-files-panel]').within(() => {
1080                     cy.get('input[type=checkbox]').first().click();
1081                 });
1082
1083                 cy.get('[data-cy=collection-files-panel-options-btn]').click();
1084                 cy.get('[data-cy=context-menu]').contains('Move selected into existing collection').click();
1085
1086                 cy.get('[data-cy=form-dialog]').contains(destinationCollection.name).click();
1087
1088                 cy.get('[data-cy=form-submit-btn]').click();
1089                 cy.wait(2000);
1090
1091                 cy.goToPath(`/collections/${destinationCollection.uuid}`);
1092
1093                 cy.get('main').contains(destinationCollection.name).should('exist');
1094                 cy.get('[data-cy=collection-files-panel]')
1095                         .and('contain', 'bar');
1096             });
1097     });
1098
1099     it('moves selected files into separate collections', () => {
1100         cy.createCollection(adminUser.token, {
1101             name: `Test Collection ${Math.floor(Math.random() * 999999)}`,
1102             owner_uuid: activeUser.user.uuid,
1103             preserve_version: true,
1104             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo 0:3:bar\n"
1105         }).as('sourceCollection')
1106
1107         cy.getAll('@sourceCollection').then(function ([sourceCollection]) {
1108                 // Visit collection, check basic information
1109                 cy.loginAs(activeUser)
1110                 cy.goToPath(`/collections/${sourceCollection.uuid}`);
1111
1112                 // Select both files
1113                 cy.get('[data-cy=collection-files-panel]').within(() => {
1114                     cy.get('input[type=checkbox]').first().click();
1115                     cy.get('input[type=checkbox]').last().click();
1116                 });
1117
1118                 // Copy to separate collections
1119                 cy.get('[data-cy=collection-files-panel-options-btn]').click();
1120                 cy.get('[data-cy=context-menu]').contains('Move selected into separate collections').click();
1121                 cy.get('[data-cy=form-dialog]').contains('Projects').click();
1122                 cy.get('[data-cy=form-submit-btn]').click();
1123
1124                 // Verify created collections
1125                 cy.waitForDom().get('.layout-pane-primary', { timeout: 12000 }).contains('Projects').click();
1126                 cy.get('main').contains(`File moved from collection ${sourceCollection.name}/foo`).click();
1127                 cy.get('[data-cy=collection-files-panel]')
1128                         .and('contain', 'foo');
1129                 cy.get('.layout-pane-primary').contains('Projects').click();
1130                 cy.get('main').contains(`File moved from collection ${sourceCollection.name}/bar`).click();
1131                 cy.get('[data-cy=collection-files-panel]')
1132                         .and('contain', 'bar');
1133             });
1134     });
1135
1136     it('creates new collection with properties on home project', function () {
1137         cy.loginAs(activeUser);
1138         cy.goToPath(`/projects/${activeUser.user.uuid}`);
1139         cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
1140         cy.get('[data-cy=breadcrumb-last]').should('not.exist');
1141         // Create new collection
1142         cy.get('[data-cy=side-panel-button]').click();
1143         cy.get('[data-cy=side-panel-new-collection]').click();
1144         // Name between brackets tests bugfix #17582
1145         const collName = `[Test collection (${Math.floor(999999 * Math.random())})]`;
1146
1147         // Select a storage class.
1148         cy.get('[data-cy=form-dialog]')
1149             .should('contain', 'New collection')
1150             .and('contain', 'Storage classes')
1151             .and('contain', 'default')
1152             .and('contain', 'foo')
1153             .and('contain', 'bar')
1154             .within(() => {
1155                 cy.get('[data-cy=parent-field]').within(() => {
1156                     cy.get('input').should('have.value', 'Home project');
1157                 });
1158                 cy.get('[data-cy=name-field]').within(() => {
1159                     cy.get('input').type(collName);
1160                 });
1161                 cy.get('[data-cy=checkbox-foo]').click();
1162             })
1163
1164         // Add a property.
1165         // Key: Color (IDTAGCOLORS) - Value: Magenta (IDVALCOLORS3)
1166         cy.get('[data-cy=form-dialog]').should('not.contain', 'Color: Magenta');
1167         cy.get('[data-cy=resource-properties-form]').within(() => {
1168             cy.get('[data-cy=property-field-key]').within(() => {
1169                 cy.get('input').type('Color');
1170             });
1171             cy.get('[data-cy=property-field-value]').within(() => {
1172                 cy.get('input').type('Magenta');
1173             });
1174             cy.root().submit();
1175         });
1176         // Confirm proper vocabulary labels are displayed on the UI.
1177         cy.get('[data-cy=form-dialog]').should('contain', 'Color: Magenta');
1178
1179         // Value field should not complain about being required just after
1180         // adding a new property. See #19732
1181         cy.get('[data-cy=form-dialog]').should('not.contain', 'This field is required');
1182
1183         cy.get('[data-cy=form-submit-btn]').click();
1184         // Confirm that the user was taken to the newly created collection
1185         cy.get('[data-cy=form-dialog]').should('not.exist');
1186         cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
1187         cy.get('[data-cy=breadcrumb-last]').should('contain', collName);
1188         cy.get('[data-cy=collection-info-panel]')
1189             .should('contain', 'default')
1190             .and('contain', 'foo')
1191             .and('contain', 'Color: Magenta')
1192             .and('not.contain', 'bar');
1193         // Confirm that the collection's properties has the real values.
1194         cy.doRequest('GET', '/arvados/v1/collections', null, {
1195             filters: `[["name", "=", "${collName}"]]`,
1196         })
1197         .its('body.items').as('collections')
1198         .then(function() {
1199             expect(this.collections).to.have.lengthOf(1);
1200             expect(this.collections[0].properties).to.have.property(
1201                 'IDTAGCOLORS', 'IDVALCOLORS3');
1202         });
1203     });
1204
1205     it('shows responsible person for collection if available', () => {
1206         cy.createCollection(adminUser.token, {
1207             name: `Test collection ${Math.floor(Math.random() * 999999)}`,
1208             owner_uuid: activeUser.user.uuid,
1209             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
1210         }).as('testCollection1');
1211
1212         cy.createCollection(adminUser.token, {
1213             name: `Test collection ${Math.floor(Math.random() * 999999)}`,
1214             owner_uuid: adminUser.user.uuid,
1215             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
1216         }).as('testCollection2').then(function (testCollection2) {
1217             cy.shareWith(adminUser.token, activeUser.user.uuid, testCollection2.uuid, 'can_write');
1218         });
1219
1220         cy.getAll('@testCollection1', '@testCollection2')
1221             .then(function ([testCollection1, testCollection2]) {
1222                 cy.loginAs(activeUser);
1223
1224                 cy.goToPath(`/collections/${testCollection1.uuid}`);
1225                 cy.get('[data-cy=responsible-person-wrapper]')
1226                     .contains(activeUser.user.uuid);
1227
1228                 cy.goToPath(`/collections/${testCollection2.uuid}`);
1229                 cy.get('[data-cy=responsible-person-wrapper]')
1230                     .contains(adminUser.user.uuid);
1231             });
1232     });
1233
1234     describe('file upload', () => {
1235         beforeEach(() => {
1236             cy.createCollection(adminUser.token, {
1237                 name: `Test collection ${Math.floor(Math.random() * 999999)}`,
1238                 owner_uuid: activeUser.user.uuid,
1239                 manifest_text: "./subdir 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo\n. 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
1240             }).as('testCollection1');
1241         });
1242
1243         it('uploads a file and checks the collection UI to be fresh', () => {
1244             cy.getAll('@testCollection1')
1245                 .then(function([testCollection1]) {
1246                     cy.loginAs(activeUser);
1247                     cy.goToPath(`/collections/${testCollection1.uuid}`);
1248                     cy.get('[data-cy=upload-button]').click();
1249                     cy.get('[data-cy=collection-files-panel]')
1250                         .contains('5mb_a.bin').should('not.exist');
1251                     cy.get('[data-cy=collection-file-count]').should('contain', '2');
1252                     cy.fixture('files/5mb.bin', 'base64').then(content => {
1253                         cy.get('[data-cy=drag-and-drop]').upload(content, '5mb_a.bin');
1254                         cy.get('[data-cy=form-submit-btn]').click();
1255                         cy.get('[data-cy=form-submit-btn]').should('not.exist');
1256                         cy.get('[data-cy=collection-files-panel]')
1257                             .contains('5mb_a.bin').should('exist');
1258                         cy.get('[data-cy=collection-file-count]').should('contain', '3');
1259
1260                         cy.get('[data-cy=collection-files-panel]').contains('subdir').click();
1261                         cy.get('[data-cy=upload-button]').click();
1262                         cy.fixture('files/5mb.bin', 'base64').then(content => {
1263                             cy.get('[data-cy=drag-and-drop]').upload(content, '5mb_b.bin');
1264                             cy.get('[data-cy=form-submit-btn]').click();
1265                             cy.waitForDom().get('[data-cy=form-submit-btn]').should('not.exist');
1266                             // subdir gets unselected, I think this is a bug but
1267                             // for the time being let's just make sure the test works.
1268                             cy.get('[data-cy=collection-files-panel]').contains('subdir').click();
1269                             cy.waitForDom().get('[data-cy=collection-files-right-panel]')
1270                                  .contains('5mb_b.bin').should('exist');
1271                         });
1272                     });
1273                 });
1274         });
1275
1276         it('allows to cancel running upload', () => {
1277             cy.getAll('@testCollection1')
1278                 .then(function([testCollection1]) {
1279                     cy.loginAs(activeUser);
1280
1281                     cy.goToPath(`/collections/${testCollection1.uuid}`);
1282
1283                     cy.get('[data-cy=upload-button]').click();
1284
1285                     cy.fixture('files/5mb.bin', 'base64').then(content => {
1286                         cy.get('[data-cy=drag-and-drop]').upload(content, '5mb_a.bin');
1287                         cy.get('[data-cy=drag-and-drop]').upload(content, '5mb_b.bin');
1288
1289                         cy.get('[data-cy=form-submit-btn]').click();
1290
1291                         cy.get('button').contains('Cancel').click();
1292
1293                         cy.get('[data-cy=form-submit-btn]').should('not.exist');
1294                     });
1295                 });
1296         });
1297
1298         it('allows to cancel single file from the running upload', () => {
1299             cy.getAll('@testCollection1')
1300                 .then(function([testCollection1]) {
1301                     cy.loginAs(activeUser);
1302
1303                     cy.goToPath(`/collections/${testCollection1.uuid}`);
1304
1305                     cy.get('[data-cy=upload-button]').click();
1306
1307                     cy.fixture('files/5mb.bin', 'base64').then(content => {
1308                         cy.get('[data-cy=drag-and-drop]').upload(content, '5mb_a.bin');
1309                         cy.get('[data-cy=drag-and-drop]').upload(content, '5mb_b.bin');
1310
1311                         cy.get('[data-cy=form-submit-btn]').click();
1312
1313                         cy.get('button[aria-label=Remove]').eq(1).click();
1314
1315                         cy.get('[data-cy=form-submit-btn]').should('not.exist');
1316
1317                         cy.get('[data-cy=collection-files-panel]').contains('5mb_a.bin').should('exist');
1318                     });
1319                 });
1320         });
1321
1322         it('allows to cancel all files from the running upload', () => {
1323             cy.getAll('@testCollection1')
1324                 .then(function([testCollection1]) {
1325                     cy.loginAs(activeUser);
1326
1327                     cy.goToPath(`/collections/${testCollection1.uuid}`);
1328
1329                     // Confirm initial collection state.
1330                     cy.get('[data-cy=collection-files-panel]')
1331                         .contains('bar').should('exist');
1332                     cy.get('[data-cy=collection-files-panel]')
1333                         .contains('5mb_a.bin').should('not.exist');
1334                     cy.get('[data-cy=collection-files-panel]')
1335                         .contains('5mb_b.bin').should('not.exist');
1336
1337                     cy.get('[data-cy=upload-button]').click();
1338
1339                     cy.fixture('files/5mb.bin', 'base64').then(content => {
1340                         cy.get('[data-cy=drag-and-drop]').upload(content, '5mb_a.bin');
1341                         cy.get('[data-cy=drag-and-drop]').upload(content, '5mb_b.bin');
1342
1343                         cy.get('[data-cy=form-submit-btn]').click();
1344
1345                         cy.get('button[aria-label=Remove]').should('exist');
1346                         cy.get('button[aria-label=Remove]')
1347                             .click({ multiple: true, force: true });
1348
1349                         cy.get('[data-cy=form-submit-btn]').should('not.exist');
1350
1351                         // Confirm final collection state.
1352                         cy.get('[data-cy=collection-files-panel]')
1353                             .contains('bar').should('exist');
1354                         // The following fails, but doesn't seem to happen
1355                         // in the real world. Maybe there's a race between
1356                         // the PUT request finishing and the 'Remove' button
1357                         // dissapearing, because sometimes just one of the 2
1358                         // files gets uploaded.
1359                         // Maybe this will be needed to simulate a slow network:
1360                         // https://docs.cypress.io/api/commands/intercept#Convenience-functions-1
1361                         // cy.get('[data-cy=collection-files-panel]')
1362                         //     .contains('5mb_a.bin').should('not.exist');
1363                         // cy.get('[data-cy=collection-files-panel]')
1364                         //     .contains('5mb_b.bin').should('not.exist');
1365                     });
1366                 });
1367         });
1368     });
1369 })