17308: Adds project creation with properties integration test.
[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         .as('testCollection').then(function() {
37             cy.loginAs(activeUser);
38             cy.doSearch(`${this.testCollection.uuid}`);
39
40             // Key: Color (IDTAGCOLORS) - Value: Magenta (IDVALCOLORS3)
41             cy.get('[data-cy=resource-properties-form]').within(() => {
42                 cy.get('[data-cy=property-field-key]').within(() => {
43                     cy.get('input').type('Color');
44                 });
45                 cy.get('[data-cy=property-field-value]').within(() => {
46                     cy.get('input').type('Magenta');
47                 });
48                 cy.root().submit();
49             });
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')
57             .then(function() {
58                 expect(this.collection.properties).to.deep.equal(
59                     {IDTAGCOLORS: 'IDVALCOLORS3'});
60             });
61         });
62     });
63
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
85                     })
86                     cy.doSearch(`${this.testCollection.uuid}`);
87
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]')
98                         .click()
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=resource-properties-form]').within(() => {
111                             cy.get('[data-cy=property-field-key]').within(() => {
112                                 cy.get('input').type('anotherKey');
113                             });
114                             cy.get('[data-cy=property-field-value]').within(() => {
115                                 cy.get('input').type('anotherValue');
116                             });
117                             cy.root().submit();
118                         })
119                         cy.get('[data-cy=collection-properties-panel]')
120                             .should('contain', 'anotherKey')
121                             .and('contain', 'anotherValue')
122                     } else {
123                         // Properties form shouldn't be displayed.
124                         cy.get('[data-cy=resource-properties-form]').should('not.exist');
125                     }
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');
129                         if (isWritable) {
130                             cy.get('[data-cy=upload-button]')
131                                 .should(`${isWritable ? '' : 'not.'}contain`, 'Upload data');
132                         }
133                     });
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]')
145                         .click()
146                     cy.get('[data-cy=context-menu]')
147                         .should('contain', 'Select all')
148                         .click()
149                     cy.get('[data-cy=collection-files-panel-options-btn]')
150                         .click()
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')
157                         .click()
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
162                 })
163             })
164         })
165     })
166
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}`);
177
178             const nameTransitions = [
179                 ['bar', '&'],
180                 ['&', 'foo'],
181                 ['foo', '&'],
182                 ['&', 'I ❤️ ⛵️'],
183                 ['I ❤️ ⛵️', '...']
184             ];
185             nameTransitions.forEach(([from, to]) => {
186                 cy.get('[data-cy=collection-files-panel]')
187                     .contains(`${from}`).rightclick();
188                 cy.get('[data-cy=context-menu]')
189                     .contains('Rename')
190                     .click();
191                 cy.get('[data-cy=form-dialog]')
192                     .should('contain', 'Rename')
193                     .within(() => {
194                         cy.get('input').type(`{selectall}{backspace}${to}`);
195                     });
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}`);
200             })
201         });
202     });
203
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}`);
214
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]')
219                 .contains('Rename')
220                 .click();
221             cy.get('[data-cy=form-dialog]')
222                 .should('contain', 'Rename')
223                 .within(() => {
224                     cy.get('input').type(`{selectall}{backspace}subdir/foo`);
225                 });
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]')
236                 .contains('Rename')
237                 .click();
238             cy.get('[data-cy=form-dialog]')
239                 .should('contain', 'Rename')
240                 .within(() => {
241                     cy.get('input')
242                         .should('have.value', 'subdir/foo')
243                         .type(`{selectall}{backspace}baz`);
244                 });
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');
249         });
250     });
251
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}`);
262
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']
271             ]
272             illegalNamesFromUI.forEach(([name, errMsg]) => {
273                 cy.get('[data-cy=collection-files-panel]')
274                     .contains('bar').rightclick();
275                 cy.get('[data-cy=context-menu]')
276                     .contains('Rename')
277                     .click();
278                 cy.get('[data-cy=form-dialog]')
279                     .should('contain', 'Rename')
280                     .within(() => {
281                         cy.get('input').type(`{selectall}{backspace}${name}`);
282                     });
283                 cy.get('[data-cy=form-dialog]')
284                     .should('contain', 'Rename')
285                     .within(() => {
286                         cy.contains(`${errMsg}`);
287                     });
288                 cy.get('[data-cy=form-cancel-btn]').click();
289             })
290         });
291     });
292
293     it('can correctly display old versions', function() {
294         const colName = `Versioned Collection ${Math.floor(Math.random() * 999999)}`;
295         let colUuid = '';
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
301         })
302         .its('body.items').as('collections')
303         .then(function() {
304             expect(this.collections).to.be.empty;
305         });
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, {
309             name: colName,
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"
317             })
318             colUuid = this.originalVersion.uuid;
319         });
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
324         })
325         .its('body.items').as('collections')
326         .then(function() {
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;
332                 }
333             });
334             // Check the old version displays as what it is.
335             cy.loginAs(activeUser)
336             cy.doSearch(`${oldVersionUuid}`);
337
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');
342         });
343     });
344
345     it('uses the collection version browser to view a previous version', function() {
346         const colName = `Test Collection ${Math.floor(Math.random() * 999999)}`;
347
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, {
351             name: colName,
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}`);
359
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');
365
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');
373
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')
379                 .within(() => {
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]')
389                         .click();
390             });
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');
397
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
404
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');
414
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
419
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')
425                 .within(() => {
426                     // appends some text
427                     cy.get('input').first().type(' renamed');
428                 });
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');
439
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();
454
455             // Restore first version
456             cy.get('[data-cy=collection-version-browser]').within(() => {
457                 cy.get('[data-cy=collection-version-browser-select-1]').click();
458             });
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');
469         });
470     });
471
472     it('creates new collection on home project', function() {
473         cy.loginAs(activeUser);
474         cy.doSearch(`${activeUser.user.uuid}`);
475         cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
476         cy.get('[data-cy=breadcrumb-last]').should('not.exist');
477         // Create new collection
478         cy.get('[data-cy=side-panel-button]').click();
479         cy.get('[data-cy=side-panel-new-collection]').click();
480         const collName = `Test collection (${Math.floor(999999 * Math.random())})`;
481         cy.get('[data-cy=form-dialog]')
482             .should('contain', 'New collection')
483             .within(() => {
484                 cy.get('[data-cy=parent-field]').within(() => {
485                     cy.get('input').should('have.value', 'Home project');
486                 })
487                 cy.get('[data-cy=name-field]').within(() => {
488                     cy.get('input').type(collName);
489                 })
490             })
491         cy.get('[data-cy=form-submit-btn]').click();
492         // Confirm that the user was taken to the newly created thing
493         cy.get('[data-cy=form-dialog]').should('not.exist');
494         cy.get('[data-cy=breadcrumb-first]').should('contain', 'Projects');
495         cy.get('[data-cy=breadcrumb-last]').should('contain', collName);
496     });
497 })