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);
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 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`
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
139 cy.goToPath(`/collections/${this.testCollection.uuid}`);
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]')
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');
167 cy.get('[data-cy=property-field-value]').within(() => {
168 cy.get('input').type('anotherValue');
172 cy.get('[data-cy=collection-properties-panel]')
173 .should('contain', 'anotherKey')
174 .and('contain', 'anotherValue')
176 // Properties form shouldn't be displayed.
177 cy.get('[data-cy=resource-properties-form]').should('not.exist');
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);
183 cy.get('[data-cy=upload-button]')
184 .should(`${isWritable ? '' : 'not.'}contain`, 'Upload data');
187 cy.get('[data-cy=collection-files-panel]')
188 .contains(fileName).rightclick({ force: true });
189 cy.get('[data-cy=context-menu]')
190 .should('contain', 'Download')
191 .and('contain', 'Open in new tab')
192 .and('contain', 'Copy to clipboard')
193 .and(`${isWritable ? '' : 'not.'}contain`, 'Rename')
194 .and(`${isWritable ? '' : 'not.'}contain`, 'Remove');
195 cy.get('body').click(); // Collapse the menu
196 // Hamburger 'more options' menu button
197 cy.get('[data-cy=collection-files-panel-options-btn]')
199 cy.get('[data-cy=context-menu]')
200 .should('contain', 'Select all')
202 cy.get('[data-cy=collection-files-panel-options-btn]')
204 cy.get('[data-cy=context-menu]')
205 // .should('contain', 'Download selected')
206 .should(`${isWritable ? '' : 'not.'}contain`, 'Remove selected')
207 cy.get('body').click(); // Collapse the menu
208 // File item 'more options' button
209 cy.get('[data-cy=file-item-options-btn')
211 cy.get('[data-cy=context-menu]')
212 .should('contain', 'Download')
213 .and(`${isWritable ? '' : 'not.'}contain`, 'Remove');
214 cy.get('body').click(); // Collapse the menu
220 it('renames a file using valid names', function () {
221 function eachPair(lst, func){
222 for(var i=0; i < lst.length - 1; i++){
223 func(lst[i], lst[i + 1])
226 // Creates the collection using the admin token so we can set up
227 // a bogus manifest text without block signatures.
228 cy.createCollection(adminUser.token, {
229 name: `Test collection ${Math.floor(Math.random() * 999999)}`,
230 owner_uuid: activeUser.user.uuid,
231 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
233 .as('testCollection').then(function () {
234 cy.loginAs(activeUser);
235 cy.goToPath(`/collections/${this.testCollection.uuid}`);
238 'bar', // initial name already set
245 'some name with whitespaces',
247 'is this name legal? I hope it is',
255 "G%C3%BCnter's%20file.pdf",
257 'bar' // make sure we can go back to the original name as a last step
259 eachPair(names, (from, to) => {
260 cy.get('[data-cy=collection-files-panel]')
261 .contains(`${from}`).rightclick();
262 cy.get('[data-cy=context-menu]')
265 cy.get('[data-cy=form-dialog]')
266 .should('contain', 'Rename')
268 cy.get('input').type(`{selectall}{backspace}${to}`);
270 cy.get('[data-cy=form-submit-btn]').click();
271 cy.get('[data-cy=collection-files-panel]')
272 .should('not.contain', `${from}`)
273 .and('contain', `${to}`);
278 it('renames a file to a different directory', function () {
279 // Creates the collection using the admin token so we can set up
280 // a bogus manifest text without block signatures.
281 cy.createCollection(adminUser.token, {
282 name: `Test collection ${Math.floor(Math.random() * 999999)}`,
283 owner_uuid: activeUser.user.uuid,
284 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
286 .as('testCollection').then(function () {
287 cy.loginAs(activeUser);
288 cy.goToPath(`/collections/${this.testCollection.uuid}`);
290 ['subdir', 'G%C3%BCnter\'s%20file', 'table%&?*2'].forEach((subdir) => {
291 cy.get('[data-cy=collection-files-panel]')
292 .contains('bar').rightclick({force: true});
293 cy.get('[data-cy=context-menu]')
296 cy.get('[data-cy=form-dialog]')
297 .should('contain', 'Rename')
299 cy.get('input').type(`{selectall}{backspace}${subdir}/foo`);
301 cy.get('[data-cy=form-submit-btn]').click();
302 cy.get('[data-cy=collection-files-panel]')
303 .should('not.contain', 'bar')
304 .and('contain', subdir);
305 // Look for the "arrow icon" and expand the "subdir" directory.
306 cy.get('[data-cy=virtual-file-tree] > div > i').click();
307 // Rename 'subdir/foo' to 'foo'
308 cy.get('[data-cy=collection-files-panel]')
309 .contains('foo').rightclick();
310 cy.get('[data-cy=context-menu]')
313 cy.get('[data-cy=form-dialog]')
314 .should('contain', 'Rename')
317 .should('have.value', `${subdir}/foo`)
318 .type(`{selectall}{backspace}bar`);
320 cy.get('[data-cy=form-submit-btn]').click();
321 cy.get('[data-cy=collection-files-panel]')
322 .should('contain', subdir) // empty dir kept
323 .and('contain', 'bar');
325 cy.get('[data-cy=collection-files-panel]')
326 .contains(subdir).rightclick();
327 cy.get('[data-cy=context-menu]')
330 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
335 it('tries to rename a file with illegal names', function () {
336 // Creates the collection using the admin token so we can set up
337 // a bogus manifest text without block signatures.
338 cy.createCollection(adminUser.token, {
339 name: `Test collection ${Math.floor(Math.random() * 999999)}`,
340 owner_uuid: activeUser.user.uuid,
341 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
343 .as('testCollection').then(function () {
344 cy.loginAs(activeUser);
345 cy.goToPath(`/collections/${this.testCollection.uuid}`);
347 const illegalNamesFromUI = [
348 ['.', "Name cannot be '.' or '..'"],
349 ['..', "Name cannot be '.' or '..'"],
350 ['', 'This field is required'],
351 [' ', 'Leading/trailing whitespaces not allowed'],
352 [' foo', 'Leading/trailing whitespaces not allowed'],
353 ['foo ', 'Leading/trailing whitespaces not allowed'],
354 ['//foo', 'Empty dir name not allowed']
356 illegalNamesFromUI.forEach(([name, errMsg]) => {
357 cy.get('[data-cy=collection-files-panel]')
358 .contains('bar').rightclick();
359 cy.get('[data-cy=context-menu]')
362 cy.get('[data-cy=form-dialog]')
363 .should('contain', 'Rename')
365 cy.get('input').type(`{selectall}{backspace}${name}`);
367 cy.get('[data-cy=form-dialog]')
368 .should('contain', 'Rename')
370 cy.contains(`${errMsg}`);
372 cy.get('[data-cy=form-cancel-btn]').click();
377 it('can correctly display old versions', function () {
378 const colName = `Versioned Collection ${Math.floor(Math.random() * 999999)}`;
380 let oldVersionUuid = '';
381 // Make sure no other collections with this name exist
382 cy.doRequest('GET', '/arvados/v1/collections', null, {
383 filters: `[["name", "=", "${colName}"]]`,
384 include_old_versions: true
386 .its('body.items').as('collections')
388 expect(this.collections).to.be.empty;
390 // Creates the collection using the admin token so we can set up
391 // a bogus manifest text without block signatures.
392 cy.createCollection(adminUser.token, {
394 owner_uuid: activeUser.user.uuid,
395 preserve_version: true,
396 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
398 .as('originalVersion').then(function () {
399 // Change the file name to create a new version.
400 cy.updateCollection(adminUser.token, this.originalVersion.uuid, {
401 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo\n"
403 colUuid = this.originalVersion.uuid;
405 // Confirm that there are 2 versions of the collection
406 cy.doRequest('GET', '/arvados/v1/collections', null, {
407 filters: `[["name", "=", "${colName}"]]`,
408 include_old_versions: true
410 .its('body.items').as('collections')
412 expect(this.collections).to.have.lengthOf(2);
413 this.collections.map(function (aCollection) {
414 expect(aCollection.current_version_uuid).to.equal(colUuid);
415 if (aCollection.uuid !== aCollection.current_version_uuid) {
416 oldVersionUuid = aCollection.uuid;
419 // Check the old version displays as what it is.
420 cy.loginAs(activeUser)
421 cy.goToPath(`/collections/${oldVersionUuid}`);
423 cy.get('[data-cy=collection-info-panel]').should('contain', 'This is an old version');
424 cy.get('[data-cy=read-only-icon]').should('exist');
425 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
426 cy.get('[data-cy=collection-files-panel]').should('contain', 'bar');
430 it('uses the collection version browser to view a previous version', function () {
431 const colName = `Test Collection ${Math.floor(Math.random() * 999999)}`;
433 // Creates the collection using the admin token so we can set up
434 // a bogus manifest text without block signatures.
435 cy.createCollection(adminUser.token, {
437 owner_uuid: activeUser.user.uuid,
438 preserve_version: true,
439 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo 0:3:bar\n"
441 .as('collection').then(function () {
442 // Visit collection, check basic information
443 cy.loginAs(activeUser)
444 cy.goToPath(`/collections/${this.collection.uuid}`);
446 cy.get('[data-cy=collection-info-panel]').should('not.contain', 'This is an old version');
447 cy.get('[data-cy=read-only-icon]').should('not.exist');
448 cy.get('[data-cy=collection-version-number]').should('contain', '1');
449 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
450 cy.get('[data-cy=collection-files-panel]').should('contain', 'foo').and('contain', 'bar');
452 // Modify collection, expect version number change
453 cy.get('[data-cy=collection-files-panel]').contains('foo').rightclick();
454 cy.get('[data-cy=context-menu]').contains('Remove').click();
455 cy.get('[data-cy=confirmation-dialog]').should('contain', 'Removing file');
456 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
457 cy.get('[data-cy=collection-version-number]').should('contain', '2');
458 cy.get('[data-cy=collection-files-panel]').should('not.contain', 'foo').and('contain', 'bar');
460 // Click on version number, check version browser. Click on past version.
461 cy.get('[data-cy=collection-version-browser]').should('not.exist');
462 cy.get('[data-cy=collection-version-number]').contains('2').click();
463 cy.get('[data-cy=collection-version-browser]')
464 .should('contain', 'Nr').and('contain', 'Size').and('contain', 'Date')
466 // Version 1: 6 bytes in size
467 cy.get('[data-cy=collection-version-browser-select-1]')
468 .should('contain', '1').and('contain', '6 B');
469 // Version 2: 3 bytes in size (one file removed)
470 cy.get('[data-cy=collection-version-browser-select-2]')
471 .should('contain', '2').and('contain', '3 B');
472 cy.get('[data-cy=collection-version-browser-select-3]')
473 .should('not.exist');
474 cy.get('[data-cy=collection-version-browser-select-1]')
477 cy.get('[data-cy=collection-info-panel]').should('contain', 'This is an old version');
478 cy.get('[data-cy=read-only-icon]').should('exist');
479 cy.get('[data-cy=collection-version-number]').should('contain', '1');
480 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
481 cy.get('[data-cy=collection-files-panel]')
482 .should('contain', 'foo').and('contain', 'bar');
484 // Check that only old collection action are available on context menu
485 cy.get('[data-cy=collection-panel-options-btn]').click();
486 cy.get('[data-cy=context-menu]')
487 .should('contain', 'Restore version')
488 .and('not.contain', 'Add to favorites');
489 cy.get('body').click(); // Collapse the menu avoiding details panel expansion
491 // Click on "head version" link, confirm that it's the latest version.
492 cy.get('[data-cy=collection-info-panel]').contains('head version').click();
493 cy.get('[data-cy=collection-info-panel]')
494 .should('not.contain', 'This is an old version');
495 cy.get('[data-cy=read-only-icon]').should('not.exist');
496 cy.get('[data-cy=collection-version-number]').should('contain', '2');
497 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
498 cy.get('[data-cy=collection-files-panel]').
499 should('not.contain', 'foo').and('contain', 'bar');
501 // Check that old collection action isn't available on context menu
502 cy.get('[data-cy=collection-panel-options-btn]').click()
503 cy.get('[data-cy=context-menu]').should('not.contain', 'Restore version')
504 cy.get('body').click(); // Collapse the menu avoiding details panel expansion
506 // Make another change, confirm new version.
507 cy.get('[data-cy=collection-panel-options-btn]').click();
508 cy.get('[data-cy=context-menu]').contains('Edit collection').click();
509 cy.get('[data-cy=form-dialog]')
510 .should('contain', 'Edit Collection')
513 cy.get('input').first().type(' renamed');
515 cy.get('[data-cy=form-submit-btn]').click();
516 cy.get('[data-cy=collection-info-panel]')
517 .should('not.contain', 'This is an old version');
518 cy.get('[data-cy=read-only-icon]').should('not.exist');
519 cy.get('[data-cy=collection-version-number]').should('contain', '3');
520 cy.get('[data-cy=collection-info-panel]').should('contain', colName + ' renamed');
521 cy.get('[data-cy=collection-files-panel]')
522 .should('not.contain', 'foo').and('contain', 'bar');
523 cy.get('[data-cy=collection-version-browser-select-3]')
524 .should('contain', '3').and('contain', '3 B');
526 // Check context menus on version browser
527 cy.get('[data-cy=collection-version-browser-select-3]').rightclick()
528 cy.get('[data-cy=context-menu]')
529 .should('contain', 'Add to favorites')
530 .and('contain', 'Make a copy')
531 .and('contain', 'Edit collection');
532 cy.get('body').click();
533 // (and now an old version...)
534 cy.get('[data-cy=collection-version-browser-select-1]').rightclick()
535 cy.get('[data-cy=context-menu]')
536 .should('not.contain', 'Add to favorites')
537 .and('contain', 'Make a copy')
538 .and('not.contain', 'Edit collection');
539 cy.get('body').click();
541 // Restore first version
542 cy.get('[data-cy=collection-version-browser]').within(() => {
543 cy.get('[data-cy=collection-version-browser-select-1]').click();
545 cy.get('[data-cy=collection-panel-options-btn]').click()
546 cy.get('[data-cy=context-menu]').contains('Restore version').click();
547 cy.get('[data-cy=confirmation-dialog]').should('contain', 'Restore version');
548 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
549 cy.get('[data-cy=collection-info-panel]')
550 .should('not.contain', 'This is an old version');
551 cy.get('[data-cy=collection-version-number]').should('contain', '4');
552 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
553 cy.get('[data-cy=collection-files-panel]')
554 .should('contain', 'foo').and('contain', 'bar');
558 it('creates new collection on home project', function () {
559 cy.loginAs(activeUser);
560 cy.goToPath(`/projects/${activeUser.user.uuid}`);
561 cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
562 cy.get('[data-cy=breadcrumb-last]').should('not.exist');
563 // Create new collection
564 cy.get('[data-cy=side-panel-button]').click();
565 cy.get('[data-cy=side-panel-new-collection]').click();
566 const collName = `Test collection (${Math.floor(999999 * Math.random())})`;
567 cy.get('[data-cy=form-dialog]')
568 .should('contain', 'New collection')
570 cy.get('[data-cy=parent-field]').within(() => {
571 cy.get('input').should('have.value', 'Home project');
573 cy.get('[data-cy=name-field]').within(() => {
574 cy.get('input').type(collName);
577 cy.get('[data-cy=form-submit-btn]').click();
578 // Confirm that the user was taken to the newly created thing
579 cy.get('[data-cy=form-dialog]').should('not.exist');
580 cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
581 cy.get('[data-cy=breadcrumb-last]').should('contain', collName);