15685: Merge branch 'master' into 15685-file-renaming-empty-name
authorLucas Di Pentima <lucas@di-pentima.com.ar>
Fri, 6 Nov 2020 16:01:44 +0000 (13:01 -0300)
committerLucas Di Pentima <lucas@di-pentima.com.ar>
Fri, 6 Nov 2020 16:01:44 +0000 (13:01 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas@di-pentima.com.ar>

cypress/integration/collection-panel.spec.js
cypress/integration/login.spec.js
src/common/webdav.ts
src/store/collection-panel/collection-panel-files/collection-panel-files-actions.ts
src/views-components/rename-file-dialog/rename-file-dialog.tsx

index 404d1c5b04f7ec2b2a17729908b0e6f0130dc60e..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);
@@ -128,8 +128,64 @@ describe('Collection panel tests', function() {
         })
     })
 
+    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
index 25c8cd4b8a4179cf9f60ad2e7905e8204fac4788..aeea01cdcfcb8d99fa5f6bac415ffec69dbc0175 100644 (file)
@@ -28,7 +28,7 @@ describe('Login tests', function() {
                 inactiveUser = this.inactiveUser;
             }
         );
-        randomUser.username = `randomuser${Math.floor(Math.random() * Math.floor(999999))}`;
+        randomUser.username = `randomuser${Math.floor(Math.random() * 999999)}`;
         randomUser.password = {
             crypt: 'zpAReoZzPnwmQ',
             clear: 'topsecret',
@@ -89,7 +89,7 @@ describe('Login tests', function() {
         cy.doRequest('PUT', `/arvados/v1/api_client_authorizations/${tokenUuid}`, {
             id: tokenUuid,
             api_client_authorization: JSON.stringify({
-                api_token: `randomToken${Math.floor(Math.random() * Math.floor(999999))}`
+                api_token: `randomToken${Math.floor(Math.random() * 999999)}`
             })
         }, null, activeUser.token, true);
         // Should log the user out.
index 17032768fd00436ef92cb4b63d156d0456ddc442..b51cff30703ea51b392b87a2998f9607f052c5a3 100644 (file)
@@ -85,14 +85,16 @@ export class WebDAV {
                 r.upload.addEventListener('progress', config.onUploadProgress);
             }
 
+            // This event gets triggered on *any* server response
             r.addEventListener('load', () => {
-                if (r.status === 404) {
+                if (r.status >= 400) {
                     return reject(r);
                 } else {
                     return resolve(r);
                 }
             });
 
+            // This event gets triggered on network errors
             r.addEventListener('error', () => {
                 return reject(r);
             });
index 704e299990a055742c5a19fdc5cba2e112bc2de0..19f5a7eeffcfe4b83d30e55b0b22a972c32bbeda 100644 (file)
@@ -146,7 +146,7 @@ export const renameFile = (newName: string) =>
                     dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'File name changed.', hideDuration: 2000 }));
                 } catch (e) {
                     const errors: FormErrors<RenameFileDialogData, string> = {
-                        name: 'Could not rename the file'
+                        name: `Could not rename the file: ${e.responseText}`
                     };
                     dispatch(stopSubmit(RENAME_FILE_DIALOG, errors));
                 }
index 1a806511523b6e0bc3fabeb1322a72ba615e3fcf..d05c110b7b3971e44e0aed7d700182e96d9b7fcb 100644 (file)
@@ -37,5 +37,5 @@ const RenameDialogFormFields = (props: WithDialogProps<RenameFileDialogData>) =>
         component={TextField}
         autoFocus={true}
     />
-    <WarningCollection text="Renaming a file will change content address." />
+    <WarningCollection text="Renaming a file will change the collection's content address." />
 </>;