1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 describe('Collection panel tests', 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;
19 cy.getUser('collectionuser1', 'Collection', 'User', false, true)
20 .as('activeUser').then(function() {
21 activeUser = this.activeUser;
26 beforeEach(function() {
28 cy.clearLocalStorage();
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
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 .and('not.contain', 'This is an old version');
59 // Check for the read-only icon
60 cy.get('[data-cy=read-only-icon]').should(`${isWritable ? 'not.' : ''}exist`);
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]')
65 cy.get('[data-cy=context-menu]')
66 .should('contain', 'Add to favorites')
67 .and(`${isWritable ? '' : 'not.'}contain`, 'Edit collection');
68 cy.get('body').click(); // Collapse the menu avoiding details panel expansion
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 if (isWritable === true) {
75 // Check that properties can be added.
76 cy.get('[data-cy=collection-properties-form]').within(() => {
77 cy.get('[data-cy=property-field-key]').within(() => {
78 cy.get('input').type('anotherKey');
80 cy.get('[data-cy=property-field-value]').within(() => {
81 cy.get('input').type('anotherValue');
85 cy.get('[data-cy=collection-properties-panel]')
86 .should('contain', 'anotherKey')
87 .and('contain', 'anotherValue')
89 // Properties form shouldn't be displayed.
90 cy.get('[data-cy=collection-properties-form]').should('not.exist');
92 // Check that the file listing show both read & write operations
93 cy.get('[data-cy=collection-files-panel]').within(() => {
94 cy.root().should('contain', 'bar');
95 cy.get('[data-cy=upload-button]')
96 .should(`${isWritable ? '' : 'not.'}contain`, 'Upload data');
98 cy.get('[data-cy=collection-files-panel]')
99 .contains('bar').rightclick();
100 cy.get('[data-cy=context-menu]')
101 .should('contain', 'Download')
102 .and('contain', 'Open in new tab')
103 .and('contain', 'Copy to clipboard')
104 .and(`${isWritable ? '' : 'not.'}contain`, 'Rename')
105 .and(`${isWritable ? '' : 'not.'}contain`, 'Remove');
106 cy.get('body').click(); // Collapse the menu
107 // Hamburger 'more options' menu button
108 cy.get('[data-cy=collection-files-panel-options-btn]')
110 cy.get('[data-cy=context-menu]')
111 .should('contain', 'Select all')
113 cy.get('[data-cy=collection-files-panel-options-btn]')
115 cy.get('[data-cy=context-menu]')
116 // .should('contain', 'Download selected')
117 .should(`${isWritable ? '' : 'not.'}contain`, 'Remove selected')
118 cy.get('body').click(); // Collapse the menu
119 // File item 'more options' button
120 cy.get('[data-cy=file-item-options-btn')
122 cy.get('[data-cy=context-menu]')
123 .should('contain', 'Download')
124 .and(`${isWritable ? '' : 'not.'}contain`, 'Remove');
125 cy.get('body').click(); // Collapse the menu
131 it('renames a file', function() {
132 // Creates the collection using the admin token so we can set up
133 // a bogus manifest text without block signatures.
134 cy.createCollection(adminUser.token, {
135 name: `Test collection ${Math.floor(Math.random() * 999999)}`,
136 owner_uuid: activeUser.user.uuid,
137 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"})
138 .as('testCollection').then(function() {
139 cy.loginAs(activeUser);
140 cy.visit(`/collections/${this.testCollection.uuid}`);
141 cy.get('[data-cy=collection-files-panel]')
142 .contains('bar').rightclick();
143 cy.get('[data-cy=context-menu]')
146 cy.get('[data-cy=form-dialog]')
147 .should('contain', 'Rename')
149 cy.get('input').type('{backspace}{backspace}{backspace}foo');
151 cy.get('[data-cy=form-submit-btn]').click();
152 cy.get('[data-cy=collection-files-panel]')
153 .should('not.contain', 'bar')
154 .and('contain', 'foo');
158 it('tries to rename a file with an illegal name', function() {
159 // Creates the collection using the admin token so we can set up
160 // a bogus manifest text without block signatures.
161 cy.createCollection(adminUser.token, {
162 name: `Test collection ${Math.floor(Math.random() * 999999)}`,
163 owner_uuid: activeUser.user.uuid,
164 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"})
165 .as('testCollection').then(function() {
166 cy.loginAs(activeUser);
167 cy.visit(`/collections/${this.testCollection.uuid}`);
168 cy.get('[data-cy=collection-files-panel]')
169 .contains('bar').rightclick();
170 cy.get('[data-cy=context-menu]')
173 cy.get('[data-cy=form-dialog]')
174 .should('contain', 'Rename')
176 cy.get('input').type('{backspace}{backspace}{backspace}');
178 cy.get('[data-cy=form-submit-btn]').click();
179 cy.get('[data-cy=form-dialog]')
180 .should('contain', 'Rename')
182 cy.contains('Could not rename');
187 it('can correctly display old versions', function() {
188 const colName = `Versioned Collection ${Math.floor(Math.random() * 999999)}`;
190 let oldVersionUuid = '';
191 // Make sure no other collections with this name exist
192 cy.doRequest('GET', '/arvados/v1/collections', null, {
193 filters: `[["name", "=", "${colName}"]]`,
194 include_old_versions: true
196 .its('body.items').as('collections')
198 expect(this.collections).to.be.empty;
200 // Creates the collection using the admin token so we can set up
201 // a bogus manifest text without block signatures.
202 cy.createCollection(adminUser.token, {
204 owner_uuid: activeUser.user.uuid,
205 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"})
206 .as('originalVersion').then(function() {
207 // Change the file name to create a new version.
208 cy.updateCollection(adminUser.token, this.originalVersion.uuid, {
209 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo\n"
211 colUuid = this.originalVersion.uuid;
213 // Confirm that there are 2 versions of the collection
214 cy.doRequest('GET', '/arvados/v1/collections', null, {
215 filters: `[["name", "=", "${colName}"]]`,
216 include_old_versions: true
218 .its('body.items').as('collections')
220 expect(this.collections).to.have.lengthOf(2);
221 this.collections.map(function(aCollection) {
222 expect(aCollection.current_version_uuid).to.equal(colUuid);
223 if (aCollection.uuid !== aCollection.current_version_uuid) {
224 oldVersionUuid = aCollection.uuid;
227 // Check the old version displays as what it is.
228 cy.loginAs(activeUser)
229 cy.visit(`/collections/${oldVersionUuid}`);
230 cy.get('[data-cy=collection-info-panel]').should('contain', 'This is an old version');
231 cy.get('[data-cy=read-only-icon]').should('exist');
232 cy.get('[data-cy=collection-info-panel]').should('contain', colName);
233 cy.get('[data-cy=collection-files-panel]').should('contain', 'bar');