16118: Enhances tests. Adds custom commands for resource creation.
[arvados-workbench2.git] / cypress / integration / collection-panel.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('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
52                     })
53                     cy.visit(`/collections/${this.testCollection.uuid}`);
54                     // Check that name & uuid are correct.
55                     cy.get('[data-cy=collection-info-panel]')
56                         .should('contain', this.testCollection.name)
57                         .and(`${isWritable ? 'not.': ''}contain`, 'Read-only')
58                         .and('contain', this.testCollection.uuid);
59                     // Check that both read and write operations are available on
60                     // the 'More options' menu.
61                     cy.get('[data-cy=collection-panel-options-btn]')
62                         .click()
63                     cy.get('[data-cy=context-menu]')
64                         .should('contain', 'Add to favorites')
65                         .and(`${isWritable ? '' : 'not.'}contain`, 'Edit collection')
66                         .type('{esc}'); // Collapse the options menu
67                     cy.get('[data-cy=collection-properties-panel]')
68                         .should('contain', 'someKey')
69                         .and('contain', 'someValue')
70                         .and('not.contain', 'anotherKey')
71                         .and('not.contain', 'anotherValue')
72                     if (isWritable === true) {
73                         // Check that properties can be added.
74                         cy.get('[data-cy=collection-properties-form]').within(() => {
75                             cy.get('[data-cy=property-field-key]').within(() => {
76                                 cy.get('input').type('anotherKey');
77                             });
78                             cy.get('[data-cy=property-field-value]').within(() => {
79                                 cy.get('input').type('anotherValue');
80                             });
81                             cy.root().submit();
82                         })
83                         cy.get('[data-cy=collection-properties-panel]')
84                             .should('contain', 'anotherKey')
85                             .and('contain', 'anotherValue')
86                     } else {
87                         // Properties form shouldn't be displayed.
88                         cy.get('[data-cy=collection-properties-form]').should('not.exist');
89                     }
90                     // Check that the file listing show both read & write operations
91                     cy.get('[data-cy=collection-files-panel]').within(() => {
92                         cy.root().should('contain', 'bar');
93                         cy.get('[data-cy=upload-button]')
94                             .should(`${isWritable ? '' : 'not.'}contain`, 'Upload data');
95                     });
96                     // Hamburger 'more options' menu button
97                     cy.get('[data-cy=collection-files-panel-options-btn]')
98                         .click()
99                     cy.get('[data-cy=context-menu]')
100                         .should('contain', 'Select all')
101                         .click()
102                     cy.get('[data-cy=collection-files-panel-options-btn]')
103                         .click()
104                     cy.get('[data-cy=context-menu]')
105                         .should('contain', 'Download selected')
106                         .and(`${isWritable ? '' : 'not.'}contain`, 'Remove selected')
107                         .type('{esc}'); // Collapse the options menu
108                     // File item 'more options' button
109                     cy.get('[data-cy=file-item-options-btn')
110                         .click()
111                     cy.get('[data-cy=context-menu]')
112                         .should('contain', 'Download')
113                         .and(`${isWritable ? '' : 'not.'}contain`, 'Remove')
114                         .type('{esc}'); // Collapse
115                 })
116             })
117         })
118     })
119 })