1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 const path = require('path');
7 describe('Collection panel tests', 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;
22 cy.getUser('collectionuser1', 'Collection', 'User', false, true)
23 .as('activeUser').then(function () {
24 activeUser = this.activeUser;
27 downloadsFolder = Cypress.config('downloadsFolder');
30 beforeEach(function () {
32 cy.clearLocalStorage();
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"
41 .as('testCollection').then(function (testCollection) {
42 cy.loginAs(activeUser);
43 cy.doSearch(`${testCollection.uuid}`);
45 cy.get('[data-cy=collection-panel-options-btn]').click();
46 cy.get('[data-cy=context-menu]').contains('Open as network folder or S3 bucket').click();
47 cy.get('[data-cy=download-button').click();
49 const filename = path.join(downloadsFolder, `${testCollection.name}.duck`);
51 cy.readFile(filename, { timeout: 15000 })
53 const childrenCollection = Array.prototype.slice.call(Cypress.$(body).find('dict')[0].children);
57 for (i=0; i < childrenCollection.length; i += j) {
58 map[childrenCollection[i].outerText] = childrenCollection[i + 1].outerText;
61 cy.get('#simple-tabpanel-0').find('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 expect(map['Path']).to.equal(`/c=${testCollection.uuid}`);
72 .then(() => cy.task('clearDownload', { filename }));
76 it('uses the property editor with vocabulary terms', function () {
77 cy.createCollection(adminUser.token, {
78 name: `Test collection ${Math.floor(Math.random() * 999999)}`,
79 owner_uuid: activeUser.user.uuid,
80 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
82 .as('testCollection').then(function () {
83 cy.loginAs(activeUser);
84 cy.goToPath(`/collections/${this.testCollection.uuid}`);
86 // Key: Color (IDTAGCOLORS) - Value: Magenta (IDVALCOLORS3)
87 cy.get('[data-cy=resource-properties-form]').within(() => {
88 cy.get('[data-cy=property-field-key]').within(() => {
89 cy.get('input').type('Color');
91 cy.get('[data-cy=property-field-value]').within(() => {
92 cy.get('input').type('Magenta');
96 // Confirm proper vocabulary labels are displayed on the UI.
97 cy.get('[data-cy=collection-properties-panel]')
98 .should('contain', 'Color')
99 .and('contain', 'Magenta');
100 // Confirm proper vocabulary IDs were saved on the backend.
101 cy.doRequest('GET', `/arvados/v1/collections/${this.testCollection.uuid}`)
102 .its('body').as('collection')
104 expect(this.collection.properties).to.deep.equal(
105 { IDTAGCOLORS: 'IDVALCOLORS3' });
110 it('shows collection by URL', function () {
111 cy.loginAs(activeUser);
112 [true, false].map(function (isWritable) {
113 // Using different file names to avoid test flakyness: the second iteration
114 // on this loop may pass an assertion from the first iteration by looking
115 // for the same file name.
116 const fileName = isWritable ? 'bar' : 'foo';
117 cy.createGroup(adminUser.token, {
118 name: 'Shared project',
119 group_class: 'project',
120 }).as('sharedGroup').then(function () {
121 // Creates the collection using the admin token so we can set up
122 // a bogus manifest text without block signatures.
123 cy.createCollection(adminUser.token, {
124 name: 'Test collection',
125 owner_uuid: this.sharedGroup.uuid,
126 properties: { someKey: 'someValue' },
127 manifest_text: `. 37b51d194a7513e45b56f6524f2d51f2+3 0:3:${fileName}\n`
129 .as('testCollection').then(function () {
130 // Share the group with active user.
131 cy.createLink(adminUser.token, {
132 name: isWritable ? 'can_write' : 'can_read',
133 link_class: 'permission',
134 head_uuid: this.sharedGroup.uuid,
135 tail_uuid: activeUser.user.uuid
137 cy.goToPath(`/collections/${this.testCollection.uuid}`);
139 // Check that name & uuid are correct.
140 cy.get('[data-cy=collection-info-panel]')
141 .should('contain', this.testCollection.name)
142 .and('contain', this.testCollection.uuid)
143 .and('not.contain', 'This is an old version');
144 // Check for the read-only icon
145 cy.get('[data-cy=read-only-icon]').should(`${isWritable ? 'not.' : ''}exist`);
146 // Check that both read and write operations are available on
147 // the 'More options' menu.
148 cy.get('[data-cy=collection-panel-options-btn]')
150 cy.get('[data-cy=context-menu]')
151 .should('contain', 'Add to favorites')
152 .and(`${isWritable ? '' : 'not.'}contain`, 'Edit collection');
153 cy.get('body').click(); // Collapse the menu avoiding details panel expansion
154 cy.get('[data-cy=collection-properties-panel]')
155 .should('contain', 'someKey')
156 .and('contain', 'someValue')
157 .and('not.contain', 'anotherKey')
158 .and('not.contain', 'anotherValue')
159 if (isWritable === true) {
160 // Check that properties can be added.
161 cy.get('[data-cy=resource-properties-form]').within(() => {
162 cy.get('[data-cy=property-field-key]').within(() => {
163 cy.get('input').type('anotherKey');
165 cy.get('[data-cy=property-field-value]').within(() => {
166 cy.get('input').type('anotherValue');
170 cy.get('[data-cy=collection-properties-panel]')
171 .should('contain', 'anotherKey')
172 .and('contain', 'anotherValue')
174 // Properties form shouldn't be displayed.
175 cy.get('[data-cy=resource-properties-form]').should('not.exist');
177 // Check that the file listing show both read & write operations
178 cy.get('[data-cy=collection-files-panel]').within(() => {
179 cy.root().should('contain', fileName);
181 cy.get('[data-cy=upload-button]')
182 .should(`${isWritable ? '' : 'not.'}contain`, 'Upload data');
185 cy.get('[data-cy=collection-files-panel]')
186 .contains(fileName).rightclick({ force: true });
187 cy.get('[data-cy=context-menu]')
188 .should('contain', 'Download')
189 .and('contain', 'Open in new tab')
190 .and('contain', 'Copy to clipboard')
191 .and(`${isWritable ? '' : 'not.'}contain`, 'Rename')
192 .and(`${isWritable ? '' : 'not.'}contain`, 'Remove');
193 cy.get('body').click(); // Collapse the menu
194 // Hamburger 'more options' menu button
195 cy.get('[data-cy=collection-files-panel-options-btn]')
197 cy.get('[data-cy=context-menu]')
198 .should('contain', 'Select all')
200 cy.get('[data-cy=collection-files-panel-options-btn]')
202 cy.get('[data-cy=context-menu]')
203 // .should('contain', 'Download selected')
204 .should(`${isWritable ? '' : 'not.'}contain`, 'Remove selected')
205 cy.get('body').click(); // Collapse the menu
206 // File item 'more options' button
207 cy.get('[data-cy=file-item-options-btn')
209 cy.get('[data-cy=context-menu]')
210 .should('contain', 'Download')
211 .and(`${isWritable ? '' : 'not.'}contain`, 'Remove');
212 cy.get('body').click(); // Collapse the menu
218 it('renames a file using valid names', function () {
219 function eachPair(lst, func){
220 for(var i=0; i < lst.length - 1; i++){
221 func(lst[i], lst[i + 1])
224 // Creates the collection using the admin token so we can set up
225 // a bogus manifest text without block signatures.
226 cy.createCollection(adminUser.token, {
227 name: `Test collection ${Math.floor(Math.random() * 999999)}`,
228 owner_uuid: activeUser.user.uuid,
229 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
231 .as('testCollection').then(function () {
232 cy.loginAs(activeUser);
233 cy.goToPath(`/collections/${this.testCollection.uuid}`);
236 'bar', // initial name already set
243 'some name with whitespaces',
245 'is this name legal? I hope it is',
253 "G%C3%BCnter's%20file.pdf",
255 'bar' // make sure we can go back to the original name as a last step
257 eachPair(names, (from, to) => {
258 cy.get('[data-cy=collection-files-panel]')
259 .contains(`${from}`).rightclick();
260 cy.get('[data-cy=context-menu]')
263 cy.get('[data-cy=form-dialog]')
264 .should('contain', 'Rename')
266 cy.get('input').type(`{selectall}{backspace}${to}`);
268 cy.get('[data-cy=form-submit-btn]').click();
269 cy.get('[data-cy=collection-files-panel]')
270 .should('not.contain', `${from}`)
271 .and('contain', `${to}`);
276 it('renames a file to a different directory', function () {
277 // Creates the collection using the admin token so we can set up
278 // a bogus manifest text without block signatures.
279 cy.createCollection(adminUser.token, {
280 name: `Test collection ${Math.floor(Math.random() * 999999)}`,
281 owner_uuid: activeUser.user.uuid,
282 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
284 .as('testCollection').then(function () {
285 cy.loginAs(activeUser);
286 cy.goToPath(`/collections/${this.testCollection.uuid}`);
288 ['subdir', 'G%C3%BCnter\'s%20file', 'table%&?*2'].forEach((subdir) => {
289 cy.get('[data-cy=collection-files-panel]')
290 .contains('bar').rightclick({force: true});
291 cy.get('[data-cy=context-menu]')
294 cy.get('[data-cy=form-dialog]')
295 .should('contain', 'Rename')
297 cy.get('input').type(`{selectall}{backspace}${subdir}/foo`);
299 cy.get('[data-cy=form-submit-btn]').click();
300 cy.get('[data-cy=collection-files-panel]')
301 .should('not.contain', 'bar')
302 .and('contain', subdir);
303 // Look for the "arrow icon" and expand the "subdir" directory.
304 cy.get('[data-cy=virtual-file-tree] > div > i').click();
305 // Rename 'subdir/foo' to 'foo'
306 cy.get('[data-cy=collection-files-panel]')
307 .contains('foo').rightclick();
308 cy.get('[data-cy=context-menu]')
311 cy.get('[data-cy=form-dialog]')
312 .should('contain', 'Rename')
315 .should('have.value', `${subdir}/foo`)
316 .type(`{selectall}{backspace}bar`);
318 cy.get('[data-cy=form-submit-btn]').click();
319 cy.get('[data-cy=collection-files-panel]')
320 .should('contain', subdir) // empty dir kept
321 .and('contain', 'bar');
323 cy.get('[data-cy=collection-files-panel]')
324 .contains(subdir).rightclick();
325 cy.get('[data-cy=context-menu]')
328 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
333 it('tries to rename a file with illegal names', function () {
334 // Creates the collection using the admin token so we can set up
335 // a bogus manifest text without block signatures.
336 cy.createCollection(adminUser.token, {
337 name: `Test collection ${Math.floor(Math.random() * 999999)}`,
338 owner_uuid: activeUser.user.uuid,
339 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
341 .as('testCollection').then(function () {
342 cy.loginAs(activeUser);
343 cy.goToPath(`/collections/${this.testCollection.uuid}`);
345 const illegalNamesFromUI = [
346 ['.', "Name cannot be '.' or '..'"],
347 ['..', "Name cannot be '.' or '..'"],
348 ['', 'This field is required'],
349 [' ', 'Leading/trailing whitespaces not allowed'],
350 [' foo', 'Leading/trailing whitespaces not allowed'],
351 ['foo ', 'Leading/trailing whitespaces not allowed'],
352 ['//foo', 'Empty dir name not allowed']
354 illegalNamesFromUI.forEach(([name, errMsg]) => {
355 cy.get('[data-cy=collection-files-panel]')
356 .contains('bar').rightclick();
357 cy.get('[data-cy=context-menu]')
360 cy.get('[data-cy=form-dialog]')
361 .should('contain', 'Rename')
363 cy.get('input').type(`{selectall}{backspace}${name}`);
365 cy.get('[data-cy=form-dialog]')
366 .should('contain', 'Rename')
368 cy.contains(`${errMsg}`);
370 cy.get('[data-cy=form-cancel-btn]').click();
375 it('can correctly display old versions', function () {
376 const colName = `Versioned Collection ${Math.floor(Math.random() * 999999)}`;
378 let oldVersionUuid = '';
379 // Make sure no other collections with this name exist
380 cy.doRequest('GET', '/arvados/v1/collections', null, {
381 filters: `[["name", "=", "${colName}"]]`,
382 include_old_versions: true
384 .its('body.items').as('collections')
386 expect(this.collections).to.be.empty;
388 // Creates the collection using the admin token so we can set up
389 // a bogus manifest text without block signatures.
390 cy.createCollection(adminUser.token, {
392 owner_uuid: activeUser.user.uuid,
393 preserve_version: true,
394 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
396 .as('originalVersion').then(function () {
397 // Change the file name to create a new version.
398 cy.updateCollection(adminUser.token, this.originalVersion.uuid, {
399 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo\n"
401 colUuid = this.originalVersion.uuid;
403 // Confirm that there are 2 versions of the collection
404 cy.doRequest('GET', '/arvados/v1/collections', null, {
405 filters: `[["name", "=", "${colName}"]]`,
406 include_old_versions: true
408 .its('body.items').as('collections')
410 expect(this.collections).to.have.lengthOf(2);
411 this.collections.map(function (aCollection) {
412 expect(aCollection.current_version_uuid).to.equal(colUuid);
413 if (aCollection.uuid !== aCollection.current_version_uuid) {
414 oldVersionUuid = aCollection.uuid;
417 // Check the old version displays as what it is.
418 cy.loginAs(activeUser)
419 cy.goToPath(`/collections/${oldVersionUuid}`);
421 cy.get('[data-cy=collection-info-panel]').should('contain', 'This is an old version');
422 cy.get('[data-cy=read-only-icon]').should('exist');
423 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
424 cy.get('[data-cy=collection-files-panel]').should('contain', 'bar');
428 it('uses the collection version browser to view a previous version', function () {
429 const colName = `Test Collection ${Math.floor(Math.random() * 999999)}`;
431 // Creates the collection using the admin token so we can set up
432 // a bogus manifest text without block signatures.
433 cy.createCollection(adminUser.token, {
435 owner_uuid: activeUser.user.uuid,
436 preserve_version: true,
437 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo 0:3:bar\n"
439 .as('collection').then(function () {
440 // Visit collection, check basic information
441 cy.loginAs(activeUser)
442 cy.goToPath(`/collections/${this.collection.uuid}`);
444 cy.get('[data-cy=collection-info-panel]').should('not.contain', 'This is an old version');
445 cy.get('[data-cy=read-only-icon]').should('not.exist');
446 cy.get('[data-cy=collection-version-number]').should('contain', '1');
447 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
448 cy.get('[data-cy=collection-files-panel]').should('contain', 'foo').and('contain', 'bar');
450 // Modify collection, expect version number change
451 cy.get('[data-cy=collection-files-panel]').contains('foo').rightclick();
452 cy.get('[data-cy=context-menu]').contains('Remove').click();
453 cy.get('[data-cy=confirmation-dialog]').should('contain', 'Removing file');
454 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
455 cy.get('[data-cy=collection-version-number]').should('contain', '2');
456 cy.get('[data-cy=collection-files-panel]').should('not.contain', 'foo').and('contain', 'bar');
458 // Click on version number, check version browser. Click on past version.
459 cy.get('[data-cy=collection-version-browser]').should('not.exist');
460 cy.get('[data-cy=collection-version-number]').contains('2').click();
461 cy.get('[data-cy=collection-version-browser]')
462 .should('contain', 'Nr').and('contain', 'Size').and('contain', 'Date')
464 // Version 1: 6 bytes in size
465 cy.get('[data-cy=collection-version-browser-select-1]')
466 .should('contain', '1').and('contain', '6 B');
467 // Version 2: 3 bytes in size (one file removed)
468 cy.get('[data-cy=collection-version-browser-select-2]')
469 .should('contain', '2').and('contain', '3 B');
470 cy.get('[data-cy=collection-version-browser-select-3]')
471 .should('not.exist');
472 cy.get('[data-cy=collection-version-browser-select-1]')
475 cy.get('[data-cy=collection-info-panel]').should('contain', 'This is an old version');
476 cy.get('[data-cy=read-only-icon]').should('exist');
477 cy.get('[data-cy=collection-version-number]').should('contain', '1');
478 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
479 cy.get('[data-cy=collection-files-panel]')
480 .should('contain', 'foo').and('contain', 'bar');
482 // Check that only old collection action are available on context menu
483 cy.get('[data-cy=collection-panel-options-btn]').click();
484 cy.get('[data-cy=context-menu]')
485 .should('contain', 'Restore version')
486 .and('not.contain', 'Add to favorites');
487 cy.get('body').click(); // Collapse the menu avoiding details panel expansion
489 // Click on "head version" link, confirm that it's the latest version.
490 cy.get('[data-cy=collection-info-panel]').contains('head version').click();
491 cy.get('[data-cy=collection-info-panel]')
492 .should('not.contain', 'This is an old version');
493 cy.get('[data-cy=read-only-icon]').should('not.exist');
494 cy.get('[data-cy=collection-version-number]').should('contain', '2');
495 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
496 cy.get('[data-cy=collection-files-panel]').
497 should('not.contain', 'foo').and('contain', 'bar');
499 // Check that old collection action isn't available on context menu
500 cy.get('[data-cy=collection-panel-options-btn]').click()
501 cy.get('[data-cy=context-menu]').should('not.contain', 'Restore version')
502 cy.get('body').click(); // Collapse the menu avoiding details panel expansion
504 // Make another change, confirm new version.
505 cy.get('[data-cy=collection-panel-options-btn]').click();
506 cy.get('[data-cy=context-menu]').contains('Edit collection').click();
507 cy.get('[data-cy=form-dialog]')
508 .should('contain', 'Edit Collection')
511 cy.get('input').first().type(' renamed');
513 cy.get('[data-cy=form-submit-btn]').click();
514 cy.get('[data-cy=collection-info-panel]')
515 .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', '3');
518 cy.get('[data-cy=collection-info-panel]').should('contain', colName + ' renamed');
519 cy.get('[data-cy=collection-files-panel]')
520 .should('not.contain', 'foo').and('contain', 'bar');
521 cy.get('[data-cy=collection-version-browser-select-3]')
522 .should('contain', '3').and('contain', '3 B');
524 // Check context menus on version browser
525 cy.get('[data-cy=collection-version-browser-select-3]').rightclick()
526 cy.get('[data-cy=context-menu]')
527 .should('contain', 'Add to favorites')
528 .and('contain', 'Make a copy')
529 .and('contain', 'Edit collection');
530 cy.get('body').click();
531 // (and now an old version...)
532 cy.get('[data-cy=collection-version-browser-select-1]').rightclick()
533 cy.get('[data-cy=context-menu]')
534 .should('not.contain', 'Add to favorites')
535 .and('contain', 'Make a copy')
536 .and('not.contain', 'Edit collection');
537 cy.get('body').click();
539 // Restore first version
540 cy.get('[data-cy=collection-version-browser]').within(() => {
541 cy.get('[data-cy=collection-version-browser-select-1]').click();
543 cy.get('[data-cy=collection-panel-options-btn]').click()
544 cy.get('[data-cy=context-menu]').contains('Restore version').click();
545 cy.get('[data-cy=confirmation-dialog]').should('contain', 'Restore version');
546 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
547 cy.get('[data-cy=collection-info-panel]')
548 .should('not.contain', 'This is an old version');
549 cy.get('[data-cy=collection-version-number]').should('contain', '4');
550 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
551 cy.get('[data-cy=collection-files-panel]')
552 .should('contain', 'foo').and('contain', 'bar');
556 it('creates new collection on home project', function () {
557 cy.loginAs(activeUser);
558 cy.goToPath(`/projects/${activeUser.user.uuid}`);
559 cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
560 cy.get('[data-cy=breadcrumb-last]').should('not.exist');
561 // Create new collection
562 cy.get('[data-cy=side-panel-button]').click();
563 cy.get('[data-cy=side-panel-new-collection]').click();
564 const collName = `Test collection (${Math.floor(999999 * Math.random())})`;
565 cy.get('[data-cy=form-dialog]')
566 .should('contain', 'New collection')
568 cy.get('[data-cy=parent-field]').within(() => {
569 cy.get('input').should('have.value', 'Home project');
571 cy.get('[data-cy=name-field]').within(() => {
572 cy.get('input').type(collName);
575 cy.get('[data-cy=form-submit-btn]').click();
576 // Confirm that the user was taken to the newly created thing
577 cy.get('[data-cy=form-dialog]').should('not.exist');
578 cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
579 cy.get('[data-cy=breadcrumb-last]').should('contain', collName);