From: Lucas Di Pentima Date: Fri, 6 Nov 2020 16:01:44 +0000 (-0300) Subject: 15685: Merge branch 'master' into 15685-file-renaming-empty-name X-Git-Tag: 2.1.1~1^2~11 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/df5bb74b46652b2e0a73a0e9ef2c09a63314e409?hp=9ee35a64c605f116aec71f78c65b54730d6e1076 15685: Merge branch 'master' into 15685-file-renaming-empty-name Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- diff --git a/cypress/integration/collection-panel.spec.js b/cypress/integration/collection-panel.spec.js index 404d1c5b..466d7433 100644 --- a/cypress/integration/collection-panel.spec.js +++ b/cypress/integration/collection-panel.spec.js @@ -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 diff --git a/cypress/integration/login.spec.js b/cypress/integration/login.spec.js index 25c8cd4b..aeea01cd 100644 --- a/cypress/integration/login.spec.js +++ b/cypress/integration/login.spec.js @@ -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. diff --git a/src/common/webdav.ts b/src/common/webdav.ts index 17032768..b51cff30 100644 --- a/src/common/webdav.ts +++ b/src/common/webdav.ts @@ -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); }); diff --git a/src/store/collection-panel/collection-panel-files/collection-panel-files-actions.ts b/src/store/collection-panel/collection-panel-files/collection-panel-files-actions.ts index 704e2999..19f5a7ee 100644 --- a/src/store/collection-panel/collection-panel-files/collection-panel-files-actions.ts +++ b/src/store/collection-panel/collection-panel-files/collection-panel-files-actions.ts @@ -146,7 +146,7 @@ export const renameFile = (newName: string) => dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'File name changed.', hideDuration: 2000 })); } catch (e) { const errors: FormErrors = { - name: 'Could not rename the file' + name: `Could not rename the file: ${e.responseText}` }; dispatch(stopSubmit(RENAME_FILE_DIALOG, errors)); } diff --git a/src/views-components/rename-file-dialog/rename-file-dialog.tsx b/src/views-components/rename-file-dialog/rename-file-dialog.tsx index 1a806511..d05c110b 100644 --- a/src/views-components/rename-file-dialog/rename-file-dialog.tsx +++ b/src/views-components/rename-file-dialog/rename-file-dialog.tsx @@ -37,5 +37,5 @@ const RenameDialogFormFields = (props: WithDialogProps) => component={TextField} autoFocus={true} /> - + ;