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.goToPath(`/collections/${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);
70 expect(map['Path']).to.equal(`/c=${testCollection.uuid}`);
74 .then(() => cy.task('clearDownload', { filename }));
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"
84 .as('testCollection').then(function () {
85 cy.loginAs(activeUser);
86 cy.goToPath(`/collections/${this.testCollection.uuid}`);
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');
93 cy.get('[data-cy=property-field-value]').within(() => {
94 cy.get('input').type('Magenta');
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')
106 expect(this.collection.properties).to.deep.equal(
107 { IDTAGCOLORS: 'IDVALCOLORS3' });
112 it('shows collection by URL', function () {
113 cy.loginAs(activeUser);
114 [true, false].map(function (isWritable) {
115 // Using different file names to avoid test flakyness: the second iteration
116 // on this loop may pass an assertion from the first iteration by looking
117 // for the same file name.
118 const fileName = isWritable ? 'bar' : 'foo';
119 const subDirName = 'subdir';
120 cy.createGroup(adminUser.token, {
121 name: 'Shared project',
122 group_class: 'project',
123 }).as('sharedGroup').then(function () {
124 // Creates the collection using the admin token so we can set up
125 // a bogus manifest text without block signatures.
126 cy.createCollection(adminUser.token, {
127 name: 'Test collection',
128 owner_uuid: this.sharedGroup.uuid,
129 properties: { someKey: 'someValue' },
130 manifest_text: `. 37b51d194a7513e45b56f6524f2d51f2+3 0:3:${fileName}\n./${subDirName} 37b51d194a7513e45b56f6524f2d51f2+3 0:3:${fileName}\n`
132 .as('testCollection').then(function () {
133 // Share the group with active user.
134 cy.createLink(adminUser.token, {
135 name: isWritable ? 'can_write' : 'can_read',
136 link_class: 'permission',
137 head_uuid: this.sharedGroup.uuid,
138 tail_uuid: activeUser.user.uuid
140 cy.goToPath(`/collections/${this.testCollection.uuid}`);
142 // Check that name & uuid are correct.
143 cy.get('[data-cy=collection-info-panel]')
144 .should('contain', this.testCollection.name)
145 .and('contain', this.testCollection.uuid)
146 .and('not.contain', 'This is an old version');
147 // Check for the read-only icon
148 cy.get('[data-cy=read-only-icon]').should(`${isWritable ? 'not.' : ''}exist`);
149 // Check that both read and write operations are available on
150 // the 'More options' menu.
151 cy.get('[data-cy=collection-panel-options-btn]')
153 cy.get('[data-cy=context-menu]')
154 .should('contain', 'Add to favorites')
155 .and(`${isWritable ? '' : 'not.'}contain`, 'Edit collection');
156 cy.get('body').click(); // Collapse the menu avoiding details panel expansion
157 cy.get('[data-cy=collection-properties-panel]')
158 .should('contain', 'someKey')
159 .and('contain', 'someValue')
160 .and('not.contain', 'anotherKey')
161 .and('not.contain', 'anotherValue')
162 if (isWritable === true) {
163 // Check that properties can be added.
164 cy.get('[data-cy=resource-properties-form]').within(() => {
165 cy.get('[data-cy=property-field-key]').within(() => {
166 cy.get('input').type('anotherKey');
168 cy.get('[data-cy=property-field-value]').within(() => {
169 cy.get('input').type('anotherValue');
173 cy.get('[data-cy=collection-properties-panel]')
174 .should('contain', 'anotherKey')
175 .and('contain', 'anotherValue')
177 // Properties form shouldn't be displayed.
178 cy.get('[data-cy=resource-properties-form]').should('not.exist');
180 // Check that the file listing show both read & write operations
181 cy.get('[data-cy=collection-files-panel]').within(() => {
182 cy.root().should('contain', fileName);
184 cy.get('[data-cy=upload-button]')
185 .should(`${isWritable ? '' : 'not.'}contain`, 'Upload data');
188 // Test context menus
189 cy.get('[data-cy=collection-files-panel]')
190 .contains(fileName).rightclick({ force: true });
191 cy.get('[data-cy=context-menu]')
192 .should('contain', 'Download')
193 .and('contain', 'Open in new tab')
194 .and('contain', 'Copy to clipboard')
195 .and(`${isWritable ? '' : 'not.'}contain`, 'Rename')
196 .and(`${isWritable ? '' : 'not.'}contain`, 'Remove');
197 cy.get('body').click(); // Collapse the menu
198 cy.get('[data-cy=collection-files-panel]')
199 .contains(subDirName).rightclick({ force: true });
200 cy.get('[data-cy=context-menu]')
201 .should('not.contain', 'Download')
202 .and('contain', 'Open in new tab')
203 .and('contain', 'Copy to clipboard')
204 .and(`${isWritable ? '' : 'not.'}contain`, 'Rename')
205 .and(`${isWritable ? '' : 'not.'}contain`, 'Remove');
206 cy.get('body').click(); // Collapse the menu
207 // Hamburger 'more options' menu button
208 cy.get('[data-cy=collection-files-panel-options-btn]')
210 cy.get('[data-cy=context-menu]')
211 .should('contain', 'Select all')
213 cy.get('[data-cy=collection-files-panel-options-btn]')
215 cy.get('[data-cy=context-menu]')
216 .should(`${isWritable ? '' : 'not.'}contain`, 'Remove selected')
217 cy.get('body').click(); // Collapse the menu
223 it('renames a file using valid names', function () {
224 function eachPair(lst, func){
225 for(var i=0; i < lst.length - 1; i++){
226 func(lst[i], lst[i + 1])
229 // Creates the collection using the admin token so we can set up
230 // a bogus manifest text without block signatures.
231 cy.createCollection(adminUser.token, {
232 name: `Test collection ${Math.floor(Math.random() * 999999)}`,
233 owner_uuid: activeUser.user.uuid,
234 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
236 .as('testCollection').then(function () {
237 cy.loginAs(activeUser);
238 cy.goToPath(`/collections/${this.testCollection.uuid}`);
241 'bar', // initial name already set
242 '[between brackets]', // JSON-like strings (#17582)
243 '{between braces}', // JSON-like strings (#17582)
250 'some name with whitespaces',
252 'is this name legal? I hope it is',
260 "G%C3%BCnter's%20file.pdf",
262 'bar' // make sure we can go back to the original name as a last step
264 eachPair(names, (from, to) => {
265 cy.get('[data-cy=collection-files-panel]')
266 .contains(`${from}`).rightclick();
267 cy.get('[data-cy=context-menu]')
270 cy.get('[data-cy=form-dialog]')
271 .should('contain', 'Rename')
274 .type('{selectall}{backspace}')
275 .type(to, { parseSpecialCharSequences: false });
277 cy.get('[data-cy=form-submit-btn]').click();
278 cy.get('[data-cy=collection-files-panel]')
279 .should('not.contain', `${from}`)
280 .and('contain', `${to}`);
285 it('renames a file to a different directory', function () {
286 // Creates the collection using the admin token so we can set up
287 // a bogus manifest text without block signatures.
288 cy.createCollection(adminUser.token, {
289 name: `Test collection ${Math.floor(Math.random() * 999999)}`,
290 owner_uuid: activeUser.user.uuid,
291 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
293 .as('testCollection').then(function () {
294 cy.loginAs(activeUser);
295 cy.goToPath(`/collections/${this.testCollection.uuid}`);
297 ['subdir', 'G%C3%BCnter\'s%20file', 'table%&?*2'].forEach((subdir) => {
298 cy.get('[data-cy=collection-files-panel]')
299 .contains('bar').rightclick({force: true});
300 cy.get('[data-cy=context-menu]')
303 cy.get('[data-cy=form-dialog]')
304 .should('contain', 'Rename')
306 cy.get('input').type(`{selectall}{backspace}${subdir}/foo`);
308 cy.get('[data-cy=form-submit-btn]').click();
309 cy.get('[data-cy=collection-files-panel]')
310 .should('not.contain', 'bar')
311 .and('contain', subdir);
312 // Look for the "arrow icon" and expand the "subdir" directory.
313 cy.get('[data-cy=virtual-file-tree] > div > i').click();
314 // Rename 'subdir/foo' to 'foo'
315 cy.get('[data-cy=collection-files-panel]')
316 .contains('foo').rightclick();
317 cy.get('[data-cy=context-menu]')
320 cy.get('[data-cy=form-dialog]')
321 .should('contain', 'Rename')
324 .should('have.value', `${subdir}/foo`)
325 .type(`{selectall}{backspace}bar`);
327 cy.get('[data-cy=form-submit-btn]').click();
328 cy.get('[data-cy=collection-files-panel]')
329 .should('contain', subdir) // empty dir kept
330 .and('contain', 'bar');
332 cy.get('[data-cy=collection-files-panel]')
333 .contains(subdir).rightclick();
334 cy.get('[data-cy=context-menu]')
337 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
342 it('tries to rename a file with illegal names', function () {
343 // Creates the collection using the admin token so we can set up
344 // a bogus manifest text without block signatures.
345 cy.createCollection(adminUser.token, {
346 name: `Test collection ${Math.floor(Math.random() * 999999)}`,
347 owner_uuid: activeUser.user.uuid,
348 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
350 .as('testCollection').then(function () {
351 cy.loginAs(activeUser);
352 cy.goToPath(`/collections/${this.testCollection.uuid}`);
354 const illegalNamesFromUI = [
355 ['.', "Name cannot be '.' or '..'"],
356 ['..', "Name cannot be '.' or '..'"],
357 ['', 'This field is required'],
358 [' ', 'Leading/trailing whitespaces not allowed'],
359 [' foo', 'Leading/trailing whitespaces not allowed'],
360 ['foo ', 'Leading/trailing whitespaces not allowed'],
361 ['//foo', 'Empty dir name not allowed']
363 illegalNamesFromUI.forEach(([name, errMsg]) => {
364 cy.get('[data-cy=collection-files-panel]')
365 .contains('bar').rightclick();
366 cy.get('[data-cy=context-menu]')
369 cy.get('[data-cy=form-dialog]')
370 .should('contain', 'Rename')
372 cy.get('input').type(`{selectall}{backspace}${name}`);
374 cy.get('[data-cy=form-dialog]')
375 .should('contain', 'Rename')
377 cy.contains(`${errMsg}`);
379 cy.get('[data-cy=form-cancel-btn]').click();
384 it('can correctly display old versions', function () {
385 const colName = `Versioned Collection ${Math.floor(Math.random() * 999999)}`;
387 let oldVersionUuid = '';
388 // Make sure no other collections with this name exist
389 cy.doRequest('GET', '/arvados/v1/collections', null, {
390 filters: `[["name", "=", "${colName}"]]`,
391 include_old_versions: true
393 .its('body.items').as('collections')
395 expect(this.collections).to.be.empty;
397 // Creates the collection using the admin token so we can set up
398 // a bogus manifest text without block signatures.
399 cy.createCollection(adminUser.token, {
401 owner_uuid: activeUser.user.uuid,
402 preserve_version: true,
403 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
405 .as('originalVersion').then(function () {
406 // Change the file name to create a new version.
407 cy.updateCollection(adminUser.token, this.originalVersion.uuid, {
408 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo\n"
410 colUuid = this.originalVersion.uuid;
412 // Confirm that there are 2 versions of the collection
413 cy.doRequest('GET', '/arvados/v1/collections', null, {
414 filters: `[["name", "=", "${colName}"]]`,
415 include_old_versions: true
417 .its('body.items').as('collections')
419 expect(this.collections).to.have.lengthOf(2);
420 this.collections.map(function (aCollection) {
421 expect(aCollection.current_version_uuid).to.equal(colUuid);
422 if (aCollection.uuid !== aCollection.current_version_uuid) {
423 oldVersionUuid = aCollection.uuid;
426 // Check the old version displays as what it is.
427 cy.loginAs(activeUser)
428 cy.goToPath(`/collections/${oldVersionUuid}`);
430 cy.get('[data-cy=collection-info-panel]').should('contain', 'This is an old version');
431 cy.get('[data-cy=read-only-icon]').should('exist');
432 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
433 cy.get('[data-cy=collection-files-panel]').should('contain', 'bar');
437 it('uses the collection version browser to view a previous version', function () {
438 const colName = `Test Collection ${Math.floor(Math.random() * 999999)}`;
440 // Creates the collection using the admin token so we can set up
441 // a bogus manifest text without block signatures.
442 cy.createCollection(adminUser.token, {
444 owner_uuid: activeUser.user.uuid,
445 preserve_version: true,
446 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo 0:3:bar\n"
448 .as('collection').then(function () {
449 // Visit collection, check basic information
450 cy.loginAs(activeUser)
451 cy.goToPath(`/collections/${this.collection.uuid}`);
453 cy.get('[data-cy=collection-info-panel]').should('not.contain', 'This is an old version');
454 cy.get('[data-cy=read-only-icon]').should('not.exist');
455 cy.get('[data-cy=collection-version-number]').should('contain', '1');
456 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
457 cy.get('[data-cy=collection-files-panel]').should('contain', 'foo').and('contain', 'bar');
459 // Modify collection, expect version number change
460 cy.get('[data-cy=collection-files-panel]').contains('foo').rightclick();
461 cy.get('[data-cy=context-menu]').contains('Remove').click();
462 cy.get('[data-cy=confirmation-dialog]').should('contain', 'Removing file');
463 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
464 cy.get('[data-cy=collection-version-number]').should('contain', '2');
465 cy.get('[data-cy=collection-files-panel]').should('not.contain', 'foo').and('contain', 'bar');
467 // Click on version number, check version browser. Click on past version.
468 cy.get('[data-cy=collection-version-browser]').should('not.exist');
469 cy.get('[data-cy=collection-version-number]').contains('2').click();
470 cy.get('[data-cy=collection-version-browser]')
471 .should('contain', 'Nr').and('contain', 'Size').and('contain', 'Date')
473 // Version 1: 6 bytes in size
474 cy.get('[data-cy=collection-version-browser-select-1]')
475 .should('contain', '1').and('contain', '6 B');
476 // Version 2: 3 bytes in size (one file removed)
477 cy.get('[data-cy=collection-version-browser-select-2]')
478 .should('contain', '2').and('contain', '3 B');
479 cy.get('[data-cy=collection-version-browser-select-3]')
480 .should('not.exist');
481 cy.get('[data-cy=collection-version-browser-select-1]')
484 cy.get('[data-cy=collection-info-panel]').should('contain', 'This is an old version');
485 cy.get('[data-cy=read-only-icon]').should('exist');
486 cy.get('[data-cy=collection-version-number]').should('contain', '1');
487 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
488 cy.get('[data-cy=collection-files-panel]')
489 .should('contain', 'foo').and('contain', 'bar');
491 // Check that only old collection action are available on context menu
492 cy.get('[data-cy=collection-panel-options-btn]').click();
493 cy.get('[data-cy=context-menu]')
494 .should('contain', 'Restore version')
495 .and('not.contain', 'Add to favorites');
496 cy.get('body').click(); // Collapse the menu avoiding details panel expansion
498 // Click on "head version" link, confirm that it's the latest version.
499 cy.get('[data-cy=collection-info-panel]').contains('head version').click();
500 cy.get('[data-cy=collection-info-panel]')
501 .should('not.contain', 'This is an old version');
502 cy.get('[data-cy=read-only-icon]').should('not.exist');
503 cy.get('[data-cy=collection-version-number]').should('contain', '2');
504 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
505 cy.get('[data-cy=collection-files-panel]').
506 should('not.contain', 'foo').and('contain', 'bar');
508 // Check that old collection action isn't available on context menu
509 cy.get('[data-cy=collection-panel-options-btn]').click()
510 cy.get('[data-cy=context-menu]').should('not.contain', 'Restore version')
511 cy.get('body').click(); // Collapse the menu avoiding details panel expansion
513 // Make another change, confirm new version.
514 cy.get('[data-cy=collection-panel-options-btn]').click();
515 cy.get('[data-cy=context-menu]').contains('Edit collection').click();
516 cy.get('[data-cy=form-dialog]')
517 .should('contain', 'Edit Collection')
520 cy.get('input').first().type(' renamed');
522 cy.get('[data-cy=form-submit-btn]').click();
523 cy.get('[data-cy=collection-info-panel]')
524 .should('not.contain', 'This is an old version');
525 cy.get('[data-cy=read-only-icon]').should('not.exist');
526 cy.get('[data-cy=collection-version-number]').should('contain', '3');
527 cy.get('[data-cy=collection-info-panel]').should('contain', colName + ' renamed');
528 cy.get('[data-cy=collection-files-panel]')
529 .should('not.contain', 'foo').and('contain', 'bar');
530 cy.get('[data-cy=collection-version-browser-select-3]')
531 .should('contain', '3').and('contain', '3 B');
533 // Check context menus on version browser
534 cy.get('[data-cy=collection-version-browser-select-3]').rightclick()
535 cy.get('[data-cy=context-menu]')
536 .should('contain', 'Add to favorites')
537 .and('contain', 'Make a copy')
538 .and('contain', 'Edit collection');
539 cy.get('body').click();
540 // (and now an old version...)
541 cy.get('[data-cy=collection-version-browser-select-1]').rightclick()
542 cy.get('[data-cy=context-menu]')
543 .should('not.contain', 'Add to favorites')
544 .and('contain', 'Make a copy')
545 .and('not.contain', 'Edit collection');
546 cy.get('body').click();
548 // Restore first version
549 cy.get('[data-cy=collection-version-browser]').within(() => {
550 cy.get('[data-cy=collection-version-browser-select-1]').click();
552 cy.get('[data-cy=collection-panel-options-btn]').click()
553 cy.get('[data-cy=context-menu]').contains('Restore version').click();
554 cy.get('[data-cy=confirmation-dialog]').should('contain', 'Restore version');
555 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
556 cy.get('[data-cy=collection-info-panel]')
557 .should('not.contain', 'This is an old version');
558 cy.get('[data-cy=collection-version-number]').should('contain', '4');
559 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
560 cy.get('[data-cy=collection-files-panel]')
561 .should('contain', 'foo').and('contain', 'bar');
565 it('creates new collection on home project', function () {
566 cy.loginAs(activeUser);
567 cy.goToPath(`/projects/${activeUser.user.uuid}`);
568 cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
569 cy.get('[data-cy=breadcrumb-last]').should('not.exist');
570 // Create new collection
571 cy.get('[data-cy=side-panel-button]').click();
572 cy.get('[data-cy=side-panel-new-collection]').click();
573 const collName = `Test collection (${Math.floor(999999 * Math.random())})`;
574 cy.get('[data-cy=form-dialog]')
575 .should('contain', 'New collection')
577 cy.get('[data-cy=parent-field]').within(() => {
578 cy.get('input').should('have.value', 'Home project');
580 cy.get('[data-cy=name-field]').within(() => {
581 cy.get('input').type(collName);
584 cy.get('[data-cy=form-submit-btn]').click();
585 // Confirm that the user was taken to the newly created thing
586 cy.get('[data-cy=form-dialog]').should('not.exist');
587 cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
588 cy.get('[data-cy=breadcrumb-last]').should('contain', collName);