17018: Adds integration tests exposing the bug.
[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('contain', this.testCollection.uuid);
58                     // Check for the read-only icon
59                     cy.get('[data-cy=read-only-icon]').should(`${isWritable ? 'not.' : ''}exist`);
60                     // Check that both read and write operations are available on
61                     // the 'More options' menu.
62                     cy.get('[data-cy=collection-panel-options-btn]')
63                         .click()
64                     cy.get('[data-cy=context-menu]')
65                         .should('contain', 'Add to favorites')
66                         .and(`${isWritable ? '' : 'not.'}contain`, 'Edit collection');
67                     cy.get('body').click(); // Collapse the menu avoiding details panel expansion
68                     cy.get('[data-cy=collection-properties-panel]')
69                         .should('contain', 'someKey')
70                         .and('contain', 'someValue')
71                         .and('not.contain', 'anotherKey')
72                         .and('not.contain', 'anotherValue')
73                     if (isWritable === true) {
74                         // Check that properties can be added.
75                         cy.get('[data-cy=collection-properties-form]').within(() => {
76                             cy.get('[data-cy=property-field-key]').within(() => {
77                                 cy.get('input').type('anotherKey');
78                             });
79                             cy.get('[data-cy=property-field-value]').within(() => {
80                                 cy.get('input').type('anotherValue');
81                             });
82                             cy.root().submit();
83                         })
84                         cy.get('[data-cy=collection-properties-panel]')
85                             .should('contain', 'anotherKey')
86                             .and('contain', 'anotherValue')
87                     } else {
88                         // Properties form shouldn't be displayed.
89                         cy.get('[data-cy=collection-properties-form]').should('not.exist');
90                     }
91                     // Check that the file listing show both read & write operations
92                     cy.get('[data-cy=collection-files-panel]').within(() => {
93                         cy.root().should('contain', 'bar');
94                         cy.get('[data-cy=upload-button]')
95                             .should(`${isWritable ? '' : 'not.'}contain`, 'Upload data');
96                     });
97                     cy.get('[data-cy=collection-files-panel]')
98                         .contains('bar').rightclick();
99                     cy.get('[data-cy=context-menu]')
100                         .should('contain', 'Download')
101                         .and('contain', 'Open in new tab')
102                         .and('contain', 'Copy to clipboard')
103                         .and(`${isWritable ? '' : 'not.'}contain`, 'Rename')
104                         .and(`${isWritable ? '' : 'not.'}contain`, 'Remove');
105                     cy.get('body').click(); // Collapse the menu
106                     // Hamburger 'more options' menu button
107                     cy.get('[data-cy=collection-files-panel-options-btn]')
108                         .click()
109                     cy.get('[data-cy=context-menu]')
110                         .should('contain', 'Select all')
111                         .click()
112                     cy.get('[data-cy=collection-files-panel-options-btn]')
113                         .click()
114                     cy.get('[data-cy=context-menu]')
115                         // .should('contain', 'Download selected')
116                         .should(`${isWritable ? '' : 'not.'}contain`, 'Remove selected')
117                     cy.get('body').click(); // Collapse the menu
118                     // File item 'more options' button
119                     cy.get('[data-cy=file-item-options-btn')
120                         .click()
121                     cy.get('[data-cy=context-menu]')
122                         .should('contain', 'Download')
123                         .and(`${isWritable ? '' : 'not.'}contain`, 'Remove');
124                     cy.get('body').click(); // Collapse the menu
125                 })
126             })
127         })
128     })
129 })