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