1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 describe('Collection panel tests', function () {
10 // Only set up common users once. These aren't set up as aliases because
11 // aliases are cleaned up after every test. Also it doesn't make sense
12 // to set the same users on beforeEach() over and over again, so we
13 // separate a little from Cypress' 'Best Practices' here.
14 cy.getUser('admin', 'Admin', 'User', true, true)
15 .as('adminUser').then(function () {
16 adminUser = this.adminUser;
19 cy.getUser('collectionuser1', 'Collection', 'User', false, true)
20 .as('activeUser').then(function () {
21 activeUser = this.activeUser;
26 beforeEach(function () {
28 cy.clearLocalStorage();
31 it('uses the property editor with vocabulary terms', function () {
32 cy.createCollection(adminUser.token, {
33 name: `Test collection ${Math.floor(Math.random() * 999999)}`,
34 owner_uuid: activeUser.user.uuid,
35 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
37 .as('testCollection').then(function () {
38 cy.loginAs(activeUser);
39 cy.doSearch(`${this.testCollection.uuid}`);
41 // Key: Color (IDTAGCOLORS) - Value: Magenta (IDVALCOLORS3)
42 cy.get('[data-cy=resource-properties-form]').within(() => {
43 cy.get('[data-cy=property-field-key]').within(() => {
44 cy.get('input').type('Color');
46 cy.get('[data-cy=property-field-value]').within(() => {
47 cy.get('input').type('Magenta');
51 // Confirm proper vocabulary labels are displayed on the UI.
52 cy.get('[data-cy=collection-properties-panel]')
53 .should('contain', 'Color')
54 .and('contain', 'Magenta');
55 // Confirm proper vocabulary IDs were saved on the backend.
56 cy.doRequest('GET', `/arvados/v1/collections/${this.testCollection.uuid}`)
57 .its('body').as('collection')
59 expect(this.collection.properties).to.deep.equal(
60 { IDTAGCOLORS: 'IDVALCOLORS3' });
65 it('shows collection by URL', function () {
66 cy.loginAs(activeUser);
67 [true, false].map(function (isWritable) {
68 // Using different file names to avoid test flakyness: the second iteration
69 // on this loop may pass an assertion from the first iteration by looking
70 // for the same file name.
71 const fileName = isWritable ? 'bar' : 'foo';
72 cy.createGroup(adminUser.token, {
73 name: 'Shared project',
74 group_class: 'project',
75 }).as('sharedGroup').then(function () {
76 // Creates the collection using the admin token so we can set up
77 // a bogus manifest text without block signatures.
78 cy.createCollection(adminUser.token, {
79 name: 'Test collection',
80 owner_uuid: this.sharedGroup.uuid,
81 properties: { someKey: 'someValue' },
82 manifest_text: `. 37b51d194a7513e45b56f6524f2d51f2+3 0:3:${fileName}\n`
84 .as('testCollection').then(function () {
85 // Share the group with active user.
86 cy.createLink(adminUser.token, {
87 name: isWritable ? 'can_write' : 'can_read',
88 link_class: 'permission',
89 head_uuid: this.sharedGroup.uuid,
90 tail_uuid: activeUser.user.uuid
92 cy.doSearch(`${this.testCollection.uuid}`);
94 // Check that name & uuid are correct.
95 cy.get('[data-cy=collection-info-panel]')
96 .should('contain', this.testCollection.name)
97 .and('contain', this.testCollection.uuid)
98 .and('not.contain', 'This is an old version');
99 // Check for the read-only icon
100 cy.get('[data-cy=read-only-icon]').should(`${isWritable ? 'not.' : ''}exist`);
101 // Check that both read and write operations are available on
102 // the 'More options' menu.
103 cy.get('[data-cy=collection-panel-options-btn]')
105 cy.get('[data-cy=context-menu]')
106 .should('contain', 'Add to favorites')
107 .and(`${isWritable ? '' : 'not.'}contain`, 'Edit collection');
108 cy.get('body').click(); // Collapse the menu avoiding details panel expansion
109 cy.get('[data-cy=collection-properties-panel]')
110 .should('contain', 'someKey')
111 .and('contain', 'someValue')
112 .and('not.contain', 'anotherKey')
113 .and('not.contain', 'anotherValue')
114 if (isWritable === true) {
115 // Check that properties can be added.
116 cy.get('[data-cy=resource-properties-form]').within(() => {
117 cy.get('[data-cy=property-field-key]').within(() => {
118 cy.get('input').type('anotherKey');
120 cy.get('[data-cy=property-field-value]').within(() => {
121 cy.get('input').type('anotherValue');
125 cy.get('[data-cy=collection-properties-panel]')
126 .should('contain', 'anotherKey')
127 .and('contain', 'anotherValue')
129 // Properties form shouldn't be displayed.
130 cy.get('[data-cy=resource-properties-form]').should('not.exist');
132 // Check that the file listing show both read & write operations
133 cy.get('[data-cy=collection-files-panel]').within(() => {
134 cy.root().should('contain', fileName);
136 cy.get('[data-cy=upload-button]')
137 .should(`${isWritable ? '' : 'not.'}contain`, 'Upload data');
140 cy.get('[data-cy=collection-files-panel]')
141 .contains(fileName).rightclick({ force: true });
142 cy.get('[data-cy=context-menu]')
143 .should('contain', 'Download')
144 .and('contain', 'Open in new tab')
145 .and('contain', 'Copy to clipboard')
146 .and(`${isWritable ? '' : 'not.'}contain`, 'Rename')
147 .and(`${isWritable ? '' : 'not.'}contain`, 'Remove');
148 cy.get('body').click(); // Collapse the menu
149 // Hamburger 'more options' menu button
150 cy.get('[data-cy=collection-files-panel-options-btn]')
152 cy.get('[data-cy=context-menu]')
153 .should('contain', 'Select all')
155 cy.get('[data-cy=collection-files-panel-options-btn]')
157 cy.get('[data-cy=context-menu]')
158 // .should('contain', 'Download selected')
159 .should(`${isWritable ? '' : 'not.'}contain`, 'Remove selected')
160 cy.get('body').click(); // Collapse the menu
161 // File item 'more options' button
162 cy.get('[data-cy=file-item-options-btn')
164 cy.get('[data-cy=context-menu]')
165 .should('contain', 'Download')
166 .and(`${isWritable ? '' : 'not.'}contain`, 'Remove');
167 cy.get('body').click(); // Collapse the menu
173 it('renames a file using valid names', function () {
174 function eachPair(lst, func){
175 for(var i=0; i < lst.length - 1; i++){
176 func(lst[i], lst[i + 1])
179 // Creates the collection using the admin token so we can set up
180 // a bogus manifest text without block signatures.
181 cy.createCollection(adminUser.token, {
182 name: `Test collection ${Math.floor(Math.random() * 999999)}`,
183 owner_uuid: activeUser.user.uuid,
184 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
186 .as('testCollection').then(function () {
187 cy.loginAs(activeUser);
188 cy.doSearch(`${this.testCollection.uuid}`);
191 'bar', // initial name already set
198 'some name with whitespaces',
200 'is this name legal? I hope it is',
208 "G%C3%BCnter's%20file.pdf",
210 'bar' // make sure we can go back to the original name as a last step
212 eachPair(names, (from, to) => {
213 cy.get('[data-cy=collection-files-panel]')
214 .contains(`${from}`).rightclick();
215 cy.get('[data-cy=context-menu]')
218 cy.get('[data-cy=form-dialog]')
219 .should('contain', 'Rename')
221 cy.get('input').type(`{selectall}{backspace}${to}`);
223 cy.get('[data-cy=form-submit-btn]').click();
224 cy.get('[data-cy=collection-files-panel]')
225 .should('not.contain', `${from}`)
226 .and('contain', `${to}`);
231 it('renames a file to a different directory', function () {
232 // Creates the collection using the admin token so we can set up
233 // a bogus manifest text without block signatures.
234 cy.createCollection(adminUser.token, {
235 name: `Test collection ${Math.floor(Math.random() * 999999)}`,
236 owner_uuid: activeUser.user.uuid,
237 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
239 .as('testCollection').then(function () {
240 cy.loginAs(activeUser);
241 cy.doSearch(`${this.testCollection.uuid}`);
243 ['subdir', 'G%C3%BCnter\'s%20file', 'table%&?*2'].forEach((subdir) => {
244 cy.get('[data-cy=collection-files-panel]')
245 .contains('bar').rightclick({force: true});
246 cy.get('[data-cy=context-menu]')
249 cy.get('[data-cy=form-dialog]')
250 .should('contain', 'Rename')
252 cy.get('input').type(`{selectall}{backspace}${subdir}/foo`);
254 cy.get('[data-cy=form-submit-btn]').click();
255 cy.get('[data-cy=collection-files-panel]')
256 .should('not.contain', 'bar')
257 .and('contain', subdir);
258 // Look for the "arrow icon" and expand the "subdir" directory.
259 cy.get('[data-cy=virtual-file-tree] > div > i').click();
260 // Rename 'subdir/foo' to 'foo'
261 cy.get('[data-cy=collection-files-panel]')
262 .contains('foo').rightclick();
263 cy.get('[data-cy=context-menu]')
266 cy.get('[data-cy=form-dialog]')
267 .should('contain', 'Rename')
270 .should('have.value', `${subdir}/foo`)
271 .type(`{selectall}{backspace}bar`);
273 cy.get('[data-cy=form-submit-btn]').click();
274 cy.get('[data-cy=collection-files-panel]')
275 .should('contain', subdir) // empty dir kept
276 .and('contain', 'bar');
278 cy.get('[data-cy=collection-files-panel]')
279 .contains(subdir).rightclick();
280 cy.get('[data-cy=context-menu]')
283 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
288 it('tries to rename a file with illegal names', function () {
289 // Creates the collection using the admin token so we can set up
290 // a bogus manifest text without block signatures.
291 cy.createCollection(adminUser.token, {
292 name: `Test collection ${Math.floor(Math.random() * 999999)}`,
293 owner_uuid: activeUser.user.uuid,
294 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
296 .as('testCollection').then(function () {
297 cy.loginAs(activeUser);
298 cy.doSearch(`${this.testCollection.uuid}`);
300 const illegalNamesFromUI = [
301 ['.', "Name cannot be '.' or '..'"],
302 ['..', "Name cannot be '.' or '..'"],
303 ['', 'This field is required'],
304 [' ', 'Leading/trailing whitespaces not allowed'],
305 [' foo', 'Leading/trailing whitespaces not allowed'],
306 ['foo ', 'Leading/trailing whitespaces not allowed'],
307 ['//foo', 'Empty dir name not allowed']
309 illegalNamesFromUI.forEach(([name, errMsg]) => {
310 cy.get('[data-cy=collection-files-panel]')
311 .contains('bar').rightclick();
312 cy.get('[data-cy=context-menu]')
315 cy.get('[data-cy=form-dialog]')
316 .should('contain', 'Rename')
318 cy.get('input').type(`{selectall}{backspace}${name}`);
320 cy.get('[data-cy=form-dialog]')
321 .should('contain', 'Rename')
323 cy.contains(`${errMsg}`);
325 cy.get('[data-cy=form-cancel-btn]').click();
330 it('can correctly display old versions', function () {
331 const colName = `Versioned Collection ${Math.floor(Math.random() * 999999)}`;
333 let oldVersionUuid = '';
334 // Make sure no other collections with this name exist
335 cy.doRequest('GET', '/arvados/v1/collections', null, {
336 filters: `[["name", "=", "${colName}"]]`,
337 include_old_versions: true
339 .its('body.items').as('collections')
341 expect(this.collections).to.be.empty;
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, {
347 owner_uuid: activeUser.user.uuid,
348 preserve_version: true,
349 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
351 .as('originalVersion').then(function () {
352 // Change the file name to create a new version.
353 cy.updateCollection(adminUser.token, this.originalVersion.uuid, {
354 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo\n"
356 colUuid = this.originalVersion.uuid;
358 // Confirm that there are 2 versions of the collection
359 cy.doRequest('GET', '/arvados/v1/collections', null, {
360 filters: `[["name", "=", "${colName}"]]`,
361 include_old_versions: true
363 .its('body.items').as('collections')
365 expect(this.collections).to.have.lengthOf(2);
366 this.collections.map(function (aCollection) {
367 expect(aCollection.current_version_uuid).to.equal(colUuid);
368 if (aCollection.uuid !== aCollection.current_version_uuid) {
369 oldVersionUuid = aCollection.uuid;
372 // Check the old version displays as what it is.
373 cy.loginAs(activeUser)
374 cy.doSearch(`${oldVersionUuid}`);
376 cy.get('[data-cy=collection-info-panel]').should('contain', 'This is an old version');
377 cy.get('[data-cy=read-only-icon]').should('exist');
378 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
379 cy.get('[data-cy=collection-files-panel]').should('contain', 'bar');
383 it('uses the collection version browser to view a previous version', function () {
384 const colName = `Test Collection ${Math.floor(Math.random() * 999999)}`;
386 // Creates the collection using the admin token so we can set up
387 // a bogus manifest text without block signatures.
388 cy.createCollection(adminUser.token, {
390 owner_uuid: activeUser.user.uuid,
391 preserve_version: true,
392 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo 0:3:bar\n"
394 .as('collection').then(function () {
395 // Visit collection, check basic information
396 cy.loginAs(activeUser)
397 cy.doSearch(`${this.collection.uuid}`);
399 cy.get('[data-cy=collection-info-panel]').should('not.contain', 'This is an old version');
400 cy.get('[data-cy=read-only-icon]').should('not.exist');
401 cy.get('[data-cy=collection-version-number]').should('contain', '1');
402 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
403 cy.get('[data-cy=collection-files-panel]').should('contain', 'foo').and('contain', 'bar');
405 // Modify collection, expect version number change
406 cy.get('[data-cy=collection-files-panel]').contains('foo').rightclick();
407 cy.get('[data-cy=context-menu]').contains('Remove').click();
408 cy.get('[data-cy=confirmation-dialog]').should('contain', 'Removing file');
409 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
410 cy.get('[data-cy=collection-version-number]').should('contain', '2');
411 cy.get('[data-cy=collection-files-panel]').should('not.contain', 'foo').and('contain', 'bar');
413 // Click on version number, check version browser. Click on past version.
414 cy.get('[data-cy=collection-version-browser]').should('not.exist');
415 cy.get('[data-cy=collection-version-number]').contains('2').click();
416 cy.get('[data-cy=collection-version-browser]')
417 .should('contain', 'Nr').and('contain', 'Size').and('contain', 'Date')
419 // Version 1: 6 bytes in size
420 cy.get('[data-cy=collection-version-browser-select-1]')
421 .should('contain', '1').and('contain', '6 B');
422 // Version 2: 3 bytes in size (one file removed)
423 cy.get('[data-cy=collection-version-browser-select-2]')
424 .should('contain', '2').and('contain', '3 B');
425 cy.get('[data-cy=collection-version-browser-select-3]')
426 .should('not.exist');
427 cy.get('[data-cy=collection-version-browser-select-1]')
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-version-number]').should('contain', '1');
433 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
434 cy.get('[data-cy=collection-files-panel]')
435 .should('contain', 'foo').and('contain', 'bar');
437 // Check that only old collection action are available on context menu
438 cy.get('[data-cy=collection-panel-options-btn]').click();
439 cy.get('[data-cy=context-menu]')
440 .should('contain', 'Restore version')
441 .and('not.contain', 'Add to favorites');
442 cy.get('body').click(); // Collapse the menu avoiding details panel expansion
444 // Click on "head version" link, confirm that it's the latest version.
445 cy.get('[data-cy=collection-info-panel]').contains('head version').click();
446 cy.get('[data-cy=collection-info-panel]')
447 .should('not.contain', 'This is an old version');
448 cy.get('[data-cy=read-only-icon]').should('not.exist');
449 cy.get('[data-cy=collection-version-number]').should('contain', '2');
450 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
451 cy.get('[data-cy=collection-files-panel]').
452 should('not.contain', 'foo').and('contain', 'bar');
454 // Check that old collection action isn't available on context menu
455 cy.get('[data-cy=collection-panel-options-btn]').click()
456 cy.get('[data-cy=context-menu]').should('not.contain', 'Restore version')
457 cy.get('body').click(); // Collapse the menu avoiding details panel expansion
459 // Make another change, confirm new version.
460 cy.get('[data-cy=collection-panel-options-btn]').click();
461 cy.get('[data-cy=context-menu]').contains('Edit collection').click();
462 cy.get('[data-cy=form-dialog]')
463 .should('contain', 'Edit Collection')
466 cy.get('input').first().type(' renamed');
468 cy.get('[data-cy=form-submit-btn]').click();
469 cy.get('[data-cy=collection-info-panel]')
470 .should('not.contain', 'This is an old version');
471 cy.get('[data-cy=read-only-icon]').should('not.exist');
472 cy.get('[data-cy=collection-version-number]').should('contain', '3');
473 cy.get('[data-cy=collection-info-panel]').should('contain', colName + ' renamed');
474 cy.get('[data-cy=collection-files-panel]')
475 .should('not.contain', 'foo').and('contain', 'bar');
476 cy.get('[data-cy=collection-version-browser-select-3]')
477 .should('contain', '3').and('contain', '3 B');
479 // Check context menus on version browser
480 cy.get('[data-cy=collection-version-browser-select-3]').rightclick()
481 cy.get('[data-cy=context-menu]')
482 .should('contain', 'Add to favorites')
483 .and('contain', 'Make a copy')
484 .and('contain', 'Edit collection');
485 cy.get('body').click();
486 // (and now an old version...)
487 cy.get('[data-cy=collection-version-browser-select-1]').rightclick()
488 cy.get('[data-cy=context-menu]')
489 .should('not.contain', 'Add to favorites')
490 .and('contain', 'Make a copy')
491 .and('not.contain', 'Edit collection');
492 cy.get('body').click();
494 // Restore first version
495 cy.get('[data-cy=collection-version-browser]').within(() => {
496 cy.get('[data-cy=collection-version-browser-select-1]').click();
498 cy.get('[data-cy=collection-panel-options-btn]').click()
499 cy.get('[data-cy=context-menu]').contains('Restore version').click();
500 cy.get('[data-cy=confirmation-dialog]').should('contain', 'Restore version');
501 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
502 cy.get('[data-cy=collection-info-panel]')
503 .should('not.contain', 'This is an old version');
504 cy.get('[data-cy=collection-version-number]').should('contain', '4');
505 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
506 cy.get('[data-cy=collection-files-panel]')
507 .should('contain', 'foo').and('contain', 'bar');
511 it('creates new collection on home project', function () {
512 cy.loginAs(activeUser);
513 cy.doSearch(`${activeUser.user.uuid}`);
514 cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
515 cy.get('[data-cy=breadcrumb-last]').should('not.exist');
516 // Create new collection
517 cy.get('[data-cy=side-panel-button]').click();
518 cy.get('[data-cy=side-panel-new-collection]').click();
519 const collName = `Test collection (${Math.floor(999999 * Math.random())})`;
520 cy.get('[data-cy=form-dialog]')
521 .should('contain', 'New collection')
523 cy.get('[data-cy=parent-field]').within(() => {
524 cy.get('input').should('have.value', 'Home project');
526 cy.get('[data-cy=name-field]').within(() => {
527 cy.get('input').type(collName);
530 cy.get('[data-cy=form-submit-btn]').click();
531 // Confirm that the user was taken to the newly created thing
532 cy.get('[data-cy=form-dialog]').should('not.exist');
533 cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
534 cy.get('[data-cy=breadcrumb-last]').should('contain', collName);