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