17337: Removed test restriction
[arvados-workbench2.git] / cypress / integration / collection.spec.js
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 describe('Collection panel tests', function () {
6     let activeUser;
7     let adminUser;
8
9     before(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;
17             }
18             );
19         cy.getUser('collectionuser1', 'Collection', 'User', false, true)
20             .as('activeUser').then(function () {
21                 activeUser = this.activeUser;
22             }
23             );
24     });
25
26     beforeEach(function () {
27         cy.clearCookies();
28         cy.clearLocalStorage();
29     });
30
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         })
37             .as('testCollection').then(function () {
38                 cy.loginAs(activeUser);
39                 cy.doSearch(`${this.testCollection.uuid}`);
40
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');
45                     });
46                     cy.get('[data-cy=property-field-value]').within(() => {
47                         cy.get('input').type('Magenta');
48                     });
49                     cy.root().submit();
50                 });
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')
58                     .then(function () {
59                         expect(this.collection.properties).to.deep.equal(
60                             { IDTAGCOLORS: 'IDVALCOLORS3' });
61                     });
62             });
63     });
64
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`
83                 })
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
91                         })
92                         cy.doSearch(`${this.testCollection.uuid}`);
93
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]')
104                             .click()
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');
119                                 });
120                                 cy.get('[data-cy=property-field-value]').within(() => {
121                                     cy.get('input').type('anotherValue');
122                                 });
123                                 cy.root().submit();
124                             })
125                             cy.get('[data-cy=collection-properties-panel]')
126                                 .should('contain', 'anotherKey')
127                                 .and('contain', 'anotherValue')
128                         } else {
129                             // Properties form shouldn't be displayed.
130                             cy.get('[data-cy=resource-properties-form]').should('not.exist');
131                         }
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);
135                             if (isWritable) {
136                                 cy.get('[data-cy=upload-button]')
137                                     .should(`${isWritable ? '' : 'not.'}contain`, 'Upload data');
138                             }
139                         });
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]')
151                             .click()
152                         cy.get('[data-cy=context-menu]')
153                             .should('contain', 'Select all')
154                             .click()
155                         cy.get('[data-cy=collection-files-panel-options-btn]')
156                             .click()
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')
163                             .click()
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
168                     })
169             })
170         })
171     })
172
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"
180         })
181             .as('testCollection').then(function () {
182                 cy.loginAs(activeUser);
183                 cy.doSearch(`${this.testCollection.uuid}`);
184
185                 const nameTransitions = [
186                     ['bar', '&'],
187                     ['&', 'foo'],
188                     ['foo', '&'],
189                     ['&', 'I ❤️ ⛵️'],
190                     ['I ❤️ ⛵️', '...']
191                 ];
192                 nameTransitions.forEach(([from, to]) => {
193                     cy.get('[data-cy=collection-files-panel]')
194                         .contains(`${from}`).rightclick();
195                     cy.get('[data-cy=context-menu]')
196                         .contains('Rename')
197                         .click();
198                     cy.get('[data-cy=form-dialog]')
199                         .should('contain', 'Rename')
200                         .within(() => {
201                             cy.get('input').type(`{selectall}{backspace}${to}`);
202                         });
203                     cy.get('[data-cy=form-submit-btn]').click();
204                     cy.get('[data-cy=collection-files-panel]')
205                         .should('not.contain', `${from}`)
206                         .and('contain', `${to}`);
207                 })
208             });
209     });
210
211     it('renames a file to a different directory', function () {
212         // Creates the collection using the admin token so we can set up
213         // a bogus manifest text without block signatures.
214         cy.createCollection(adminUser.token, {
215             name: `Test collection ${Math.floor(Math.random() * 999999)}`,
216             owner_uuid: activeUser.user.uuid,
217             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
218         })
219             .as('testCollection').then(function () {
220                 cy.loginAs(activeUser);
221                 cy.doSearch(`${this.testCollection.uuid}`);
222
223                 // Rename 'bar' to 'subdir/foo'
224                 cy.get('[data-cy=collection-files-panel]')
225                     .contains('bar').rightclick();
226                 cy.get('[data-cy=context-menu]')
227                     .contains('Rename')
228                     .click();
229                 cy.get('[data-cy=form-dialog]')
230                     .should('contain', 'Rename')
231                     .within(() => {
232                         cy.get('input').type(`{selectall}{backspace}subdir/foo`);
233                     });
234                 cy.get('[data-cy=form-submit-btn]').click();
235                 cy.get('[data-cy=collection-files-panel]')
236                     .should('not.contain', 'bar')
237                     .and('contain', 'subdir');
238                 // Look for the "arrow icon" and expand the "subdir" directory.
239                 cy.get('[data-cy=virtual-file-tree] > div > i').click();
240                 // Rename 'subdir/foo' to 'baz'
241                 cy.get('[data-cy=collection-files-panel]')
242                     .contains('foo').rightclick();
243                 cy.get('[data-cy=context-menu]')
244                     .contains('Rename')
245                     .click();
246                 cy.get('[data-cy=form-dialog]')
247                     .should('contain', 'Rename')
248                     .within(() => {
249                         cy.get('input')
250                             .should('have.value', 'subdir/foo')
251                             .type(`{selectall}{backspace}baz`);
252                     });
253                 cy.get('[data-cy=form-submit-btn]').click();
254                 cy.get('[data-cy=collection-files-panel]')
255                     .should('contain', 'subdir') // empty dir kept
256                     .and('contain', 'baz');
257             });
258     });
259
260     it('tries to rename a file with illegal names', function () {
261         // Creates the collection using the admin token so we can set up
262         // a bogus manifest text without block signatures.
263         cy.createCollection(adminUser.token, {
264             name: `Test collection ${Math.floor(Math.random() * 999999)}`,
265             owner_uuid: activeUser.user.uuid,
266             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
267         })
268             .as('testCollection').then(function () {
269                 cy.loginAs(activeUser);
270                 cy.doSearch(`${this.testCollection.uuid}`);
271
272                 const illegalNamesFromUI = [
273                     ['.', "Name cannot be '.' or '..'"],
274                     ['..', "Name cannot be '.' or '..'"],
275                     ['', 'This field is required'],
276                     [' ', 'Leading/trailing whitespaces not allowed'],
277                     [' foo', 'Leading/trailing whitespaces not allowed'],
278                     ['foo ', 'Leading/trailing whitespaces not allowed'],
279                     ['//foo', 'Empty dir name not allowed']
280                 ]
281                 illegalNamesFromUI.forEach(([name, errMsg]) => {
282                     cy.get('[data-cy=collection-files-panel]')
283                         .contains('bar').rightclick();
284                     cy.get('[data-cy=context-menu]')
285                         .contains('Rename')
286                         .click();
287                     cy.get('[data-cy=form-dialog]')
288                         .should('contain', 'Rename')
289                         .within(() => {
290                             cy.get('input').type(`{selectall}{backspace}${name}`);
291                         });
292                     cy.get('[data-cy=form-dialog]')
293                         .should('contain', 'Rename')
294                         .within(() => {
295                             cy.contains(`${errMsg}`);
296                         });
297                     cy.get('[data-cy=form-cancel-btn]').click();
298                 })
299             });
300     });
301
302     it('can correctly display old versions', function () {
303         const colName = `Versioned Collection ${Math.floor(Math.random() * 999999)}`;
304         let colUuid = '';
305         let oldVersionUuid = '';
306         // Make sure no other collections with this name exist
307         cy.doRequest('GET', '/arvados/v1/collections', null, {
308             filters: `[["name", "=", "${colName}"]]`,
309             include_old_versions: true
310         })
311             .its('body.items').as('collections')
312             .then(function () {
313                 expect(this.collections).to.be.empty;
314             });
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: colName,
319             owner_uuid: activeUser.user.uuid,
320             preserve_version: true,
321             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
322         })
323             .as('originalVersion').then(function () {
324                 // Change the file name to create a new version.
325                 cy.updateCollection(adminUser.token, this.originalVersion.uuid, {
326                     manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo\n"
327                 })
328                 colUuid = this.originalVersion.uuid;
329             });
330         // Confirm that there are 2 versions of the collection
331         cy.doRequest('GET', '/arvados/v1/collections', null, {
332             filters: `[["name", "=", "${colName}"]]`,
333             include_old_versions: true
334         })
335             .its('body.items').as('collections')
336             .then(function () {
337                 expect(this.collections).to.have.lengthOf(2);
338                 this.collections.map(function (aCollection) {
339                     expect(aCollection.current_version_uuid).to.equal(colUuid);
340                     if (aCollection.uuid !== aCollection.current_version_uuid) {
341                         oldVersionUuid = aCollection.uuid;
342                     }
343                 });
344                 // Check the old version displays as what it is.
345                 cy.loginAs(activeUser)
346                 cy.doSearch(`${oldVersionUuid}`);
347
348                 cy.get('[data-cy=collection-info-panel]').should('contain', 'This is an old version');
349                 cy.get('[data-cy=read-only-icon]').should('exist');
350                 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
351                 cy.get('[data-cy=collection-files-panel]').should('contain', 'bar');
352             });
353     });
354
355     it('should display all filles within the collection even with the # sign within the file name', () => {
356         const colName = `Test Collection ${Math.floor(Math.random() * 999999)}`;
357
358         cy.createCollection(adminUser.token, {
359             name: colName,
360             owner_uuid: activeUser.user.uuid,
361             preserve_version: true,
362             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:#foo 0:3:bar\n"
363         })
364             .as('collection')
365             .then((collection) => {
366                 cy.loginAs(activeUser)
367                 cy.doSearch(`${collection.uuid}`);
368                 cy.get('[data-cy=collection-files-panel]').contains('#foo').closest('[data-cy=virtual-file-tree]').find('[type=checkbox]').click();
369                 cy.get('[data-cy=collection-files-panel-options-btn]').click();
370                 cy.get('[data-cy=context-menu]').contains('Remove selected').click();
371                 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
372                 cy.get('[data-cy=collection-files-panel]').contains('#foo').should('not.exist');
373
374                 cy.get('[data-cy=collection-files-panel]').contains('bar').rightclick();
375                 cy.get('[data-cy=context-menu]').contains('Rename').click();
376                 cy.get('input[name=path]').type('bar 123 321 bar');
377                 cy.get('[data-cy=form-submit-btn]').click();
378                 cy.get('[data-cy=collection-files-panel]').contains('barbar 123 321 bar').should('exist');
379             });
380     });
381
382     it('uses the collection version browser to view a previous version', function () {
383         const colName = `Test Collection ${Math.floor(Math.random() * 999999)}`;
384
385         // Creates the collection using the admin token so we can set up
386         // a bogus manifest text without block signatures.
387         cy.createCollection(adminUser.token, {
388             name: colName,
389             owner_uuid: activeUser.user.uuid,
390             preserve_version: true,
391             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo 0:3:bar\n"
392         })
393             .as('collection').then(function () {
394                 // Visit collection, check basic information
395                 cy.loginAs(activeUser)
396                 cy.doSearch(`${this.collection.uuid}`);
397
398                 cy.get('[data-cy=collection-info-panel]').should('not.contain', 'This is an old version');
399                 cy.get('[data-cy=read-only-icon]').should('not.exist');
400                 cy.get('[data-cy=collection-version-number]').should('contain', '1');
401                 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
402                 cy.get('[data-cy=collection-files-panel]').should('contain', 'foo').and('contain', 'bar');
403
404                 // Modify collection, expect version number change
405                 cy.get('[data-cy=collection-files-panel]').contains('foo').rightclick();
406                 cy.get('[data-cy=context-menu]').contains('Remove').click();
407                 cy.get('[data-cy=confirmation-dialog]').should('contain', 'Removing file');
408                 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
409                 cy.get('[data-cy=collection-version-number]').should('contain', '2');
410                 cy.get('[data-cy=collection-files-panel]').should('not.contain', 'foo').and('contain', 'bar');
411
412                 // Click on version number, check version browser. Click on past version.
413                 cy.get('[data-cy=collection-version-browser]').should('not.exist');
414                 cy.get('[data-cy=collection-version-number]').contains('2').click();
415                 cy.get('[data-cy=collection-version-browser]')
416                     .should('contain', 'Nr').and('contain', 'Size').and('contain', 'Date')
417                     .within(() => {
418                         // Version 1: 6 bytes in size
419                         cy.get('[data-cy=collection-version-browser-select-1]')
420                             .should('contain', '1').and('contain', '6 B');
421                         // Version 2: 3 bytes in size (one file removed)
422                         cy.get('[data-cy=collection-version-browser-select-2]')
423                             .should('contain', '2').and('contain', '3 B');
424                         cy.get('[data-cy=collection-version-browser-select-3]')
425                             .should('not.exist');
426                         cy.get('[data-cy=collection-version-browser-select-1]')
427                             .click();
428                     });
429                 cy.get('[data-cy=collection-info-panel]').should('contain', 'This is an old version');
430                 cy.get('[data-cy=read-only-icon]').should('exist');
431                 cy.get('[data-cy=collection-version-number]').should('contain', '1');
432                 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
433                 cy.get('[data-cy=collection-files-panel]')
434                     .should('contain', 'foo').and('contain', 'bar');
435
436                 // Check that only old collection action are available on context menu
437                 cy.get('[data-cy=collection-panel-options-btn]').click();
438                 cy.get('[data-cy=context-menu]')
439                     .should('contain', 'Restore version')
440                     .and('not.contain', 'Add to favorites');
441                 cy.get('body').click(); // Collapse the menu avoiding details panel expansion
442
443                 // Click on "head version" link, confirm that it's the latest version.
444                 cy.get('[data-cy=collection-info-panel]').contains('head version').click();
445                 cy.get('[data-cy=collection-info-panel]')
446                     .should('not.contain', 'This is an old version');
447                 cy.get('[data-cy=read-only-icon]').should('not.exist');
448                 cy.get('[data-cy=collection-version-number]').should('contain', '2');
449                 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
450                 cy.get('[data-cy=collection-files-panel]').
451                     should('not.contain', 'foo').and('contain', 'bar');
452
453                 // Check that old collection action isn't available on context menu
454                 cy.get('[data-cy=collection-panel-options-btn]').click()
455                 cy.get('[data-cy=context-menu]').should('not.contain', 'Restore version')
456                 cy.get('body').click(); // Collapse the menu avoiding details panel expansion
457
458                 // Make another change, confirm new version.
459                 cy.get('[data-cy=collection-panel-options-btn]').click();
460                 cy.get('[data-cy=context-menu]').contains('Edit collection').click();
461                 cy.get('[data-cy=form-dialog]')
462                     .should('contain', 'Edit Collection')
463                     .within(() => {
464                         // appends some text
465                         cy.get('input').first().type(' renamed');
466                     });
467                 cy.get('[data-cy=form-submit-btn]').click();
468                 cy.get('[data-cy=collection-info-panel]')
469                     .should('not.contain', 'This is an old version');
470                 cy.get('[data-cy=read-only-icon]').should('not.exist');
471                 cy.get('[data-cy=collection-version-number]').should('contain', '3');
472                 cy.get('[data-cy=collection-info-panel]').should('contain', colName + ' renamed');
473                 cy.get('[data-cy=collection-files-panel]')
474                     .should('not.contain', 'foo').and('contain', 'bar');
475                 cy.get('[data-cy=collection-version-browser-select-3]')
476                     .should('contain', '3').and('contain', '3 B');
477
478                 // Check context menus on version browser
479                 cy.get('[data-cy=collection-version-browser-select-3]').rightclick()
480                 cy.get('[data-cy=context-menu]')
481                     .should('contain', 'Add to favorites')
482                     .and('contain', 'Make a copy')
483                     .and('contain', 'Edit collection');
484                 cy.get('body').click();
485                 // (and now an old version...)
486                 cy.get('[data-cy=collection-version-browser-select-1]').rightclick()
487                 cy.get('[data-cy=context-menu]')
488                     .should('not.contain', 'Add to favorites')
489                     .and('contain', 'Make a copy')
490                     .and('not.contain', 'Edit collection');
491                 cy.get('body').click();
492
493                 // Restore first version
494                 cy.get('[data-cy=collection-version-browser]').within(() => {
495                     cy.get('[data-cy=collection-version-browser-select-1]').click();
496                 });
497                 cy.get('[data-cy=collection-panel-options-btn]').click()
498                 cy.get('[data-cy=context-menu]').contains('Restore version').click();
499                 cy.get('[data-cy=confirmation-dialog]').should('contain', 'Restore version');
500                 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
501                 cy.get('[data-cy=collection-info-panel]')
502                     .should('not.contain', 'This is an old version');
503                 cy.get('[data-cy=collection-version-number]').should('contain', '4');
504                 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
505                 cy.get('[data-cy=collection-files-panel]')
506                     .should('contain', 'foo').and('contain', 'bar');
507             });
508     });
509
510     it('creates new collection on home project', function () {
511         cy.loginAs(activeUser);
512         cy.doSearch(`${activeUser.user.uuid}`);
513         cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
514         cy.get('[data-cy=breadcrumb-last]').should('not.exist');
515         // Create new collection
516         cy.get('[data-cy=side-panel-button]').click();
517         cy.get('[data-cy=side-panel-new-collection]').click();
518         const collName = `Test collection (${Math.floor(999999 * Math.random())})`;
519         cy.get('[data-cy=form-dialog]')
520             .should('contain', 'New collection')
521             .within(() => {
522                 cy.get('[data-cy=parent-field]').within(() => {
523                     cy.get('input').should('have.value', 'Home project');
524                 })
525                 cy.get('[data-cy=name-field]').within(() => {
526                     cy.get('input').type(collName);
527                 })
528             })
529         cy.get('[data-cy=form-submit-btn]').click();
530         // Confirm that the user was taken to the newly created thing
531         cy.get('[data-cy=form-dialog]').should('not.exist');
532         cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
533         cy.get('[data-cy=breadcrumb-last]').should('contain', collName);
534     });
535 })