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"})
36 .as('testCollection').then(function() {
37 cy.loginAs(activeUser);
38 cy.doSearch(`${this.testCollection.uuid}`);
40 // Key: Color (IDTAGCOLORS) - Value: Magenta (IDVALCOLORS3)
41 cy.get('[data-cy=collection-properties-form]').within(() => {
42 cy.get('[data-cy=property-field-key]').within(() => {
43 cy.get('input').type('Color');
45 cy.get('[data-cy=property-field-value]').within(() => {
46 cy.get('input').type('Magenta');
50 // Confirm proper vocabulary labels are displayed on the UI.
51 cy.get('[data-cy=collection-properties-panel]')
52 .should('contain', 'Color')
53 .and('contain', 'Magenta');
54 // Confirm proper vocabulary IDs were saved on the backend.
55 cy.doRequest('GET', `/arvados/v1/collections/${this.testCollection.uuid}`)
56 .its('body').as('collection')
58 expect(this.collection.properties).to.deep.equal(
59 {IDTAGCOLORS: 'IDVALCOLORS3'});
64 it('shows collection by URL', function() {
65 cy.loginAs(activeUser);
66 [true, false].map(function(isWritable) {
67 cy.createGroup(adminUser.token, {
68 name: 'Shared project',
69 group_class: 'project',
70 }).as('sharedGroup').then(function() {
71 // Creates the collection using the admin token so we can set up
72 // a bogus manifest text without block signatures.
73 cy.createCollection(adminUser.token, {
74 name: 'Test collection',
75 owner_uuid: this.sharedGroup.uuid,
76 properties: {someKey: 'someValue'},
77 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"})
78 .as('testCollection').then(function() {
79 // Share the group with active user.
80 cy.createLink(adminUser.token, {
81 name: isWritable ? 'can_write' : 'can_read',
82 link_class: 'permission',
83 head_uuid: this.sharedGroup.uuid,
84 tail_uuid: activeUser.user.uuid
86 cy.doSearch(`${this.testCollection.uuid}`);
88 // Check that name & uuid are correct.
89 cy.get('[data-cy=collection-info-panel]')
90 .should('contain', this.testCollection.name)
91 .and('contain', this.testCollection.uuid)
92 .and('not.contain', 'This is an old version');
93 // Check for the read-only icon
94 cy.get('[data-cy=read-only-icon]').should(`${isWritable ? 'not.' : ''}exist`);
95 // Check that both read and write operations are available on
96 // the 'More options' menu.
97 cy.get('[data-cy=collection-panel-options-btn]')
99 cy.get('[data-cy=context-menu]')
100 .should('contain', 'Add to favorites')
101 .and(`${isWritable ? '' : 'not.'}contain`, 'Edit collection');
102 cy.get('body').click(); // Collapse the menu avoiding details panel expansion
103 cy.get('[data-cy=collection-properties-panel]')
104 .should('contain', 'someKey')
105 .and('contain', 'someValue')
106 .and('not.contain', 'anotherKey')
107 .and('not.contain', 'anotherValue')
108 if (isWritable === true) {
109 // Check that properties can be added.
110 cy.get('[data-cy=collection-properties-form]').within(() => {
111 cy.get('[data-cy=property-field-key]').within(() => {
112 cy.get('input').type('anotherKey');
114 cy.get('[data-cy=property-field-value]').within(() => {
115 cy.get('input').type('anotherValue');
119 cy.get('[data-cy=collection-properties-panel]')
120 .should('contain', 'anotherKey')
121 .and('contain', 'anotherValue')
123 // Properties form shouldn't be displayed.
124 cy.get('[data-cy=collection-properties-form]').should('not.exist');
126 // Check that the file listing show both read & write operations
127 cy.get('[data-cy=collection-files-panel]').within(() => {
128 cy.root().should('contain', 'bar');
130 cy.get('[data-cy=upload-button]')
131 .should(`${isWritable ? '' : 'not.'}contain`, 'Upload data');
134 cy.get('[data-cy=collection-files-panel]')
135 .contains('bar').rightclick();
136 cy.get('[data-cy=context-menu]')
137 .should('contain', 'Download')
138 .and('contain', 'Open in new tab')
139 .and('contain', 'Copy to clipboard')
140 .and(`${isWritable ? '' : 'not.'}contain`, 'Rename')
141 .and(`${isWritable ? '' : 'not.'}contain`, 'Remove');
142 cy.get('body').click(); // Collapse the menu
143 // Hamburger 'more options' menu button
144 cy.get('[data-cy=collection-files-panel-options-btn]')
146 cy.get('[data-cy=context-menu]')
147 .should('contain', 'Select all')
149 cy.get('[data-cy=collection-files-panel-options-btn]')
151 cy.get('[data-cy=context-menu]')
152 // .should('contain', 'Download selected')
153 .should(`${isWritable ? '' : 'not.'}contain`, 'Remove selected')
154 cy.get('body').click(); // Collapse the menu
155 // File item 'more options' button
156 cy.get('[data-cy=file-item-options-btn')
158 cy.get('[data-cy=context-menu]')
159 .should('contain', 'Download')
160 .and(`${isWritable ? '' : 'not.'}contain`, 'Remove');
161 cy.get('body').click(); // Collapse the menu
167 it('renames a file using valid names', function() {
168 // Creates the collection using the admin token so we can set up
169 // a bogus manifest text without block signatures.
170 cy.createCollection(adminUser.token, {
171 name: `Test collection ${Math.floor(Math.random() * 999999)}`,
172 owner_uuid: activeUser.user.uuid,
173 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"})
174 .as('testCollection').then(function() {
175 cy.loginAs(activeUser);
176 cy.doSearch(`${this.testCollection.uuid}`);
178 const nameTransitions = [
182 ['&', 'I ❤️ ⛵️'],
185 nameTransitions.forEach(([from, to]) => {
186 cy.get('[data-cy=collection-files-panel]')
187 .contains(`${from}`).rightclick();
188 cy.get('[data-cy=context-menu]')
191 cy.get('[data-cy=form-dialog]')
192 .should('contain', 'Rename')
194 cy.get('input').type(`{selectall}{backspace}${to}`);
196 cy.get('[data-cy=form-submit-btn]').click();
197 cy.get('[data-cy=collection-files-panel]')
198 .should('not.contain', `${from}`)
199 .and('contain', `${to}`);
204 it('renames a file to a different directory', function() {
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"})
211 .as('testCollection').then(function() {
212 cy.loginAs(activeUser);
213 cy.doSearch(`${this.testCollection.uuid}`);
215 // Rename 'bar' to 'subdir/foo'
216 cy.get('[data-cy=collection-files-panel]')
217 .contains('bar').rightclick();
218 cy.get('[data-cy=context-menu]')
221 cy.get('[data-cy=form-dialog]')
222 .should('contain', 'Rename')
224 cy.get('input').type(`{selectall}{backspace}subdir/foo`);
226 cy.get('[data-cy=form-submit-btn]').click();
227 cy.get('[data-cy=collection-files-panel]')
228 .should('not.contain', 'bar')
229 .and('contain', 'subdir');
230 // Look for the "arrow icon" and expand the "subdir" directory.
231 cy.get('[data-cy=virtual-file-tree] > div > i').click();
232 // Rename 'subdir/foo' to 'baz'
233 cy.get('[data-cy=collection-files-panel]')
234 .contains('foo').rightclick();
235 cy.get('[data-cy=context-menu]')
238 cy.get('[data-cy=form-dialog]')
239 .should('contain', 'Rename')
242 .should('have.value', 'subdir/foo')
243 .type(`{selectall}{backspace}baz`);
245 cy.get('[data-cy=form-submit-btn]').click();
246 cy.get('[data-cy=collection-files-panel]')
247 .should('contain', 'subdir') // empty dir kept
248 .and('contain', 'baz');
252 it('tries to rename a file with illegal names', function() {
253 // Creates the collection using the admin token so we can set up
254 // a bogus manifest text without block signatures.
255 cy.createCollection(adminUser.token, {
256 name: `Test collection ${Math.floor(Math.random() * 999999)}`,
257 owner_uuid: activeUser.user.uuid,
258 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"})
259 .as('testCollection').then(function() {
260 cy.loginAs(activeUser);
261 cy.doSearch(`${this.testCollection.uuid}`);
263 const illegalNamesFromUI = [
264 ['.', "Name cannot be '.' or '..'"],
265 ['..', "Name cannot be '.' or '..'"],
266 ['', 'This field is required'],
267 [' ', 'Leading/trailing whitespaces not allowed'],
268 [' foo', 'Leading/trailing whitespaces not allowed'],
269 ['foo ', 'Leading/trailing whitespaces not allowed'],
270 ['//foo', 'Empty dir name not allowed']
272 illegalNamesFromUI.forEach(([name, errMsg]) => {
273 cy.get('[data-cy=collection-files-panel]')
274 .contains('bar').rightclick();
275 cy.get('[data-cy=context-menu]')
278 cy.get('[data-cy=form-dialog]')
279 .should('contain', 'Rename')
281 cy.get('input').type(`{selectall}{backspace}${name}`);
283 cy.get('[data-cy=form-dialog]')
284 .should('contain', 'Rename')
286 cy.contains(`${errMsg}`);
288 cy.get('[data-cy=form-cancel-btn]').click();
293 it('can correctly display old versions', function() {
294 const colName = `Versioned Collection ${Math.floor(Math.random() * 999999)}`;
296 let oldVersionUuid = '';
297 // Make sure no other collections with this name exist
298 cy.doRequest('GET', '/arvados/v1/collections', null, {
299 filters: `[["name", "=", "${colName}"]]`,
300 include_old_versions: true
302 .its('body.items').as('collections')
304 expect(this.collections).to.be.empty;
306 // Creates the collection using the admin token so we can set up
307 // a bogus manifest text without block signatures.
308 cy.createCollection(adminUser.token, {
310 owner_uuid: activeUser.user.uuid,
311 preserve_version: true,
312 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"})
313 .as('originalVersion').then(function() {
314 // Change the file name to create a new version.
315 cy.updateCollection(adminUser.token, this.originalVersion.uuid, {
316 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo\n"
318 colUuid = this.originalVersion.uuid;
320 // Confirm that there are 2 versions of the collection
321 cy.doRequest('GET', '/arvados/v1/collections', null, {
322 filters: `[["name", "=", "${colName}"]]`,
323 include_old_versions: true
325 .its('body.items').as('collections')
327 expect(this.collections).to.have.lengthOf(2);
328 this.collections.map(function(aCollection) {
329 expect(aCollection.current_version_uuid).to.equal(colUuid);
330 if (aCollection.uuid !== aCollection.current_version_uuid) {
331 oldVersionUuid = aCollection.uuid;
334 // Check the old version displays as what it is.
335 cy.loginAs(activeUser)
336 cy.doSearch(`${oldVersionUuid}`);
338 cy.get('[data-cy=collection-info-panel]').should('contain', 'This is an old version');
339 cy.get('[data-cy=read-only-icon]').should('exist');
340 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
341 cy.get('[data-cy=collection-files-panel]').should('contain', 'bar');
345 it('uses the collection version browser to view a previous version', function() {
346 const colName = `Test Collection ${Math.floor(Math.random() * 999999)}`;
348 // Creates the collection using the admin token so we can set up
349 // a bogus manifest text without block signatures.
350 cy.createCollection(adminUser.token, {
352 owner_uuid: activeUser.user.uuid,
353 preserve_version: true,
354 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo 0:3:bar\n"})
355 .as('collection').then(function() {
356 // Visit collection, check basic information
357 cy.loginAs(activeUser)
358 cy.doSearch(`${this.collection.uuid}`);
360 cy.get('[data-cy=collection-info-panel]').should('not.contain', 'This is an old version');
361 cy.get('[data-cy=read-only-icon]').should('not.exist');
362 cy.get('[data-cy=collection-version-number]').should('contain', '1');
363 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
364 cy.get('[data-cy=collection-files-panel]').should('contain', 'foo').and('contain', 'bar');
366 // Modify collection, expect version number change
367 cy.get('[data-cy=collection-files-panel]').contains('foo').rightclick();
368 cy.get('[data-cy=context-menu]').contains('Remove').click();
369 cy.get('[data-cy=confirmation-dialog]').should('contain', 'Removing file');
370 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
371 cy.get('[data-cy=collection-version-number]').should('contain', '2');
372 cy.get('[data-cy=collection-files-panel]').should('not.contain', 'foo').and('contain', 'bar');
374 // Click on version number, check version browser. Click on past version.
375 cy.get('[data-cy=collection-version-browser]').should('not.exist');
376 cy.get('[data-cy=collection-version-number]').contains('2').click();
377 cy.get('[data-cy=collection-version-browser]')
378 .should('contain', 'Nr').and('contain', 'Size').and('contain', 'Date')
380 // Version 1: 6 bytes in size
381 cy.get('[data-cy=collection-version-browser-select-1]')
382 .should('contain', '1').and('contain', '6 B');
383 // Version 2: 3 bytes in size (one file removed)
384 cy.get('[data-cy=collection-version-browser-select-2]')
385 .should('contain', '2').and('contain', '3 B');
386 cy.get('[data-cy=collection-version-browser-select-3]')
387 .should('not.exist');
388 cy.get('[data-cy=collection-version-browser-select-1]')
391 cy.get('[data-cy=collection-info-panel]').should('contain', 'This is an old version');
392 cy.get('[data-cy=read-only-icon]').should('exist');
393 cy.get('[data-cy=collection-version-number]').should('contain', '1');
394 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
395 cy.get('[data-cy=collection-files-panel]')
396 .should('contain', 'foo').and('contain', 'bar');
398 // Check that only old collection action are available on context menu
399 cy.get('[data-cy=collection-panel-options-btn]').click();
400 cy.get('[data-cy=context-menu]')
401 .should('contain', 'Restore version')
402 .and('not.contain', 'Add to favorites');
403 cy.get('body').click(); // Collapse the menu avoiding details panel expansion
405 // Click on "head version" link, confirm that it's the latest version.
406 cy.get('[data-cy=collection-info-panel]').contains('head version').click();
407 cy.get('[data-cy=collection-info-panel]')
408 .should('not.contain', 'This is an old version');
409 cy.get('[data-cy=read-only-icon]').should('not.exist');
410 cy.get('[data-cy=collection-version-number]').should('contain', '2');
411 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
412 cy.get('[data-cy=collection-files-panel]').
413 should('not.contain', 'foo').and('contain', 'bar');
415 // Check that old collection action isn't available on context menu
416 cy.get('[data-cy=collection-panel-options-btn]').click()
417 cy.get('[data-cy=context-menu]').should('not.contain', 'Restore version')
418 cy.get('body').click(); // Collapse the menu avoiding details panel expansion
420 // Make another change, confirm new version.
421 cy.get('[data-cy=collection-panel-options-btn]').click();
422 cy.get('[data-cy=context-menu]').contains('Edit collection').click();
423 cy.get('[data-cy=form-dialog]')
424 .should('contain', 'Edit Collection')
427 cy.get('input').first().type(' renamed');
429 cy.get('[data-cy=form-submit-btn]').click();
430 cy.get('[data-cy=collection-info-panel]')
431 .should('not.contain', 'This is an old version');
432 cy.get('[data-cy=read-only-icon]').should('not.exist');
433 cy.get('[data-cy=collection-version-number]').should('contain', '3');
434 cy.get('[data-cy=collection-info-panel]').should('contain', colName + ' renamed');
435 cy.get('[data-cy=collection-files-panel]')
436 .should('not.contain', 'foo').and('contain', 'bar');
437 cy.get('[data-cy=collection-version-browser-select-3]')
438 .should('contain', '3').and('contain', '3 B');
440 // Check context menus on version browser
441 cy.get('[data-cy=collection-version-browser-select-3]').rightclick()
442 cy.get('[data-cy=context-menu]')
443 .should('contain', 'Add to favorites')
444 .and('contain', 'Make a copy')
445 .and('contain', 'Edit collection');
446 cy.get('body').click();
447 // (and now an old version...)
448 cy.get('[data-cy=collection-version-browser-select-1]').rightclick()
449 cy.get('[data-cy=context-menu]')
450 .should('not.contain', 'Add to favorites')
451 .and('contain', 'Make a copy')
452 .and('not.contain', 'Edit collection');
453 cy.get('body').click();
455 // Restore first version
456 cy.get('[data-cy=collection-version-browser]').within(() => {
457 cy.get('[data-cy=collection-version-browser-select-1]').click();
459 cy.get('[data-cy=collection-panel-options-btn]').click()
460 cy.get('[data-cy=context-menu]').contains('Restore version').click();
461 cy.get('[data-cy=confirmation-dialog]').should('contain', 'Restore version');
462 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
463 cy.get('[data-cy=collection-info-panel]')
464 .should('not.contain', 'This is an old version');
465 cy.get('[data-cy=collection-version-number]').should('contain', '4');
466 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
467 cy.get('[data-cy=collection-files-panel]')
468 .should('contain', 'foo').and('contain', 'bar');