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
248 'some name with whitespaces',
250 'is this name legal? I hope it is',
258 "G%C3%BCnter's%20file.pdf",
260 'bar' // make sure we can go back to the original name as a last step
262 eachPair(names, (from, to) => {
263 cy.get('[data-cy=collection-files-panel]')
264 .contains(`${from}`).rightclick();
265 cy.get('[data-cy=context-menu]')
268 cy.get('[data-cy=form-dialog]')
269 .should('contain', 'Rename')
272 .type('{selectall}{backspace}')
273 .type(to, { parseSpecialCharSequences: false });
275 cy.get('[data-cy=form-submit-btn]').click();
276 cy.get('[data-cy=collection-files-panel]')
277 .should('not.contain', `${from}`)
278 .and('contain', `${to}`);
283 it('renames a file to a different directory', function () {
284 // Creates the collection using the admin token so we can set up
285 // a bogus manifest text without block signatures.
286 cy.createCollection(adminUser.token, {
287 name: `Test collection ${Math.floor(Math.random() * 999999)}`,
288 owner_uuid: activeUser.user.uuid,
289 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
291 .as('testCollection').then(function () {
292 cy.loginAs(activeUser);
293 cy.goToPath(`/collections/${this.testCollection.uuid}`);
295 ['subdir', 'G%C3%BCnter\'s%20file', 'table%&?*2'].forEach((subdir) => {
296 cy.get('[data-cy=collection-files-panel]')
297 .contains('bar').rightclick({force: true});
298 cy.get('[data-cy=context-menu]')
301 cy.get('[data-cy=form-dialog]')
302 .should('contain', 'Rename')
304 cy.get('input').type(`{selectall}{backspace}${subdir}/foo`);
306 cy.get('[data-cy=form-submit-btn]').click();
307 cy.get('[data-cy=collection-files-panel]')
308 .should('not.contain', 'bar')
309 .and('contain', subdir);
310 // Look for the "arrow icon" and expand the "subdir" directory.
311 cy.get('[data-cy=virtual-file-tree] > div > i').click();
312 // Rename 'subdir/foo' to 'foo'
313 cy.get('[data-cy=collection-files-panel]')
314 .contains('foo').rightclick();
315 cy.get('[data-cy=context-menu]')
318 cy.get('[data-cy=form-dialog]')
319 .should('contain', 'Rename')
322 .should('have.value', `${subdir}/foo`)
323 .type(`{selectall}{backspace}bar`);
325 cy.get('[data-cy=form-submit-btn]').click();
326 cy.get('[data-cy=collection-files-panel]')
327 .should('contain', subdir) // empty dir kept
328 .and('contain', 'bar');
330 cy.get('[data-cy=collection-files-panel]')
331 .contains(subdir).rightclick();
332 cy.get('[data-cy=context-menu]')
335 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
340 it('tries to rename a file with illegal names', function () {
341 // Creates the collection using the admin token so we can set up
342 // a bogus manifest text without block signatures.
343 cy.createCollection(adminUser.token, {
344 name: `Test collection ${Math.floor(Math.random() * 999999)}`,
345 owner_uuid: activeUser.user.uuid,
346 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
348 .as('testCollection').then(function () {
349 cy.loginAs(activeUser);
350 cy.goToPath(`/collections/${this.testCollection.uuid}`);
352 const illegalNamesFromUI = [
353 ['.', "Name cannot be '.' or '..'"],
354 ['..', "Name cannot be '.' or '..'"],
355 ['', 'This field is required'],
356 [' ', 'Leading/trailing whitespaces not allowed'],
357 [' foo', 'Leading/trailing whitespaces not allowed'],
358 ['foo ', 'Leading/trailing whitespaces not allowed'],
359 ['//foo', 'Empty dir name not allowed']
361 illegalNamesFromUI.forEach(([name, errMsg]) => {
362 cy.get('[data-cy=collection-files-panel]')
363 .contains('bar').rightclick();
364 cy.get('[data-cy=context-menu]')
367 cy.get('[data-cy=form-dialog]')
368 .should('contain', 'Rename')
370 cy.get('input').type(`{selectall}{backspace}${name}`);
372 cy.get('[data-cy=form-dialog]')
373 .should('contain', 'Rename')
375 cy.contains(`${errMsg}`);
377 cy.get('[data-cy=form-cancel-btn]').click();
382 it('can correctly display old versions', function () {
383 const colName = `Versioned Collection ${Math.floor(Math.random() * 999999)}`;
385 let oldVersionUuid = '';
386 // Make sure no other collections with this name exist
387 cy.doRequest('GET', '/arvados/v1/collections', null, {
388 filters: `[["name", "=", "${colName}"]]`,
389 include_old_versions: true
391 .its('body.items').as('collections')
393 expect(this.collections).to.be.empty;
395 // Creates the collection using the admin token so we can set up
396 // a bogus manifest text without block signatures.
397 cy.createCollection(adminUser.token, {
399 owner_uuid: activeUser.user.uuid,
400 preserve_version: true,
401 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
403 .as('originalVersion').then(function () {
404 // Change the file name to create a new version.
405 cy.updateCollection(adminUser.token, this.originalVersion.uuid, {
406 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo\n"
408 colUuid = this.originalVersion.uuid;
410 // Confirm that there are 2 versions of the collection
411 cy.doRequest('GET', '/arvados/v1/collections', null, {
412 filters: `[["name", "=", "${colName}"]]`,
413 include_old_versions: true
415 .its('body.items').as('collections')
417 expect(this.collections).to.have.lengthOf(2);
418 this.collections.map(function (aCollection) {
419 expect(aCollection.current_version_uuid).to.equal(colUuid);
420 if (aCollection.uuid !== aCollection.current_version_uuid) {
421 oldVersionUuid = aCollection.uuid;
424 // Check the old version displays as what it is.
425 cy.loginAs(activeUser)
426 cy.goToPath(`/collections/${oldVersionUuid}`);
428 cy.get('[data-cy=collection-info-panel]').should('contain', 'This is an old version');
429 cy.get('[data-cy=read-only-icon]').should('exist');
430 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
431 cy.get('[data-cy=collection-files-panel]').should('contain', 'bar');
435 it('uses the collection version browser to view a previous version', function () {
436 const colName = `Test Collection ${Math.floor(Math.random() * 999999)}`;
438 // Creates the collection using the admin token so we can set up
439 // a bogus manifest text without block signatures.
440 cy.createCollection(adminUser.token, {
442 owner_uuid: activeUser.user.uuid,
443 preserve_version: true,
444 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo 0:3:bar\n"
446 .as('collection').then(function () {
447 // Visit collection, check basic information
448 cy.loginAs(activeUser)
449 cy.goToPath(`/collections/${this.collection.uuid}`);
451 cy.get('[data-cy=collection-info-panel]').should('not.contain', 'This is an old version');
452 cy.get('[data-cy=read-only-icon]').should('not.exist');
453 cy.get('[data-cy=collection-version-number]').should('contain', '1');
454 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
455 cy.get('[data-cy=collection-files-panel]').should('contain', 'foo').and('contain', 'bar');
457 // Modify collection, expect version number change
458 cy.get('[data-cy=collection-files-panel]').contains('foo').rightclick();
459 cy.get('[data-cy=context-menu]').contains('Remove').click();
460 cy.get('[data-cy=confirmation-dialog]').should('contain', 'Removing file');
461 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
462 cy.get('[data-cy=collection-version-number]').should('contain', '2');
463 cy.get('[data-cy=collection-files-panel]').should('not.contain', 'foo').and('contain', 'bar');
465 // Click on version number, check version browser. Click on past version.
466 cy.get('[data-cy=collection-version-browser]').should('not.exist');
467 cy.get('[data-cy=collection-version-number]').contains('2').click();
468 cy.get('[data-cy=collection-version-browser]')
469 .should('contain', 'Nr').and('contain', 'Size').and('contain', 'Date')
471 // Version 1: 6 bytes in size
472 cy.get('[data-cy=collection-version-browser-select-1]')
473 .should('contain', '1').and('contain', '6 B');
474 // Version 2: 3 bytes in size (one file removed)
475 cy.get('[data-cy=collection-version-browser-select-2]')
476 .should('contain', '2').and('contain', '3 B');
477 cy.get('[data-cy=collection-version-browser-select-3]')
478 .should('not.exist');
479 cy.get('[data-cy=collection-version-browser-select-1]')
482 cy.get('[data-cy=collection-info-panel]').should('contain', 'This is an old version');
483 cy.get('[data-cy=read-only-icon]').should('exist');
484 cy.get('[data-cy=collection-version-number]').should('contain', '1');
485 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
486 cy.get('[data-cy=collection-files-panel]')
487 .should('contain', 'foo').and('contain', 'bar');
489 // Check that only old collection action are available on context menu
490 cy.get('[data-cy=collection-panel-options-btn]').click();
491 cy.get('[data-cy=context-menu]')
492 .should('contain', 'Restore version')
493 .and('not.contain', 'Add to favorites');
494 cy.get('body').click(); // Collapse the menu avoiding details panel expansion
496 // Click on "head version" link, confirm that it's the latest version.
497 cy.get('[data-cy=collection-info-panel]').contains('head version').click();
498 cy.get('[data-cy=collection-info-panel]')
499 .should('not.contain', 'This is an old version');
500 cy.get('[data-cy=read-only-icon]').should('not.exist');
501 cy.get('[data-cy=collection-version-number]').should('contain', '2');
502 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
503 cy.get('[data-cy=collection-files-panel]').
504 should('not.contain', 'foo').and('contain', 'bar');
506 // Check that old collection action isn't available on context menu
507 cy.get('[data-cy=collection-panel-options-btn]').click()
508 cy.get('[data-cy=context-menu]').should('not.contain', 'Restore version')
509 cy.get('body').click(); // Collapse the menu avoiding details panel expansion
511 // Make another change, confirm new version.
512 cy.get('[data-cy=collection-panel-options-btn]').click();
513 cy.get('[data-cy=context-menu]').contains('Edit collection').click();
514 cy.get('[data-cy=form-dialog]')
515 .should('contain', 'Edit Collection')
518 cy.get('input').first().type(' renamed');
520 cy.get('[data-cy=form-submit-btn]').click();
521 cy.get('[data-cy=collection-info-panel]')
522 .should('not.contain', 'This is an old version');
523 cy.get('[data-cy=read-only-icon]').should('not.exist');
524 cy.get('[data-cy=collection-version-number]').should('contain', '3');
525 cy.get('[data-cy=collection-info-panel]').should('contain', colName + ' renamed');
526 cy.get('[data-cy=collection-files-panel]')
527 .should('not.contain', 'foo').and('contain', 'bar');
528 cy.get('[data-cy=collection-version-browser-select-3]')
529 .should('contain', '3').and('contain', '3 B');
531 // Check context menus on version browser
532 cy.get('[data-cy=collection-version-browser-select-3]').rightclick()
533 cy.get('[data-cy=context-menu]')
534 .should('contain', 'Add to favorites')
535 .and('contain', 'Make a copy')
536 .and('contain', 'Edit collection');
537 cy.get('body').click();
538 // (and now an old version...)
539 cy.get('[data-cy=collection-version-browser-select-1]').rightclick()
540 cy.get('[data-cy=context-menu]')
541 .should('not.contain', 'Add to favorites')
542 .and('contain', 'Make a copy')
543 .and('not.contain', 'Edit collection');
544 cy.get('body').click();
546 // Restore first version
547 cy.get('[data-cy=collection-version-browser]').within(() => {
548 cy.get('[data-cy=collection-version-browser-select-1]').click();
550 cy.get('[data-cy=collection-panel-options-btn]').click()
551 cy.get('[data-cy=context-menu]').contains('Restore version').click();
552 cy.get('[data-cy=confirmation-dialog]').should('contain', 'Restore version');
553 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
554 cy.get('[data-cy=collection-info-panel]')
555 .should('not.contain', 'This is an old version');
556 cy.get('[data-cy=collection-version-number]').should('contain', '4');
557 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
558 cy.get('[data-cy=collection-files-panel]')
559 .should('contain', 'foo').and('contain', 'bar');
563 it('creates new collection on home project', function () {
564 cy.loginAs(activeUser);
565 cy.goToPath(`/projects/${activeUser.user.uuid}`);
566 cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
567 cy.get('[data-cy=breadcrumb-last]').should('not.exist');
568 // Create new collection
569 cy.get('[data-cy=side-panel-button]').click();
570 cy.get('[data-cy=side-panel-new-collection]').click();
571 // Name between brackets tests bugfix #17582
572 const collName = `[Test collection (${Math.floor(999999 * Math.random())})]`;
573 cy.get('[data-cy=form-dialog]')
574 .should('contain', 'New collection')
576 cy.get('[data-cy=parent-field]').within(() => {
577 cy.get('input').should('have.value', 'Home project');
579 cy.get('[data-cy=name-field]').within(() => {
580 cy.get('input').type(collName);
583 cy.get('[data-cy=form-submit-btn]').click();
584 // Confirm that the user was taken to the newly created thing
585 cy.get('[data-cy=form-dialog]').should('not.exist');
586 cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
587 cy.get('[data-cy=breadcrumb-last]').should('contain', collName);