From 4f51c1d2c9104a1038ec1260f8650f7a21626d7e Mon Sep 17 00:00:00 2001 From: Keith Grant Date: Tue, 31 Mar 2020 10:09:33 -0700 Subject: [PATCH] fix LaunchButton tests --- .../components/LaunchButton/LaunchButton.jsx | 29 +++++++++++-------- .../LaunchButton/LaunchButton.test.jsx | 10 ++++--- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/awx/ui_next/src/components/LaunchButton/LaunchButton.jsx b/awx/ui_next/src/components/LaunchButton/LaunchButton.jsx index e8c75c5057..878945f8d8 100644 --- a/awx/ui_next/src/components/LaunchButton/LaunchButton.jsx +++ b/awx/ui_next/src/components/LaunchButton/LaunchButton.jsx @@ -25,7 +25,8 @@ function canLaunchWithoutPrompt(launchData) { !launchData.ask_limit_on_launch && !launchData.ask_scm_branch_on_launch && !launchData.survey_enabled && - launchData.variables_needed_to_start.length === 0 + (!launchData.variables_needed_to_start || + launchData.variables_needed_to_start.length === 0) ); } @@ -83,18 +84,22 @@ class LaunchButton extends React.Component { } async launchWithParams(params) { - const { history, resource } = this.props; - const launchJob = - resource.type === 'workflow_job_template' - ? WorkflowJobTemplatesAPI.launch(resource.id, params) - : JobTemplatesAPI.launch(resource.id, params); + try { + const { history, resource } = this.props; + const jobPromise = + resource.type === 'workflow_job_template' + ? WorkflowJobTemplatesAPI.launch(resource.id, params) + : JobTemplatesAPI.launch(resource.id, params); - const { data: job } = await launchJob; - history.push( - `/${ - resource.type === 'workflow_job_template' ? 'jobs/workflow' : 'jobs' - }/${job.id}/output` - ); + const { data: job } = await jobPromise; + history.push( + `/${ + resource.type === 'workflow_job_template' ? 'jobs/workflow' : 'jobs' + }/${job.id}/output` + ); + } catch (launchError) { + this.setState({ launchError }); + } } async handleRelaunch() { diff --git a/awx/ui_next/src/components/LaunchButton/LaunchButton.test.jsx b/awx/ui_next/src/components/LaunchButton/LaunchButton.test.jsx index b9bd3f7e53..49ae7e16ac 100644 --- a/awx/ui_next/src/components/LaunchButton/LaunchButton.test.jsx +++ b/awx/ui_next/src/components/LaunchButton/LaunchButton.test.jsx @@ -60,9 +60,10 @@ describe('LaunchButton', () => { button.prop('onClick')(); expect(JobTemplatesAPI.readLaunch).toHaveBeenCalledWith(1); await sleep(0); - expect(JobTemplatesAPI.launch).toHaveBeenCalledWith(1); + expect(JobTemplatesAPI.launch).toHaveBeenCalledWith(1, null); expect(history.location.pathname).toEqual('/jobs/9000/output'); }); + test('should launch the correct job type', async () => { WorkflowJobTemplatesAPI.readLaunch.mockResolvedValue({ data: { @@ -72,7 +73,7 @@ describe('LaunchButton', () => { const history = createMemoryHistory({ initialEntries: ['/jobs/9000'], }); - JobTemplatesAPI.launch.mockResolvedValue({ + WorkflowJobTemplatesAPI.launch.mockResolvedValue({ data: { id: 9000, }, @@ -96,9 +97,10 @@ describe('LaunchButton', () => { button.prop('onClick')(); expect(WorkflowJobTemplatesAPI.readLaunch).toHaveBeenCalledWith(1); await sleep(0); - expect(WorkflowJobTemplatesAPI.launch).toHaveBeenCalledWith(1); - expect(history.location.pathname).toEqual('/jobs/9000'); + expect(WorkflowJobTemplatesAPI.launch).toHaveBeenCalledWith(1, null); + expect(history.location.pathname).toEqual('/jobs/workflow/9000/output'); }); + test('displays error modal after unsuccessful launch', async () => { const wrapper = mountWithContexts( {children}