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