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.only('shows collection by URL', function() {
32 cy.loginAs(activeUser);
33 [true, false].map(function(isWritable) {
34 cy.createGroup(adminUser.token, {
35 name: 'Shared project',
36 group_class: 'project',
37 }).as('sharedGroup').then(function() {
38 // Creates the collection using the admin token so we can set up
39 // a bogus manifest text without block signatures.
40 cy.createCollection(adminUser.token, {
41 name: 'Test collection',
42 owner_uuid: this.sharedGroup.uuid,
43 properties: {someKey: 'someValue'},
44 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"})
45 .as('testCollection').then(function() {
46 // Share the group with active user.
47 cy.createLink(adminUser.token, {
48 name: isWritable ? 'can_write' : 'can_read',
49 link_class: 'permission',
50 head_uuid: this.sharedGroup.uuid,
51 tail_uuid: activeUser.user.uuid
53 cy.visit(`/collections/${this.testCollection.uuid}`);
55 cy.get('[data-cy=linear-progress]').should('exist');
56 cy.get('[data-cy=linear-progress]').should('not.exist');
58 // Check that name & uuid are correct.
59 cy.get('[data-cy=collection-info-panel]')
60 .should('contain', this.testCollection.name)
61 .and('contain', this.testCollection.uuid)
62 .and('not.contain', 'This is an old version');
63 // Check for the read-only icon
64 cy.get('[data-cy=read-only-icon]').should(`${isWritable ? 'not.' : ''}exist`);
65 // Check that both read and write operations are available on
66 // the 'More options' menu.
67 cy.get('[data-cy=collection-panel-options-btn]')
69 cy.get('[data-cy=context-menu]')
70 .should('contain', 'Add to favorites')
71 .and(`${isWritable ? '' : 'not.'}contain`, 'Edit collection');
72 cy.get('body').click(); // Collapse the menu avoiding details panel expansion
73 cy.get('[data-cy=collection-properties-panel]')
74 .should('contain', 'someKey')
75 .and('contain', 'someValue')
76 .and('not.contain', 'anotherKey')
77 .and('not.contain', 'anotherValue')
78 if (isWritable === true) {
79 // Check that properties can be added.
80 cy.get('[data-cy=collection-properties-form]').within(() => {
81 cy.get('[data-cy=property-field-key]').within(() => {
82 cy.get('input').type('anotherKey');
84 cy.get('[data-cy=property-field-value]').within(() => {
85 cy.get('input').type('anotherValue');
89 cy.get('[data-cy=collection-properties-panel]')
90 .should('contain', 'anotherKey')
91 .and('contain', 'anotherValue')
93 // Properties form shouldn't be displayed.
94 cy.get('[data-cy=collection-properties-form]').should('not.exist');
96 // Check that the file listing show both read & write operations
97 cy.get('[data-cy=collection-files-panel]').within(() => {
98 cy.root().should('contain', 'bar');
100 cy.get('[data-cy=upload-button]')
101 .should(`${isWritable ? '' : 'not.'}contain`, 'Upload data');
104 cy.get('[data-cy=collection-files-panel]')
105 .contains('bar').rightclick();
106 cy.get('[data-cy=context-menu]')
107 .should('contain', 'Download')
108 .and('contain', 'Open in new tab')
109 .and('contain', 'Copy to clipboard')
110 .and(`${isWritable ? '' : 'not.'}contain`, 'Rename')
111 .and(`${isWritable ? '' : 'not.'}contain`, 'Remove');
112 cy.get('body').click(); // Collapse the menu
113 // Hamburger 'more options' menu button
114 cy.get('[data-cy=collection-files-panel-options-btn]')
116 cy.get('[data-cy=context-menu]')
117 .should('contain', 'Select all')
119 cy.get('[data-cy=collection-files-panel-options-btn]')
121 cy.get('[data-cy=context-menu]')
122 // .should('contain', 'Download selected')
123 .should(`${isWritable ? '' : 'not.'}contain`, 'Remove selected')
124 cy.get('body').click(); // Collapse the menu
125 // File item 'more options' button
126 cy.get('[data-cy=file-item-options-btn')
128 cy.get('[data-cy=context-menu]')
129 .should('contain', 'Download')
130 .and(`${isWritable ? '' : 'not.'}contain`, 'Remove');
131 cy.get('body').click(); // Collapse the menu
137 it('renames a file using valid names', function() {
138 // Creates the collection using the admin token so we can set up
139 // a bogus manifest text without block signatures.
140 cy.createCollection(adminUser.token, {
141 name: `Test collection ${Math.floor(Math.random() * 999999)}`,
142 owner_uuid: activeUser.user.uuid,
143 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"})
144 .as('testCollection').then(function() {
145 cy.loginAs(activeUser);
146 cy.visit(`/collections/${this.testCollection.uuid}`);
148 cy.get('[data-cy=linear-progress]').should('exist');
149 cy.get('[data-cy=linear-progress]').should('not.exist');
151 const nameTransitions = [
155 ['&', 'I ❤️ ⛵️'],
158 nameTransitions.forEach(([from, to]) => {
159 cy.get('[data-cy=collection-files-panel]')
160 .contains(`${from}`).rightclick();
161 cy.get('[data-cy=context-menu]')
164 cy.get('[data-cy=form-dialog]')
165 .should('contain', 'Rename')
167 cy.get('input').type(`{selectall}{backspace}${to}`);
169 cy.get('[data-cy=form-submit-btn]').click();
170 cy.get('[data-cy=collection-files-panel]')
171 .should('not.contain', `${from}`)
172 .and('contain', `${to}`);
177 it('renames a file to a different directory', function() {
178 // Creates the collection using the admin token so we can set up
179 // a bogus manifest text without block signatures.
180 cy.createCollection(adminUser.token, {
181 name: `Test collection ${Math.floor(Math.random() * 999999)}`,
182 owner_uuid: activeUser.user.uuid,
183 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"})
184 .as('testCollection').then(function() {
185 cy.loginAs(activeUser);
186 cy.visit(`/collections/${this.testCollection.uuid}`);
188 cy.get('[data-cy=linear-progress]').should('exist');
189 cy.get('[data-cy=linear-progress]').should('not.exist');
191 // Rename 'bar' to 'subdir/foo'
192 cy.get('[data-cy=collection-files-panel]')
193 .contains('bar').rightclick();
194 cy.get('[data-cy=context-menu]')
197 cy.get('[data-cy=form-dialog]')
198 .should('contain', 'Rename')
200 cy.get('input').type(`{selectall}{backspace}subdir/foo`);
202 cy.get('[data-cy=form-submit-btn]').click();
203 cy.get('[data-cy=collection-files-panel]')
204 .should('not.contain', 'bar')
205 .and('contain', 'subdir');
206 // Look for the "arrow icon" and expand the "subdir" directory.
207 cy.get('[data-cy=virtual-file-tree] > div > i').click();
208 // Rename 'subdir/foo' to 'baz'
209 cy.get('[data-cy=collection-files-panel]')
210 .contains('foo').rightclick();
211 cy.get('[data-cy=context-menu]')
214 cy.get('[data-cy=form-dialog]')
215 .should('contain', 'Rename')
218 .should('have.value', 'subdir/foo')
219 .type(`{selectall}{backspace}baz`);
221 cy.get('[data-cy=form-submit-btn]').click();
222 cy.get('[data-cy=collection-files-panel]')
223 .should('contain', 'subdir') // empty dir kept
224 .and('contain', 'baz');
228 it('tries to rename a file with illegal names', function() {
229 // Creates the collection using the admin token so we can set up
230 // a bogus manifest text without block signatures.
231 cy.createCollection(adminUser.token, {
232 name: `Test collection ${Math.floor(Math.random() * 999999)}`,
233 owner_uuid: activeUser.user.uuid,
234 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"})
235 .as('testCollection').then(function() {
236 cy.loginAs(activeUser);
237 cy.visit(`/collections/${this.testCollection.uuid}`);
239 cy.get('[data-cy=linear-progress]').should('exist');
240 cy.get('[data-cy=linear-progress]').should('not.exist');
242 const illegalNamesFromUI = [
243 ['.', "Name cannot be '.' or '..'"],
244 ['..', "Name cannot be '.' or '..'"],
245 ['', 'This field is required'],
246 [' ', 'Leading/trailing whitespaces not allowed'],
247 [' foo', 'Leading/trailing whitespaces not allowed'],
248 ['foo ', 'Leading/trailing whitespaces not allowed'],
249 ['//foo', 'Empty dir name not allowed']
251 illegalNamesFromUI.forEach(([name, errMsg]) => {
252 cy.get('[data-cy=collection-files-panel]')
253 .contains('bar').rightclick();
254 cy.get('[data-cy=context-menu]')
257 cy.get('[data-cy=form-dialog]')
258 .should('contain', 'Rename')
260 cy.get('input').type(`{selectall}{backspace}${name}`);
262 cy.get('[data-cy=form-dialog]')
263 .should('contain', 'Rename')
265 cy.contains(`${errMsg}`);
267 cy.get('[data-cy=form-cancel-btn]').click();
272 it('can correctly display old versions', function() {
273 const colName = `Versioned Collection ${Math.floor(Math.random() * 999999)}`;
275 let oldVersionUuid = '';
276 // Make sure no other collections with this name exist
277 cy.doRequest('GET', '/arvados/v1/collections', null, {
278 filters: `[["name", "=", "${colName}"]]`,
279 include_old_versions: true
281 .its('body.items').as('collections')
283 expect(this.collections).to.be.empty;
285 // Creates the collection using the admin token so we can set up
286 // a bogus manifest text without block signatures.
287 cy.createCollection(adminUser.token, {
289 owner_uuid: activeUser.user.uuid,
290 preserve_version: true,
291 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"})
292 .as('originalVersion').then(function() {
293 // Change the file name to create a new version.
294 cy.updateCollection(adminUser.token, this.originalVersion.uuid, {
295 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo\n"
297 colUuid = this.originalVersion.uuid;
299 // Confirm that there are 2 versions of the collection
300 cy.doRequest('GET', '/arvados/v1/collections', null, {
301 filters: `[["name", "=", "${colName}"]]`,
302 include_old_versions: true
304 .its('body.items').as('collections')
306 expect(this.collections).to.have.lengthOf(2);
307 this.collections.map(function(aCollection) {
308 expect(aCollection.current_version_uuid).to.equal(colUuid);
309 if (aCollection.uuid !== aCollection.current_version_uuid) {
310 oldVersionUuid = aCollection.uuid;
313 // Check the old version displays as what it is.
314 cy.loginAs(activeUser)
315 cy.visit(`/collections/${oldVersionUuid}`);
317 cy.get('[data-cy=linear-progress]').should('exist');
318 cy.get('[data-cy=linear-progress]').should('not.exist');
320 cy.get('[data-cy=collection-info-panel]').should('contain', 'This is an old version');
321 cy.get('[data-cy=read-only-icon]').should('exist');
322 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
323 cy.get('[data-cy=collection-files-panel]').should('contain', 'bar');
327 it('uses the collection version browser to view a previous version', function() {
328 const colName = `Test Collection ${Math.floor(Math.random() * 999999)}`;
330 // Creates the collection using the admin token so we can set up
331 // a bogus manifest text without block signatures.
332 cy.createCollection(adminUser.token, {
334 owner_uuid: activeUser.user.uuid,
335 preserve_version: true,
336 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo 0:3:bar\n"})
337 .as('collection').then(function() {
338 // Visit collection, check basic information
339 cy.loginAs(activeUser)
340 cy.visit(`/collections/${this.collection.uuid}`);
342 cy.get('[data-cy=linear-progress]').should('exist');
343 cy.get('[data-cy=linear-progress]').should('not.exist');
345 cy.get('[data-cy=collection-info-panel]').should('not.contain', 'This is an old version');
346 cy.get('[data-cy=read-only-icon]').should('not.exist');
347 cy.get('[data-cy=collection-version-number]').should('contain', '1');
348 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
349 cy.get('[data-cy=collection-files-panel]').should('contain', 'foo').and('contain', 'bar');
351 // Modify collection, expect version number change
352 cy.get('[data-cy=collection-files-panel]').contains('foo').rightclick();
353 cy.get('[data-cy=context-menu]').contains('Remove').click();
354 cy.get('[data-cy=confirmation-dialog]').should('contain', 'Removing file');
355 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
356 cy.get('[data-cy=collection-version-number]').should('contain', '2');
357 cy.get('[data-cy=collection-files-panel]').should('not.contain', 'foo').and('contain', 'bar');
359 // Click on version number, check version browser. Click on past version.
360 cy.get('[data-cy=collection-version-browser]').should('not.exist');
361 cy.get('[data-cy=collection-version-number]').contains('2').click();
362 cy.get('[data-cy=collection-version-browser]')
363 .should('contain', 'Nr').and('contain', 'Size').and('contain', 'Date')
365 // Version 1: 6 bytes in size
366 cy.get('[data-cy=collection-version-browser-select-1]')
367 .should('contain', '1').and('contain', '6 B');
368 // Version 2: 3 bytes in size (one file removed)
369 cy.get('[data-cy=collection-version-browser-select-2]')
370 .should('contain', '2').and('contain', '3 B');
371 cy.get('[data-cy=collection-version-browser-select-3]')
372 .should('not.exist');
373 cy.get('[data-cy=collection-version-browser-select-1]')
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-version-number]').should('contain', '1');
379 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
380 cy.get('[data-cy=collection-files-panel]')
381 .should('contain', 'foo').and('contain', 'bar');
383 // Check that only old collection action are available on context menu
384 cy.get('[data-cy=collection-panel-options-btn]').click();
385 cy.get('[data-cy=context-menu]')
386 .should('contain', 'Restore version')
387 .and('not.contain', 'Add to favorites');
388 cy.get('body').click(); // Collapse the menu avoiding details panel expansion
390 // Click on "head version" link, confirm that it's the latest version.
391 cy.get('[data-cy=collection-info-panel]').contains('head version').click();
392 cy.get('[data-cy=collection-info-panel]')
393 .should('not.contain', 'This is an old version');
394 cy.get('[data-cy=read-only-icon]').should('not.exist');
395 cy.get('[data-cy=collection-version-number]').should('contain', '2');
396 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
397 cy.get('[data-cy=collection-files-panel]').
398 should('not.contain', 'foo').and('contain', 'bar');
400 // Check that old collection action isn't available on context menu
401 cy.get('[data-cy=collection-panel-options-btn]').click()
402 cy.get('[data-cy=context-menu]').should('not.contain', 'Restore version')
403 cy.get('body').click(); // Collapse the menu avoiding details panel expansion
405 // Make another change, confirm new version.
406 cy.get('[data-cy=collection-panel-options-btn]').click();
407 cy.get('[data-cy=context-menu]').contains('Edit collection').click();
408 cy.get('[data-cy=form-dialog]')
409 .should('contain', 'Edit Collection')
412 cy.get('input').first().type(' renamed');
414 cy.get('[data-cy=form-submit-btn]').click();
415 cy.get('[data-cy=collection-info-panel]')
416 .should('not.contain', 'This is an old version');
417 cy.get('[data-cy=read-only-icon]').should('not.exist');
418 cy.get('[data-cy=collection-version-number]').should('contain', '3');
419 cy.get('[data-cy=collection-info-panel]').should('contain', colName + ' renamed');
420 cy.get('[data-cy=collection-files-panel]')
421 .should('not.contain', 'foo').and('contain', 'bar');
422 cy.get('[data-cy=collection-version-browser-select-3]')
423 .should('contain', '3').and('contain', '3 B');
425 // Check context menus on version browser
426 cy.get('[data-cy=collection-version-browser-select-3]').rightclick()
427 cy.get('[data-cy=context-menu]')
428 .should('contain', 'Add to favorites')
429 .and('contain', 'Make a copy')
430 .and('contain', 'Edit collection');
431 cy.get('body').click();
432 // (and now an old version...)
433 cy.get('[data-cy=collection-version-browser-select-1]').rightclick()
434 cy.get('[data-cy=context-menu]')
435 .should('not.contain', 'Add to favorites')
436 .and('contain', 'Make a copy')
437 .and('not.contain', 'Edit collection');
438 cy.get('body').click();
440 // Restore first version
441 cy.get('[data-cy=collection-version-browser]').within(() => {
442 cy.get('[data-cy=collection-version-browser-select-1]').click();
444 cy.get('[data-cy=collection-panel-options-btn]').click()
445 cy.get('[data-cy=context-menu]').contains('Restore version').click();
446 cy.get('[data-cy=confirmation-dialog]').should('contain', 'Restore version');
447 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
448 cy.get('[data-cy=collection-info-panel]')
449 .should('not.contain', 'This is an old version');
450 cy.get('[data-cy=collection-version-number]').should('contain', '4');
451 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
452 cy.get('[data-cy=collection-files-panel]')
453 .should('contain', 'foo').and('contain', 'bar');