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.only('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.resolve(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);
71 .then(() => cy.task('clearDownload', { filename }));
75 it('uses the property editor with vocabulary terms', function () {
76 cy.createCollection(adminUser.token, {
77 name: `Test collection ${Math.floor(Math.random() * 999999)}`,
78 owner_uuid: activeUser.user.uuid,
79 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
81 .as('testCollection').then(function () {
82 cy.loginAs(activeUser);
83 cy.doSearch(`${this.testCollection.uuid}`);
85 // Key: Color (IDTAGCOLORS) - Value: Magenta (IDVALCOLORS3)
86 cy.get('[data-cy=resource-properties-form]').within(() => {
87 cy.get('[data-cy=property-field-key]').within(() => {
88 cy.get('input').type('Color');
90 cy.get('[data-cy=property-field-value]').within(() => {
91 cy.get('input').type('Magenta');
95 // Confirm proper vocabulary labels are displayed on the UI.
96 cy.get('[data-cy=collection-properties-panel]')
97 .should('contain', 'Color')
98 .and('contain', 'Magenta');
99 // Confirm proper vocabulary IDs were saved on the backend.
100 cy.doRequest('GET', `/arvados/v1/collections/${this.testCollection.uuid}`)
101 .its('body').as('collection')
103 expect(this.collection.properties).to.deep.equal(
104 { IDTAGCOLORS: 'IDVALCOLORS3' });
109 it('shows collection by URL', function () {
110 cy.loginAs(activeUser);
111 [true, false].map(function (isWritable) {
112 // Using different file names to avoid test flakyness: the second iteration
113 // on this loop may pass an assertion from the first iteration by looking
114 // for the same file name.
115 const fileName = isWritable ? 'bar' : 'foo';
116 cy.createGroup(adminUser.token, {
117 name: 'Shared project',
118 group_class: 'project',
119 }).as('sharedGroup').then(function () {
120 // Creates the collection using the admin token so we can set up
121 // a bogus manifest text without block signatures.
122 cy.createCollection(adminUser.token, {
123 name: 'Test collection',
124 owner_uuid: this.sharedGroup.uuid,
125 properties: { someKey: 'someValue' },
126 manifest_text: `. 37b51d194a7513e45b56f6524f2d51f2+3 0:3:${fileName}\n`
128 .as('testCollection').then(function () {
129 // Share the group with active user.
130 cy.createLink(adminUser.token, {
131 name: isWritable ? 'can_write' : 'can_read',
132 link_class: 'permission',
133 head_uuid: this.sharedGroup.uuid,
134 tail_uuid: activeUser.user.uuid
136 cy.doSearch(`${this.testCollection.uuid}`);
138 // Check that name & uuid are correct.
139 cy.get('[data-cy=collection-info-panel]')
140 .should('contain', this.testCollection.name)
141 .and('contain', this.testCollection.uuid)
142 .and('not.contain', 'This is an old version');
143 // Check for the read-only icon
144 cy.get('[data-cy=read-only-icon]').should(`${isWritable ? 'not.' : ''}exist`);
145 // Check that both read and write operations are available on
146 // the 'More options' menu.
147 cy.get('[data-cy=collection-panel-options-btn]')
149 cy.get('[data-cy=context-menu]')
150 .should('contain', 'Add to favorites')
151 .and(`${isWritable ? '' : 'not.'}contain`, 'Edit collection');
152 cy.get('body').click(); // Collapse the menu avoiding details panel expansion
153 cy.get('[data-cy=collection-properties-panel]')
154 .should('contain', 'someKey')
155 .and('contain', 'someValue')
156 .and('not.contain', 'anotherKey')
157 .and('not.contain', 'anotherValue')
158 if (isWritable === true) {
159 // Check that properties can be added.
160 cy.get('[data-cy=resource-properties-form]').within(() => {
161 cy.get('[data-cy=property-field-key]').within(() => {
162 cy.get('input').type('anotherKey');
164 cy.get('[data-cy=property-field-value]').within(() => {
165 cy.get('input').type('anotherValue');
169 cy.get('[data-cy=collection-properties-panel]')
170 .should('contain', 'anotherKey')
171 .and('contain', 'anotherValue')
173 // Properties form shouldn't be displayed.
174 cy.get('[data-cy=resource-properties-form]').should('not.exist');
176 // Check that the file listing show both read & write operations
177 cy.get('[data-cy=collection-files-panel]').within(() => {
178 cy.root().should('contain', fileName);
180 cy.get('[data-cy=upload-button]')
181 .should(`${isWritable ? '' : 'not.'}contain`, 'Upload data');
184 cy.get('[data-cy=collection-files-panel]')
185 .contains(fileName).rightclick({ force: true });
186 cy.get('[data-cy=context-menu]')
187 .should('contain', 'Download')
188 .and('contain', 'Open in new tab')
189 .and('contain', 'Copy to clipboard')
190 .and(`${isWritable ? '' : 'not.'}contain`, 'Rename')
191 .and(`${isWritable ? '' : 'not.'}contain`, 'Remove');
192 cy.get('body').click(); // Collapse the menu
193 // Hamburger 'more options' menu button
194 cy.get('[data-cy=collection-files-panel-options-btn]')
196 cy.get('[data-cy=context-menu]')
197 .should('contain', 'Select all')
199 cy.get('[data-cy=collection-files-panel-options-btn]')
201 cy.get('[data-cy=context-menu]')
202 // .should('contain', 'Download selected')
203 .should(`${isWritable ? '' : 'not.'}contain`, 'Remove selected')
204 cy.get('body').click(); // Collapse the menu
205 // File item 'more options' button
206 cy.get('[data-cy=file-item-options-btn')
208 cy.get('[data-cy=context-menu]')
209 .should('contain', 'Download')
210 .and(`${isWritable ? '' : 'not.'}contain`, 'Remove');
211 cy.get('body').click(); // Collapse the menu
217 it('renames a file using valid names', function () {
218 function eachPair(lst, func){
219 for(var i=0; i < lst.length - 1; i++){
220 func(lst[i], lst[i + 1])
223 // Creates the collection using the admin token so we can set up
224 // a bogus manifest text without block signatures.
225 cy.createCollection(adminUser.token, {
226 name: `Test collection ${Math.floor(Math.random() * 999999)}`,
227 owner_uuid: activeUser.user.uuid,
228 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
230 .as('testCollection').then(function () {
231 cy.loginAs(activeUser);
232 cy.doSearch(`${this.testCollection.uuid}`);
235 'bar', // initial name already set
242 'some name with whitespaces',
244 'is this name legal? I hope it is',
252 "G%C3%BCnter's%20file.pdf",
254 'bar' // make sure we can go back to the original name as a last step
256 eachPair(names, (from, to) => {
257 cy.get('[data-cy=collection-files-panel]')
258 .contains(`${from}`).rightclick();
259 cy.get('[data-cy=context-menu]')
262 cy.get('[data-cy=form-dialog]')
263 .should('contain', 'Rename')
265 cy.get('input').type(`{selectall}{backspace}${to}`);
267 cy.get('[data-cy=form-submit-btn]').click();
268 cy.get('[data-cy=collection-files-panel]')
269 .should('not.contain', `${from}`)
270 .and('contain', `${to}`);
275 it('renames a file to a different directory', function () {
276 // Creates the collection using the admin token so we can set up
277 // a bogus manifest text without block signatures.
278 cy.createCollection(adminUser.token, {
279 name: `Test collection ${Math.floor(Math.random() * 999999)}`,
280 owner_uuid: activeUser.user.uuid,
281 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
283 .as('testCollection').then(function () {
284 cy.loginAs(activeUser);
285 cy.doSearch(`${this.testCollection.uuid}`);
287 ['subdir', 'G%C3%BCnter\'s%20file', 'table%&?*2'].forEach((subdir) => {
288 cy.get('[data-cy=collection-files-panel]')
289 .contains('bar').rightclick({force: true});
290 cy.get('[data-cy=context-menu]')
293 cy.get('[data-cy=form-dialog]')
294 .should('contain', 'Rename')
296 cy.get('input').type(`{selectall}{backspace}${subdir}/foo`);
298 cy.get('[data-cy=form-submit-btn]').click();
299 cy.get('[data-cy=collection-files-panel]')
300 .should('not.contain', 'bar')
301 .and('contain', subdir);
302 // Look for the "arrow icon" and expand the "subdir" directory.
303 cy.get('[data-cy=virtual-file-tree] > div > i').click();
304 // Rename 'subdir/foo' to 'foo'
305 cy.get('[data-cy=collection-files-panel]')
306 .contains('foo').rightclick();
307 cy.get('[data-cy=context-menu]')
310 cy.get('[data-cy=form-dialog]')
311 .should('contain', 'Rename')
314 .should('have.value', `${subdir}/foo`)
315 .type(`{selectall}{backspace}bar`);
317 cy.get('[data-cy=form-submit-btn]').click();
318 cy.get('[data-cy=collection-files-panel]')
319 .should('contain', subdir) // empty dir kept
320 .and('contain', 'bar');
322 cy.get('[data-cy=collection-files-panel]')
323 .contains(subdir).rightclick();
324 cy.get('[data-cy=context-menu]')
327 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
332 it('tries to rename a file with illegal names', function () {
333 // Creates the collection using the admin token so we can set up
334 // a bogus manifest text without block signatures.
335 cy.createCollection(adminUser.token, {
336 name: `Test collection ${Math.floor(Math.random() * 999999)}`,
337 owner_uuid: activeUser.user.uuid,
338 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
340 .as('testCollection').then(function () {
341 cy.loginAs(activeUser);
342 cy.doSearch(`${this.testCollection.uuid}`);
344 const illegalNamesFromUI = [
345 ['.', "Name cannot be '.' or '..'"],
346 ['..', "Name cannot be '.' or '..'"],
347 ['', 'This field is required'],
348 [' ', 'Leading/trailing whitespaces not allowed'],
349 [' foo', 'Leading/trailing whitespaces not allowed'],
350 ['foo ', 'Leading/trailing whitespaces not allowed'],
351 ['//foo', 'Empty dir name not allowed']
353 illegalNamesFromUI.forEach(([name, errMsg]) => {
354 cy.get('[data-cy=collection-files-panel]')
355 .contains('bar').rightclick();
356 cy.get('[data-cy=context-menu]')
359 cy.get('[data-cy=form-dialog]')
360 .should('contain', 'Rename')
362 cy.get('input').type(`{selectall}{backspace}${name}`);
364 cy.get('[data-cy=form-dialog]')
365 .should('contain', 'Rename')
367 cy.contains(`${errMsg}`);
369 cy.get('[data-cy=form-cancel-btn]').click();
374 it('can correctly display old versions', function () {
375 const colName = `Versioned Collection ${Math.floor(Math.random() * 999999)}`;
377 let oldVersionUuid = '';
378 // Make sure no other collections with this name exist
379 cy.doRequest('GET', '/arvados/v1/collections', null, {
380 filters: `[["name", "=", "${colName}"]]`,
381 include_old_versions: true
383 .its('body.items').as('collections')
385 expect(this.collections).to.be.empty;
387 // Creates the collection using the admin token so we can set up
388 // a bogus manifest text without block signatures.
389 cy.createCollection(adminUser.token, {
391 owner_uuid: activeUser.user.uuid,
392 preserve_version: true,
393 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
395 .as('originalVersion').then(function () {
396 // Change the file name to create a new version.
397 cy.updateCollection(adminUser.token, this.originalVersion.uuid, {
398 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo\n"
400 colUuid = this.originalVersion.uuid;
402 // Confirm that there are 2 versions of the collection
403 cy.doRequest('GET', '/arvados/v1/collections', null, {
404 filters: `[["name", "=", "${colName}"]]`,
405 include_old_versions: true
407 .its('body.items').as('collections')
409 expect(this.collections).to.have.lengthOf(2);
410 this.collections.map(function (aCollection) {
411 expect(aCollection.current_version_uuid).to.equal(colUuid);
412 if (aCollection.uuid !== aCollection.current_version_uuid) {
413 oldVersionUuid = aCollection.uuid;
416 // Check the old version displays as what it is.
417 cy.loginAs(activeUser)
418 cy.doSearch(`${oldVersionUuid}`);
420 cy.get('[data-cy=collection-info-panel]').should('contain', 'This is an old version');
421 cy.get('[data-cy=read-only-icon]').should('exist');
422 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
423 cy.get('[data-cy=collection-files-panel]').should('contain', 'bar');
427 it('uses the collection version browser to view a previous version', function () {
428 const colName = `Test Collection ${Math.floor(Math.random() * 999999)}`;
430 // Creates the collection using the admin token so we can set up
431 // a bogus manifest text without block signatures.
432 cy.createCollection(adminUser.token, {
434 owner_uuid: activeUser.user.uuid,
435 preserve_version: true,
436 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo 0:3:bar\n"
438 .as('collection').then(function () {
439 // Visit collection, check basic information
440 cy.loginAs(activeUser)
441 cy.doSearch(`${this.collection.uuid}`);
443 cy.get('[data-cy=collection-info-panel]').should('not.contain', 'This is an old version');
444 cy.get('[data-cy=read-only-icon]').should('not.exist');
445 cy.get('[data-cy=collection-version-number]').should('contain', '1');
446 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
447 cy.get('[data-cy=collection-files-panel]').should('contain', 'foo').and('contain', 'bar');
449 // Modify collection, expect version number change
450 cy.get('[data-cy=collection-files-panel]').contains('foo').rightclick();
451 cy.get('[data-cy=context-menu]').contains('Remove').click();
452 cy.get('[data-cy=confirmation-dialog]').should('contain', 'Removing file');
453 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
454 cy.get('[data-cy=collection-version-number]').should('contain', '2');
455 cy.get('[data-cy=collection-files-panel]').should('not.contain', 'foo').and('contain', 'bar');
457 // Click on version number, check version browser. Click on past version.
458 cy.get('[data-cy=collection-version-browser]').should('not.exist');
459 cy.get('[data-cy=collection-version-number]').contains('2').click();
460 cy.get('[data-cy=collection-version-browser]')
461 .should('contain', 'Nr').and('contain', 'Size').and('contain', 'Date')
463 // Version 1: 6 bytes in size
464 cy.get('[data-cy=collection-version-browser-select-1]')
465 .should('contain', '1').and('contain', '6 B');
466 // Version 2: 3 bytes in size (one file removed)
467 cy.get('[data-cy=collection-version-browser-select-2]')
468 .should('contain', '2').and('contain', '3 B');
469 cy.get('[data-cy=collection-version-browser-select-3]')
470 .should('not.exist');
471 cy.get('[data-cy=collection-version-browser-select-1]')
474 cy.get('[data-cy=collection-info-panel]').should('contain', 'This is an old version');
475 cy.get('[data-cy=read-only-icon]').should('exist');
476 cy.get('[data-cy=collection-version-number]').should('contain', '1');
477 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
478 cy.get('[data-cy=collection-files-panel]')
479 .should('contain', 'foo').and('contain', 'bar');
481 // Check that only old collection action are available on context menu
482 cy.get('[data-cy=collection-panel-options-btn]').click();
483 cy.get('[data-cy=context-menu]')
484 .should('contain', 'Restore version')
485 .and('not.contain', 'Add to favorites');
486 cy.get('body').click(); // Collapse the menu avoiding details panel expansion
488 // Click on "head version" link, confirm that it's the latest version.
489 cy.get('[data-cy=collection-info-panel]').contains('head version').click();
490 cy.get('[data-cy=collection-info-panel]')
491 .should('not.contain', 'This is an old version');
492 cy.get('[data-cy=read-only-icon]').should('not.exist');
493 cy.get('[data-cy=collection-version-number]').should('contain', '2');
494 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
495 cy.get('[data-cy=collection-files-panel]').
496 should('not.contain', 'foo').and('contain', 'bar');
498 // Check that old collection action isn't available on context menu
499 cy.get('[data-cy=collection-panel-options-btn]').click()
500 cy.get('[data-cy=context-menu]').should('not.contain', 'Restore version')
501 cy.get('body').click(); // Collapse the menu avoiding details panel expansion
503 // Make another change, confirm new version.
504 cy.get('[data-cy=collection-panel-options-btn]').click();
505 cy.get('[data-cy=context-menu]').contains('Edit collection').click();
506 cy.get('[data-cy=form-dialog]')
507 .should('contain', 'Edit Collection')
510 cy.get('input').first().type(' renamed');
512 cy.get('[data-cy=form-submit-btn]').click();
513 cy.get('[data-cy=collection-info-panel]')
514 .should('not.contain', 'This is an old version');
515 cy.get('[data-cy=read-only-icon]').should('not.exist');
516 cy.get('[data-cy=collection-version-number]').should('contain', '3');
517 cy.get('[data-cy=collection-info-panel]').should('contain', colName + ' renamed');
518 cy.get('[data-cy=collection-files-panel]')
519 .should('not.contain', 'foo').and('contain', 'bar');
520 cy.get('[data-cy=collection-version-browser-select-3]')
521 .should('contain', '3').and('contain', '3 B');
523 // Check context menus on version browser
524 cy.get('[data-cy=collection-version-browser-select-3]').rightclick()
525 cy.get('[data-cy=context-menu]')
526 .should('contain', 'Add to favorites')
527 .and('contain', 'Make a copy')
528 .and('contain', 'Edit collection');
529 cy.get('body').click();
530 // (and now an old version...)
531 cy.get('[data-cy=collection-version-browser-select-1]').rightclick()
532 cy.get('[data-cy=context-menu]')
533 .should('not.contain', 'Add to favorites')
534 .and('contain', 'Make a copy')
535 .and('not.contain', 'Edit collection');
536 cy.get('body').click();
538 // Restore first version
539 cy.get('[data-cy=collection-version-browser]').within(() => {
540 cy.get('[data-cy=collection-version-browser-select-1]').click();
542 cy.get('[data-cy=collection-panel-options-btn]').click()
543 cy.get('[data-cy=context-menu]').contains('Restore version').click();
544 cy.get('[data-cy=confirmation-dialog]').should('contain', 'Restore version');
545 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
546 cy.get('[data-cy=collection-info-panel]')
547 .should('not.contain', 'This is an old version');
548 cy.get('[data-cy=collection-version-number]').should('contain', '4');
549 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
550 cy.get('[data-cy=collection-files-panel]')
551 .should('contain', 'foo').and('contain', 'bar');
555 it('creates new collection on home project', function () {
556 cy.loginAs(activeUser);
557 cy.doSearch(`${activeUser.user.uuid}`);
558 cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
559 cy.get('[data-cy=breadcrumb-last]').should('not.exist');
560 // Create new collection
561 cy.get('[data-cy=side-panel-button]').click();
562 cy.get('[data-cy=side-panel-new-collection]').click();
563 const collName = `Test collection (${Math.floor(999999 * Math.random())})`;
564 cy.get('[data-cy=form-dialog]')
565 .should('contain', 'New collection')
567 cy.get('[data-cy=parent-field]').within(() => {
568 cy.get('input').should('have.value', 'Home project');
570 cy.get('[data-cy=name-field]').within(() => {
571 cy.get('input').type(collName);
574 cy.get('[data-cy=form-submit-btn]').click();
575 // Confirm that the user was taken to the newly created thing
576 cy.get('[data-cy=form-dialog]').should('not.exist');
577 cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
578 cy.get('[data-cy=breadcrumb-last]').should('contain', collName);