16118: Adds test checking writable/readonly collection UI changes.
[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             // Creates the collection using the admin token so we can set up
35             // a bogus manifest text without block signatures.
36             cy.createCollection(adminUser.token, {
37                 name: 'Test collection',
38                 owner_uuid: isWritable
39                     ? activeUser.user.uuid
40                     : adminUser.user.uuid,
41                 properties: {someKey: 'someValue'},
42                 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"})
43             .as('testCollection').then(function() {
44                 if (isWritable === false) {
45                     // Share collection as read-only
46                     cy.do_request('POST', '/arvados/v1/links', {
47                         link: JSON.stringify({
48                             name: 'can_read',
49                             link_class: 'permission',
50                             head_uuid: this.testCollection.uuid,
51                             tail_uuid: activeUser.user.uuid
52                         })
53                     }, null, adminUser.token, null);
54                 }
55                 cy.visit(`/collections/${this.testCollection.uuid}`);
56                 // Check that name & uuid are correct.
57                 cy.get('[data-cy=collection-info-panel]')
58                     .should('contain', this.testCollection.name)
59                     .and(`${isWritable ? 'not.': ''}contain`, 'Read-only')
60                     .and('contain', this.testCollection.uuid);
61                 // Check that both read and write operations are available on
62                 // the 'More options' menu.
63                 cy.get('[data-cy=collection-panel-options-btn]')
64                     .click()
65                 cy.get('[data-cy=context-menu]')
66                     .should('contain', 'Add to favorites')
67                     .and(`${isWritable ? '' : 'not.'}contain`, 'Edit collection')
68                     .type('{esc}'); // Collapse the options menu
69                 cy.get('[data-cy=collection-properties-panel]')
70                     .should('contain', 'someKey')
71                     .and('contain', 'someValue')
72                     .and('not.contain', 'anotherKey')
73                     .and('not.contain', 'anotherValue')
74                 // Check that properties can be added.
75                 if (isWritable === true) {
76                     cy.get('[data-cy=collection-properties-form]').within(() => {
77                         cy.get('[data-cy=property-field-key]').within(() => {
78                             cy.get('input').type('anotherKey');
79                         });
80                         cy.get('[data-cy=property-field-value]').within(() => {
81                             cy.get('input').type('anotherValue');
82                         });
83                         cy.root().submit();
84                     })
85                     cy.get('[data-cy=collection-properties-panel]')
86                         .should('contain', 'anotherKey')
87                         .and('contain', 'anotherValue')
88                 }
89                 // Check that the file listing show both read & write operations
90                 cy.get('[data-cy=collection-files-panel]').within(() => {
91                     cy.root().should('contain', 'bar');
92                     cy.get('[data-cy=upload-button]')
93                         .should(`${isWritable ? '' : 'not.'}contain`, 'Upload data');
94                 });
95                 // Hamburger 'more options' menu button
96                 cy.get('[data-cy=collection-files-panel-options-btn]')
97                     .click()
98                 cy.get('[data-cy=context-menu]')
99                     .should('contain', 'Select all')
100                     .click()
101                 cy.get('[data-cy=collection-files-panel-options-btn]')
102                     .click()
103                 cy.get('[data-cy=context-menu]')
104                     .should('contain', 'Download selected')
105                     .and(`${isWritable ? '' : 'not.'}contain`, 'Remove selected')
106                     .type('{esc}'); // Collapse the options menu
107                 // File item 'more options' button
108                 cy.get('[data-cy=file-item-options-btn')
109                     .click()
110                 cy.get('[data-cy=context-menu]')
111                     .should('contain', 'Download')
112                     .and(`${isWritable ? '' : 'not.'}contain`, 'Remove')
113                     .type('{esc}'); // Collapse
114             })
115         })
116     })
117 })