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