From b1d166b83f589ce9d6fac88371c23c65dcc8e695 Mon Sep 17 00:00:00 2001 From: Yuan Gong Date: Wed, 20 Nov 2019 14:39:38 +0800 Subject: [PATCH] Trim pipeline upload url before sending to backend --- .../components/UploadPipelineDialog.test.tsx | 22 +++++++++++++++++++ .../src/components/UploadPipelineDialog.tsx | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/UploadPipelineDialog.test.tsx b/frontend/src/components/UploadPipelineDialog.test.tsx index a6725d60cd8..ea7a98077dd 100644 --- a/frontend/src/components/UploadPipelineDialog.test.tsx +++ b/frontend/src/components/UploadPipelineDialog.test.tsx @@ -81,6 +81,28 @@ describe('UploadPipelineDialog', () => { expect(spy).toHaveBeenLastCalledWith(true, 'test name', null, '', ImportMethod.LOCAL, ''); }); + it('calls close callback with trimmed file url and pipeline name when confirmed', () => { + const spy = jest.fn(); + tree = shallow(); + // Click 'Import by URL' + tree.find('#uploadFromUrlBtn').simulate('change'); + (tree.instance() as UploadPipelineDialog).handleChange('fileUrl')({ + target: { value: '\n https://www.google.com/test-file.txt ' }, + }); + (tree.instance() as UploadPipelineDialog).handleChange('uploadPipelineName')({ + target: { value: 'test name' }, + }); + tree.find('#confirmUploadBtn').simulate('click'); + expect(spy).toHaveBeenLastCalledWith( + true, + 'test name', + null, + 'https://www.google.com/test-file.txt', + ImportMethod.URL, + '', + ); + }); + it('trims file extension for pipeline name suggestion', () => { tree = shallow(); const file = { name: 'test_upload_file.tar.gz' }; diff --git a/frontend/src/components/UploadPipelineDialog.tsx b/frontend/src/components/UploadPipelineDialog.tsx index ddbd9ec8b6d..9fc2068163a 100644 --- a/frontend/src/components/UploadPipelineDialog.tsx +++ b/frontend/src/components/UploadPipelineDialog.tsx @@ -257,7 +257,7 @@ class UploadPipelineDialog extends React.Component< confirmed, this.state.uploadPipelineName, this.state.file, - this.state.fileUrl, + this.state.fileUrl.trim(), this.state.importMethod, this.state.uploadPipelineDescription, );