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