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 // Creates the collection using the admin token so we can set up
175 // a bogus manifest text without block signatures.
176 cy.createCollection(adminUser.token, {
177 name: `Test collection ${Math.floor(Math.random() * 999999)}`,
178 owner_uuid: activeUser.user.uuid,
179 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
181 .as('testCollection').then(function () {
182 cy.loginAs(activeUser);
183 cy.doSearch(`${this.testCollection.uuid}`);
185 const nameTransitions = [
189 ['&', 'I ❤️ ⛵️'],
192 ['#...', 'some name with whitespaces'],
193 ['some name with whitespaces', 'some name with whitespaces #2'],
194 ['some name with whitespaces #2', 'is this name legal? I hope it is'],
195 ['is this name legal? I hope it is', 'some_file.pdf#'],
196 ['some_file.pdf#', 'some_file.pdf?'],
197 ['some_file.pdf?', '?some_file.pdf']
199 nameTransitions.forEach(([from, to]) => {
200 cy.get('[data-cy=collection-files-panel]')
201 .contains(`${from}`).rightclick();
202 cy.get('[data-cy=context-menu]')
205 cy.get('[data-cy=form-dialog]')
206 .should('contain', 'Rename')
208 cy.get('input').type(`{selectall}{backspace}${to}`);
210 cy.get('[data-cy=form-submit-btn]').click();
211 cy.get('[data-cy=collection-files-panel]')
212 .should('not.contain', `${from}`)
213 .and('contain', `${to}`);
218 it('renames a file to a different directory', function () {
219 // Creates the collection using the admin token so we can set up
220 // a bogus manifest text without block signatures.
221 cy.createCollection(adminUser.token, {
222 name: `Test collection ${Math.floor(Math.random() * 999999)}`,
223 owner_uuid: activeUser.user.uuid,
224 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
226 .as('testCollection').then(function () {
227 cy.loginAs(activeUser);
228 cy.doSearch(`${this.testCollection.uuid}`);
230 // Rename 'bar' to 'subdir/foo'
231 cy.get('[data-cy=collection-files-panel]')
232 .contains('bar').rightclick();
233 cy.get('[data-cy=context-menu]')
236 cy.get('[data-cy=form-dialog]')
237 .should('contain', 'Rename')
239 cy.get('input').type(`{selectall}{backspace}subdir/foo`);
241 cy.get('[data-cy=form-submit-btn]').click();
242 cy.get('[data-cy=collection-files-panel]')
243 .should('not.contain', 'bar')
244 .and('contain', 'subdir');
245 // Look for the "arrow icon" and expand the "subdir" directory.
246 cy.get('[data-cy=virtual-file-tree] > div > i').click();
247 // Rename 'subdir/foo' to 'baz'
248 cy.get('[data-cy=collection-files-panel]')
249 .contains('foo').rightclick();
250 cy.get('[data-cy=context-menu]')
253 cy.get('[data-cy=form-dialog]')
254 .should('contain', 'Rename')
257 .should('have.value', 'subdir/foo')
258 .type(`{selectall}{backspace}baz`);
260 cy.get('[data-cy=form-submit-btn]').click();
261 cy.get('[data-cy=collection-files-panel]')
262 .should('contain', 'subdir') // empty dir kept
263 .and('contain', 'baz');
267 it('tries to rename a file with illegal names', function () {
268 // Creates the collection using the admin token so we can set up
269 // a bogus manifest text without block signatures.
270 cy.createCollection(adminUser.token, {
271 name: `Test collection ${Math.floor(Math.random() * 999999)}`,
272 owner_uuid: activeUser.user.uuid,
273 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
275 .as('testCollection').then(function () {
276 cy.loginAs(activeUser);
277 cy.doSearch(`${this.testCollection.uuid}`);
279 const illegalNamesFromUI = [
280 ['.', "Name cannot be '.' or '..'"],
281 ['..', "Name cannot be '.' or '..'"],
282 ['', 'This field is required'],
283 [' ', 'Leading/trailing whitespaces not allowed'],
284 [' foo', 'Leading/trailing whitespaces not allowed'],
285 ['foo ', 'Leading/trailing whitespaces not allowed'],
286 ['//foo', 'Empty dir name not allowed']
288 illegalNamesFromUI.forEach(([name, errMsg]) => {
289 cy.get('[data-cy=collection-files-panel]')
290 .contains('bar').rightclick();
291 cy.get('[data-cy=context-menu]')
294 cy.get('[data-cy=form-dialog]')
295 .should('contain', 'Rename')
297 cy.get('input').type(`{selectall}{backspace}${name}`);
299 cy.get('[data-cy=form-dialog]')
300 .should('contain', 'Rename')
302 cy.contains(`${errMsg}`);
304 cy.get('[data-cy=form-cancel-btn]').click();
309 it('can correctly display old versions', function () {
310 const colName = `Versioned Collection ${Math.floor(Math.random() * 999999)}`;
312 let oldVersionUuid = '';
313 // Make sure no other collections with this name exist
314 cy.doRequest('GET', '/arvados/v1/collections', null, {
315 filters: `[["name", "=", "${colName}"]]`,
316 include_old_versions: true
318 .its('body.items').as('collections')
320 expect(this.collections).to.be.empty;
322 // Creates the collection using the admin token so we can set up
323 // a bogus manifest text without block signatures.
324 cy.createCollection(adminUser.token, {
326 owner_uuid: activeUser.user.uuid,
327 preserve_version: true,
328 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
330 .as('originalVersion').then(function () {
331 // Change the file name to create a new version.
332 cy.updateCollection(adminUser.token, this.originalVersion.uuid, {
333 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo\n"
335 colUuid = this.originalVersion.uuid;
337 // Confirm that there are 2 versions of the collection
338 cy.doRequest('GET', '/arvados/v1/collections', null, {
339 filters: `[["name", "=", "${colName}"]]`,
340 include_old_versions: true
342 .its('body.items').as('collections')
344 expect(this.collections).to.have.lengthOf(2);
345 this.collections.map(function (aCollection) {
346 expect(aCollection.current_version_uuid).to.equal(colUuid);
347 if (aCollection.uuid !== aCollection.current_version_uuid) {
348 oldVersionUuid = aCollection.uuid;
351 // Check the old version displays as what it is.
352 cy.loginAs(activeUser)
353 cy.doSearch(`${oldVersionUuid}`);
355 cy.get('[data-cy=collection-info-panel]').should('contain', 'This is an old version');
356 cy.get('[data-cy=read-only-icon]').should('exist');
357 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
358 cy.get('[data-cy=collection-files-panel]').should('contain', 'bar');
362 it('should display all filles within the collection even with the # sign within the file name', () => {
363 const colName = `Test Collection ${Math.floor(Math.random() * 999999)}`;
365 cy.createCollection(adminUser.token, {
367 owner_uuid: activeUser.user.uuid,
368 preserve_version: true,
369 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:#foo 0:3:bar\n"
372 .then((collection) => {
373 cy.loginAs(activeUser)
374 cy.doSearch(`${collection.uuid}`);
375 cy.get('[data-cy=collection-files-panel]').contains('#foo').closest('[data-cy=virtual-file-tree]').find('[type=checkbox]').click();
376 cy.get('[data-cy=collection-files-panel-options-btn]').click();
377 cy.get('[data-cy=context-menu]').contains('Remove selected').click();
378 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
379 cy.get('[data-cy=collection-files-panel]').contains('#foo').should('not.exist');
381 cy.get('[data-cy=collection-files-panel]').contains('bar').rightclick();
382 cy.get('[data-cy=context-menu]').contains('Rename').click();
383 cy.get('input[name=path]').type('bar 123 321 bar');
384 cy.get('[data-cy=form-submit-btn]').click();
385 cy.get('[data-cy=collection-files-panel]').contains('barbar 123 321 bar').should('exist');
389 it('uses the collection version browser to view a previous version', function () {
390 const colName = `Test Collection ${Math.floor(Math.random() * 999999)}`;
392 // Creates the collection using the admin token so we can set up
393 // a bogus manifest text without block signatures.
394 cy.createCollection(adminUser.token, {
396 owner_uuid: activeUser.user.uuid,
397 preserve_version: true,
398 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo 0:3:bar\n"
400 .as('collection').then(function () {
401 // Visit collection, check basic information
402 cy.loginAs(activeUser)
403 cy.doSearch(`${this.collection.uuid}`);
405 cy.get('[data-cy=collection-info-panel]').should('not.contain', 'This is an old version');
406 cy.get('[data-cy=read-only-icon]').should('not.exist');
407 cy.get('[data-cy=collection-version-number]').should('contain', '1');
408 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
409 cy.get('[data-cy=collection-files-panel]').should('contain', 'foo').and('contain', 'bar');
411 // Modify collection, expect version number change
412 cy.get('[data-cy=collection-files-panel]').contains('foo').rightclick();
413 cy.get('[data-cy=context-menu]').contains('Remove').click();
414 cy.get('[data-cy=confirmation-dialog]').should('contain', 'Removing file');
415 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
416 cy.get('[data-cy=collection-version-number]').should('contain', '2');
417 cy.get('[data-cy=collection-files-panel]').should('not.contain', 'foo').and('contain', 'bar');
419 // Click on version number, check version browser. Click on past version.
420 cy.get('[data-cy=collection-version-browser]').should('not.exist');
421 cy.get('[data-cy=collection-version-number]').contains('2').click();
422 cy.get('[data-cy=collection-version-browser]')
423 .should('contain', 'Nr').and('contain', 'Size').and('contain', 'Date')
425 // Version 1: 6 bytes in size
426 cy.get('[data-cy=collection-version-browser-select-1]')
427 .should('contain', '1').and('contain', '6 B');
428 // Version 2: 3 bytes in size (one file removed)
429 cy.get('[data-cy=collection-version-browser-select-2]')
430 .should('contain', '2').and('contain', '3 B');
431 cy.get('[data-cy=collection-version-browser-select-3]')
432 .should('not.exist');
433 cy.get('[data-cy=collection-version-browser-select-1]')
436 cy.get('[data-cy=collection-info-panel]').should('contain', 'This is an old version');
437 cy.get('[data-cy=read-only-icon]').should('exist');
438 cy.get('[data-cy=collection-version-number]').should('contain', '1');
439 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
440 cy.get('[data-cy=collection-files-panel]')
441 .should('contain', 'foo').and('contain', 'bar');
443 // Check that only old collection action are available on context menu
444 cy.get('[data-cy=collection-panel-options-btn]').click();
445 cy.get('[data-cy=context-menu]')
446 .should('contain', 'Restore version')
447 .and('not.contain', 'Add to favorites');
448 cy.get('body').click(); // Collapse the menu avoiding details panel expansion
450 // Click on "head version" link, confirm that it's the latest version.
451 cy.get('[data-cy=collection-info-panel]').contains('head version').click();
452 cy.get('[data-cy=collection-info-panel]')
453 .should('not.contain', 'This is an old version');
454 cy.get('[data-cy=read-only-icon]').should('not.exist');
455 cy.get('[data-cy=collection-version-number]').should('contain', '2');
456 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
457 cy.get('[data-cy=collection-files-panel]').
458 should('not.contain', 'foo').and('contain', 'bar');
460 // Check that old collection action isn't available on context menu
461 cy.get('[data-cy=collection-panel-options-btn]').click()
462 cy.get('[data-cy=context-menu]').should('not.contain', 'Restore version')
463 cy.get('body').click(); // Collapse the menu avoiding details panel expansion
465 // Make another change, confirm new version.
466 cy.get('[data-cy=collection-panel-options-btn]').click();
467 cy.get('[data-cy=context-menu]').contains('Edit collection').click();
468 cy.get('[data-cy=form-dialog]')
469 .should('contain', 'Edit Collection')
472 cy.get('input').first().type(' renamed');
474 cy.get('[data-cy=form-submit-btn]').click();
475 cy.get('[data-cy=collection-info-panel]')
476 .should('not.contain', 'This is an old version');
477 cy.get('[data-cy=read-only-icon]').should('not.exist');
478 cy.get('[data-cy=collection-version-number]').should('contain', '3');
479 cy.get('[data-cy=collection-info-panel]').should('contain', colName + ' renamed');
480 cy.get('[data-cy=collection-files-panel]')
481 .should('not.contain', 'foo').and('contain', 'bar');
482 cy.get('[data-cy=collection-version-browser-select-3]')
483 .should('contain', '3').and('contain', '3 B');
485 // Check context menus on version browser
486 cy.get('[data-cy=collection-version-browser-select-3]').rightclick()
487 cy.get('[data-cy=context-menu]')
488 .should('contain', 'Add to favorites')
489 .and('contain', 'Make a copy')
490 .and('contain', 'Edit collection');
491 cy.get('body').click();
492 // (and now an old version...)
493 cy.get('[data-cy=collection-version-browser-select-1]').rightclick()
494 cy.get('[data-cy=context-menu]')
495 .should('not.contain', 'Add to favorites')
496 .and('contain', 'Make a copy')
497 .and('not.contain', 'Edit collection');
498 cy.get('body').click();
500 // Restore first version
501 cy.get('[data-cy=collection-version-browser]').within(() => {
502 cy.get('[data-cy=collection-version-browser-select-1]').click();
504 cy.get('[data-cy=collection-panel-options-btn]').click()
505 cy.get('[data-cy=context-menu]').contains('Restore version').click();
506 cy.get('[data-cy=confirmation-dialog]').should('contain', 'Restore version');
507 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
508 cy.get('[data-cy=collection-info-panel]')
509 .should('not.contain', 'This is an old version');
510 cy.get('[data-cy=collection-version-number]').should('contain', '4');
511 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
512 cy.get('[data-cy=collection-files-panel]')
513 .should('contain', 'foo').and('contain', 'bar');
517 it('creates new collection on home project', function () {
518 cy.loginAs(activeUser);
519 cy.doSearch(`${activeUser.user.uuid}`);
520 cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
521 cy.get('[data-cy=breadcrumb-last]').should('not.exist');
522 // Create new collection
523 cy.get('[data-cy=side-panel-button]').click();
524 cy.get('[data-cy=side-panel-new-collection]').click();
525 const collName = `Test collection (${Math.floor(999999 * Math.random())})`;
526 cy.get('[data-cy=form-dialog]')
527 .should('contain', 'New collection')
529 cy.get('[data-cy=parent-field]').within(() => {
530 cy.get('input').should('have.value', 'Home project');
532 cy.get('[data-cy=name-field]').within(() => {
533 cy.get('input').type(collName);
536 cy.get('[data-cy=form-submit-btn]').click();
537 // Confirm that the user was taken to the newly created thing
538 cy.get('[data-cy=form-dialog]').should('not.exist');
539 cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
540 cy.get('[data-cy=breadcrumb-last]').should('contain', collName);