15685: Merge branch 'master' into 15685-file-renaming-empty-name
[arvados-workbench2.git] / cypress / integration / collection-panel.spec.js
index 414d7e3ed40d12e91ba8155e888e4eab700a74ed..466d7433323a24c7a67e6856d791085667c4cf17 100644 (file)
@@ -21,12 +21,12 @@ describe('Collection panel tests', function() {
                 activeUser = this.activeUser;
             }
         );
-    })
+    });
 
     beforeEach(function() {
-        cy.clearCookies()
-        cy.clearLocalStorage()
-    })
+        cy.clearCookies();
+        cy.clearLocalStorage();
+    });
 
     it('shows collection by URL', function() {
         cy.loginAs(activeUser);
@@ -64,8 +64,8 @@ describe('Collection panel tests', function() {
                         .click()
                     cy.get('[data-cy=context-menu]')
                         .should('contain', 'Add to favorites')
-                        .and(`${isWritable ? '' : 'not.'}contain`, 'Edit collection')
-                        .type('{esc}'); // Collapse the options menu
+                        .and(`${isWritable ? '' : 'not.'}contain`, 'Edit collection');
+                    cy.get('body').click(); // Collapse the menu avoiding details panel expansion
                     cy.get('[data-cy=collection-properties-panel]')
                         .should('contain', 'someKey')
                         .and('contain', 'someValue')
@@ -95,6 +95,15 @@ describe('Collection panel tests', function() {
                         cy.get('[data-cy=upload-button]')
                             .should(`${isWritable ? '' : 'not.'}contain`, 'Upload data');
                     });
+                    cy.get('[data-cy=collection-files-panel]')
+                        .contains('bar').rightclick();
+                    cy.get('[data-cy=context-menu]')
+                        .should('contain', 'Download')
+                        .and('contain', 'Open in new tab')
+                        .and('contain', 'Copy to clipboard')
+                        .and(`${isWritable ? '' : 'not.'}contain`, 'Rename')
+                        .and(`${isWritable ? '' : 'not.'}contain`, 'Remove');
+                    cy.get('body').click(); // Collapse the menu
                     // Hamburger 'more options' menu button
                     cy.get('[data-cy=collection-files-panel-options-btn]')
                         .click()
@@ -106,21 +115,77 @@ describe('Collection panel tests', function() {
                     cy.get('[data-cy=context-menu]')
                         // .should('contain', 'Download selected')
                         .should(`${isWritable ? '' : 'not.'}contain`, 'Remove selected')
-                        .type('{esc}'); // Collapse the options menu
+                    cy.get('body').click(); // Collapse the menu
                     // File item 'more options' button
                     cy.get('[data-cy=file-item-options-btn')
                         .click()
                     cy.get('[data-cy=context-menu]')
                         .should('contain', 'Download')
-                        .and(`${isWritable ? '' : 'not.'}contain`, 'Remove')
-                        .type('{esc}'); // Collapse
+                        .and(`${isWritable ? '' : 'not.'}contain`, 'Remove');
+                    cy.get('body').click(); // Collapse the menu
                 })
             })
         })
     })
 
+    it('renames a file', function() {
+        // Creates the collection using the admin token so we can set up
+        // a bogus manifest text without block signatures.
+        cy.createCollection(adminUser.token, {
+            name: `Test collection ${Math.floor(Math.random() * 999999)}`,
+            owner_uuid: activeUser.user.uuid,
+            manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"})
+        .as('testCollection').then(function() {
+            cy.loginAs(activeUser);
+            cy.visit(`/collections/${this.testCollection.uuid}`);
+            cy.get('[data-cy=collection-files-panel]')
+                .contains('bar').rightclick();
+            cy.get('[data-cy=context-menu]')
+                .contains('Rename')
+                .click();
+            cy.get('[data-cy=form-dialog]')
+                .should('contain', 'Rename')
+                .within(() => {
+                    cy.get('input').type('{backspace}{backspace}{backspace}foo');
+                });
+            cy.get('[data-cy=form-submit-btn]').click();
+            cy.get('[data-cy=collection-files-panel]')
+                .should('not.contain', 'bar')
+                .and('contain', 'foo');
+        });
+    });
+
+    it('tries to rename a file with an illegal name', function() {
+        // Creates the collection using the admin token so we can set up
+        // a bogus manifest text without block signatures.
+        cy.createCollection(adminUser.token, {
+            name: `Test collection ${Math.floor(Math.random() * 999999)}`,
+            owner_uuid: activeUser.user.uuid,
+            manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"})
+        .as('testCollection').then(function() {
+            cy.loginAs(activeUser);
+            cy.visit(`/collections/${this.testCollection.uuid}`);
+            cy.get('[data-cy=collection-files-panel]')
+                .contains('bar').rightclick();
+            cy.get('[data-cy=context-menu]')
+                .contains('Rename')
+                .click();
+            cy.get('[data-cy=form-dialog]')
+                .should('contain', 'Rename')
+                .within(() => {
+                    cy.get('input').type('{backspace}{backspace}{backspace}');
+                });
+            cy.get('[data-cy=form-submit-btn]').click();
+            cy.get('[data-cy=form-dialog]')
+                .should('contain', 'Rename')
+                .within(() => {
+                    cy.contains('Could not rename');
+                });
+        });
+    });
+
     it('can correctly display old versions', function() {
-        const colName = `Versioned Collection ${Math.floor(Math.random() * Math.floor(999999))}`;
+        const colName = `Versioned Collection ${Math.floor(Math.random() * 999999)}`;
         let colUuid = '';
         let oldVersionUuid = '';
         // Make sure no other collections with this name exist