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 })
52 .should('have.length.gt', 50)
53 .then(() => cy.task('clearDownload', { filename }));
57 it('uses the property editor with vocabulary terms', function () {
58 cy.createCollection(adminUser.token, {
59 name: `Test collection ${Math.floor(Math.random() * 999999)}`,
60 owner_uuid: activeUser.user.uuid,
61 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
63 .as('testCollection').then(function () {
64 cy.loginAs(activeUser);
65 cy.doSearch(`${this.testCollection.uuid}`);
67 // Key: Color (IDTAGCOLORS) - Value: Magenta (IDVALCOLORS3)
68 cy.get('[data-cy=resource-properties-form]').within(() => {
69 cy.get('[data-cy=property-field-key]').within(() => {
70 cy.get('input').type('Color');
72 cy.get('[data-cy=property-field-value]').within(() => {
73 cy.get('input').type('Magenta');
77 // Confirm proper vocabulary labels are displayed on the UI.
78 cy.get('[data-cy=collection-properties-panel]')
79 .should('contain', 'Color')
80 .and('contain', 'Magenta');
81 // Confirm proper vocabulary IDs were saved on the backend.
82 cy.doRequest('GET', `/arvados/v1/collections/${this.testCollection.uuid}`)
83 .its('body').as('collection')
85 expect(this.collection.properties).to.deep.equal(
86 { IDTAGCOLORS: 'IDVALCOLORS3' });
91 it('shows collection by URL', function () {
92 cy.loginAs(activeUser);
93 [true, false].map(function (isWritable) {
94 // Using different file names to avoid test flakyness: the second iteration
95 // on this loop may pass an assertion from the first iteration by looking
96 // for the same file name.
97 const fileName = isWritable ? 'bar' : 'foo';
98 cy.createGroup(adminUser.token, {
99 name: 'Shared project',
100 group_class: 'project',
101 }).as('sharedGroup').then(function () {
102 // Creates the collection using the admin token so we can set up
103 // a bogus manifest text without block signatures.
104 cy.createCollection(adminUser.token, {
105 name: 'Test collection',
106 owner_uuid: this.sharedGroup.uuid,
107 properties: { someKey: 'someValue' },
108 manifest_text: `. 37b51d194a7513e45b56f6524f2d51f2+3 0:3:${fileName}\n`
110 .as('testCollection').then(function () {
111 // Share the group with active user.
112 cy.createLink(adminUser.token, {
113 name: isWritable ? 'can_write' : 'can_read',
114 link_class: 'permission',
115 head_uuid: this.sharedGroup.uuid,
116 tail_uuid: activeUser.user.uuid
118 cy.doSearch(`${this.testCollection.uuid}`);
120 // Check that name & uuid are correct.
121 cy.get('[data-cy=collection-info-panel]')
122 .should('contain', this.testCollection.name)
123 .and('contain', this.testCollection.uuid)
124 .and('not.contain', 'This is an old version');
125 // Check for the read-only icon
126 cy.get('[data-cy=read-only-icon]').should(`${isWritable ? 'not.' : ''}exist`);
127 // Check that both read and write operations are available on
128 // the 'More options' menu.
129 cy.get('[data-cy=collection-panel-options-btn]')
131 cy.get('[data-cy=context-menu]')
132 .should('contain', 'Add to favorites')
133 .and(`${isWritable ? '' : 'not.'}contain`, 'Edit collection');
134 cy.get('body').click(); // Collapse the menu avoiding details panel expansion
135 cy.get('[data-cy=collection-properties-panel]')
136 .should('contain', 'someKey')
137 .and('contain', 'someValue')
138 .and('not.contain', 'anotherKey')
139 .and('not.contain', 'anotherValue')
140 if (isWritable === true) {
141 // Check that properties can be added.
142 cy.get('[data-cy=resource-properties-form]').within(() => {
143 cy.get('[data-cy=property-field-key]').within(() => {
144 cy.get('input').type('anotherKey');
146 cy.get('[data-cy=property-field-value]').within(() => {
147 cy.get('input').type('anotherValue');
151 cy.get('[data-cy=collection-properties-panel]')
152 .should('contain', 'anotherKey')
153 .and('contain', 'anotherValue')
155 // Properties form shouldn't be displayed.
156 cy.get('[data-cy=resource-properties-form]').should('not.exist');
158 // Check that the file listing show both read & write operations
159 cy.get('[data-cy=collection-files-panel]').within(() => {
160 cy.root().should('contain', fileName);
162 cy.get('[data-cy=upload-button]')
163 .should(`${isWritable ? '' : 'not.'}contain`, 'Upload data');
166 cy.get('[data-cy=collection-files-panel]')
167 .contains(fileName).rightclick({ force: true });
168 cy.get('[data-cy=context-menu]')
169 .should('contain', 'Download')
170 .and('contain', 'Open in new tab')
171 .and('contain', 'Copy to clipboard')
172 .and(`${isWritable ? '' : 'not.'}contain`, 'Rename')
173 .and(`${isWritable ? '' : 'not.'}contain`, 'Remove');
174 cy.get('body').click(); // Collapse the menu
175 // Hamburger 'more options' menu button
176 cy.get('[data-cy=collection-files-panel-options-btn]')
178 cy.get('[data-cy=context-menu]')
179 .should('contain', 'Select all')
181 cy.get('[data-cy=collection-files-panel-options-btn]')
183 cy.get('[data-cy=context-menu]')
184 // .should('contain', 'Download selected')
185 .should(`${isWritable ? '' : 'not.'}contain`, 'Remove selected')
186 cy.get('body').click(); // Collapse the menu
187 // File item 'more options' button
188 cy.get('[data-cy=file-item-options-btn')
190 cy.get('[data-cy=context-menu]')
191 .should('contain', 'Download')
192 .and(`${isWritable ? '' : 'not.'}contain`, 'Remove');
193 cy.get('body').click(); // Collapse the menu
199 it('renames a file using valid names', function () {
200 function eachPair(lst, func){
201 for(var i=0; i < lst.length - 1; i++){
202 func(lst[i], lst[i + 1])
205 // Creates the collection using the admin token so we can set up
206 // a bogus manifest text without block signatures.
207 cy.createCollection(adminUser.token, {
208 name: `Test collection ${Math.floor(Math.random() * 999999)}`,
209 owner_uuid: activeUser.user.uuid,
210 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
212 .as('testCollection').then(function () {
213 cy.loginAs(activeUser);
214 cy.doSearch(`${this.testCollection.uuid}`);
217 'bar', // initial name already set
224 'some name with whitespaces',
226 'is this name legal? I hope it is',
234 "G%C3%BCnter's%20file.pdf",
236 'bar' // make sure we can go back to the original name as a last step
238 eachPair(names, (from, to) => {
239 cy.get('[data-cy=collection-files-panel]')
240 .contains(`${from}`).rightclick();
241 cy.get('[data-cy=context-menu]')
244 cy.get('[data-cy=form-dialog]')
245 .should('contain', 'Rename')
247 cy.get('input').type(`{selectall}{backspace}${to}`);
249 cy.get('[data-cy=form-submit-btn]').click();
250 cy.get('[data-cy=collection-files-panel]')
251 .should('not.contain', `${from}`)
252 .and('contain', `${to}`);
257 it('renames a file to a different directory', function () {
258 // Creates the collection using the admin token so we can set up
259 // a bogus manifest text without block signatures.
260 cy.createCollection(adminUser.token, {
261 name: `Test collection ${Math.floor(Math.random() * 999999)}`,
262 owner_uuid: activeUser.user.uuid,
263 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
265 .as('testCollection').then(function () {
266 cy.loginAs(activeUser);
267 cy.doSearch(`${this.testCollection.uuid}`);
269 ['subdir', 'G%C3%BCnter\'s%20file', 'table%&?*2'].forEach((subdir) => {
270 cy.get('[data-cy=collection-files-panel]')
271 .contains('bar').rightclick({force: true});
272 cy.get('[data-cy=context-menu]')
275 cy.get('[data-cy=form-dialog]')
276 .should('contain', 'Rename')
278 cy.get('input').type(`{selectall}{backspace}${subdir}/foo`);
280 cy.get('[data-cy=form-submit-btn]').click();
281 cy.get('[data-cy=collection-files-panel]')
282 .should('not.contain', 'bar')
283 .and('contain', subdir);
284 // Look for the "arrow icon" and expand the "subdir" directory.
285 cy.get('[data-cy=virtual-file-tree] > div > i').click();
286 // Rename 'subdir/foo' to 'foo'
287 cy.get('[data-cy=collection-files-panel]')
288 .contains('foo').rightclick();
289 cy.get('[data-cy=context-menu]')
292 cy.get('[data-cy=form-dialog]')
293 .should('contain', 'Rename')
296 .should('have.value', `${subdir}/foo`)
297 .type(`{selectall}{backspace}bar`);
299 cy.get('[data-cy=form-submit-btn]').click();
300 cy.get('[data-cy=collection-files-panel]')
301 .should('contain', subdir) // empty dir kept
302 .and('contain', 'bar');
304 cy.get('[data-cy=collection-files-panel]')
305 .contains(subdir).rightclick();
306 cy.get('[data-cy=context-menu]')
309 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
314 it('tries to rename a file with illegal names', function () {
315 // Creates the collection using the admin token so we can set up
316 // a bogus manifest text without block signatures.
317 cy.createCollection(adminUser.token, {
318 name: `Test collection ${Math.floor(Math.random() * 999999)}`,
319 owner_uuid: activeUser.user.uuid,
320 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
322 .as('testCollection').then(function () {
323 cy.loginAs(activeUser);
324 cy.doSearch(`${this.testCollection.uuid}`);
326 const illegalNamesFromUI = [
327 ['.', "Name cannot be '.' or '..'"],
328 ['..', "Name cannot be '.' or '..'"],
329 ['', 'This field is required'],
330 [' ', 'Leading/trailing whitespaces not allowed'],
331 [' foo', 'Leading/trailing whitespaces not allowed'],
332 ['foo ', 'Leading/trailing whitespaces not allowed'],
333 ['//foo', 'Empty dir name not allowed']
335 illegalNamesFromUI.forEach(([name, errMsg]) => {
336 cy.get('[data-cy=collection-files-panel]')
337 .contains('bar').rightclick();
338 cy.get('[data-cy=context-menu]')
341 cy.get('[data-cy=form-dialog]')
342 .should('contain', 'Rename')
344 cy.get('input').type(`{selectall}{backspace}${name}`);
346 cy.get('[data-cy=form-dialog]')
347 .should('contain', 'Rename')
349 cy.contains(`${errMsg}`);
351 cy.get('[data-cy=form-cancel-btn]').click();
356 it('can correctly display old versions', function () {
357 const colName = `Versioned Collection ${Math.floor(Math.random() * 999999)}`;
359 let oldVersionUuid = '';
360 // Make sure no other collections with this name exist
361 cy.doRequest('GET', '/arvados/v1/collections', null, {
362 filters: `[["name", "=", "${colName}"]]`,
363 include_old_versions: true
365 .its('body.items').as('collections')
367 expect(this.collections).to.be.empty;
369 // Creates the collection using the admin token so we can set up
370 // a bogus manifest text without block signatures.
371 cy.createCollection(adminUser.token, {
373 owner_uuid: activeUser.user.uuid,
374 preserve_version: true,
375 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
377 .as('originalVersion').then(function () {
378 // Change the file name to create a new version.
379 cy.updateCollection(adminUser.token, this.originalVersion.uuid, {
380 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo\n"
382 colUuid = this.originalVersion.uuid;
384 // Confirm that there are 2 versions of the collection
385 cy.doRequest('GET', '/arvados/v1/collections', null, {
386 filters: `[["name", "=", "${colName}"]]`,
387 include_old_versions: true
389 .its('body.items').as('collections')
391 expect(this.collections).to.have.lengthOf(2);
392 this.collections.map(function (aCollection) {
393 expect(aCollection.current_version_uuid).to.equal(colUuid);
394 if (aCollection.uuid !== aCollection.current_version_uuid) {
395 oldVersionUuid = aCollection.uuid;
398 // Check the old version displays as what it is.
399 cy.loginAs(activeUser)
400 cy.doSearch(`${oldVersionUuid}`);
402 cy.get('[data-cy=collection-info-panel]').should('contain', 'This is an old version');
403 cy.get('[data-cy=read-only-icon]').should('exist');
404 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
405 cy.get('[data-cy=collection-files-panel]').should('contain', 'bar');
409 it('uses the collection version browser to view a previous version', function () {
410 const colName = `Test Collection ${Math.floor(Math.random() * 999999)}`;
412 // Creates the collection using the admin token so we can set up
413 // a bogus manifest text without block signatures.
414 cy.createCollection(adminUser.token, {
416 owner_uuid: activeUser.user.uuid,
417 preserve_version: true,
418 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo 0:3:bar\n"
420 .as('collection').then(function () {
421 // Visit collection, check basic information
422 cy.loginAs(activeUser)
423 cy.doSearch(`${this.collection.uuid}`);
425 cy.get('[data-cy=collection-info-panel]').should('not.contain', 'This is an old version');
426 cy.get('[data-cy=read-only-icon]').should('not.exist');
427 cy.get('[data-cy=collection-version-number]').should('contain', '1');
428 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
429 cy.get('[data-cy=collection-files-panel]').should('contain', 'foo').and('contain', 'bar');
431 // Modify collection, expect version number change
432 cy.get('[data-cy=collection-files-panel]').contains('foo').rightclick();
433 cy.get('[data-cy=context-menu]').contains('Remove').click();
434 cy.get('[data-cy=confirmation-dialog]').should('contain', 'Removing file');
435 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
436 cy.get('[data-cy=collection-version-number]').should('contain', '2');
437 cy.get('[data-cy=collection-files-panel]').should('not.contain', 'foo').and('contain', 'bar');
439 // Click on version number, check version browser. Click on past version.
440 cy.get('[data-cy=collection-version-browser]').should('not.exist');
441 cy.get('[data-cy=collection-version-number]').contains('2').click();
442 cy.get('[data-cy=collection-version-browser]')
443 .should('contain', 'Nr').and('contain', 'Size').and('contain', 'Date')
445 // Version 1: 6 bytes in size
446 cy.get('[data-cy=collection-version-browser-select-1]')
447 .should('contain', '1').and('contain', '6 B');
448 // Version 2: 3 bytes in size (one file removed)
449 cy.get('[data-cy=collection-version-browser-select-2]')
450 .should('contain', '2').and('contain', '3 B');
451 cy.get('[data-cy=collection-version-browser-select-3]')
452 .should('not.exist');
453 cy.get('[data-cy=collection-version-browser-select-1]')
456 cy.get('[data-cy=collection-info-panel]').should('contain', 'This is an old version');
457 cy.get('[data-cy=read-only-icon]').should('exist');
458 cy.get('[data-cy=collection-version-number]').should('contain', '1');
459 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
460 cy.get('[data-cy=collection-files-panel]')
461 .should('contain', 'foo').and('contain', 'bar');
463 // Check that only old collection action are available on context menu
464 cy.get('[data-cy=collection-panel-options-btn]').click();
465 cy.get('[data-cy=context-menu]')
466 .should('contain', 'Restore version')
467 .and('not.contain', 'Add to favorites');
468 cy.get('body').click(); // Collapse the menu avoiding details panel expansion
470 // Click on "head version" link, confirm that it's the latest version.
471 cy.get('[data-cy=collection-info-panel]').contains('head version').click();
472 cy.get('[data-cy=collection-info-panel]')
473 .should('not.contain', 'This is an old version');
474 cy.get('[data-cy=read-only-icon]').should('not.exist');
475 cy.get('[data-cy=collection-version-number]').should('contain', '2');
476 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
477 cy.get('[data-cy=collection-files-panel]').
478 should('not.contain', 'foo').and('contain', 'bar');
480 // Check that old collection action isn't available on context menu
481 cy.get('[data-cy=collection-panel-options-btn]').click()
482 cy.get('[data-cy=context-menu]').should('not.contain', 'Restore version')
483 cy.get('body').click(); // Collapse the menu avoiding details panel expansion
485 // Make another change, confirm new version.
486 cy.get('[data-cy=collection-panel-options-btn]').click();
487 cy.get('[data-cy=context-menu]').contains('Edit collection').click();
488 cy.get('[data-cy=form-dialog]')
489 .should('contain', 'Edit Collection')
492 cy.get('input').first().type(' renamed');
494 cy.get('[data-cy=form-submit-btn]').click();
495 cy.get('[data-cy=collection-info-panel]')
496 .should('not.contain', 'This is an old version');
497 cy.get('[data-cy=read-only-icon]').should('not.exist');
498 cy.get('[data-cy=collection-version-number]').should('contain', '3');
499 cy.get('[data-cy=collection-info-panel]').should('contain', colName + ' renamed');
500 cy.get('[data-cy=collection-files-panel]')
501 .should('not.contain', 'foo').and('contain', 'bar');
502 cy.get('[data-cy=collection-version-browser-select-3]')
503 .should('contain', '3').and('contain', '3 B');
505 // Check context menus on version browser
506 cy.get('[data-cy=collection-version-browser-select-3]').rightclick()
507 cy.get('[data-cy=context-menu]')
508 .should('contain', 'Add to favorites')
509 .and('contain', 'Make a copy')
510 .and('contain', 'Edit collection');
511 cy.get('body').click();
512 // (and now an old version...)
513 cy.get('[data-cy=collection-version-browser-select-1]').rightclick()
514 cy.get('[data-cy=context-menu]')
515 .should('not.contain', 'Add to favorites')
516 .and('contain', 'Make a copy')
517 .and('not.contain', 'Edit collection');
518 cy.get('body').click();
520 // Restore first version
521 cy.get('[data-cy=collection-version-browser]').within(() => {
522 cy.get('[data-cy=collection-version-browser-select-1]').click();
524 cy.get('[data-cy=collection-panel-options-btn]').click()
525 cy.get('[data-cy=context-menu]').contains('Restore version').click();
526 cy.get('[data-cy=confirmation-dialog]').should('contain', 'Restore version');
527 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
528 cy.get('[data-cy=collection-info-panel]')
529 .should('not.contain', 'This is an old version');
530 cy.get('[data-cy=collection-version-number]').should('contain', '4');
531 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
532 cy.get('[data-cy=collection-files-panel]')
533 .should('contain', 'foo').and('contain', 'bar');
537 it('creates new collection on home project', function () {
538 cy.loginAs(activeUser);
539 cy.doSearch(`${activeUser.user.uuid}`);
540 cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
541 cy.get('[data-cy=breadcrumb-last]').should('not.exist');
542 // Create new collection
543 cy.get('[data-cy=side-panel-button]').click();
544 cy.get('[data-cy=side-panel-new-collection]').click();
545 const collName = `Test collection (${Math.floor(999999 * Math.random())})`;
546 cy.get('[data-cy=form-dialog]')
547 .should('contain', 'New collection')
549 cy.get('[data-cy=parent-field]').within(() => {
550 cy.get('input').should('have.value', 'Home project');
552 cy.get('[data-cy=name-field]').within(() => {
553 cy.get('input').type(collName);
556 cy.get('[data-cy=form-submit-btn]').click();
557 // Confirm that the user was taken to the newly created thing
558 cy.get('[data-cy=form-dialog]').should('not.exist');
559 cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
560 cy.get('[data-cy=breadcrumb-last]').should('contain', collName);