From dff43e973e39f1c59782c2cc35455e4bc69a5cfc Mon Sep 17 00:00:00 2001 From: "Keith J. Grant" Date: Mon, 19 Apr 2021 09:29:40 -0700 Subject: [PATCH] add LaunchButton test to cover disabled launch button behavior --- .../components/LaunchButton/LaunchButton.jsx | 2 + .../LaunchButton/LaunchButton.test.jsx | 43 +++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/awx/ui_next/src/components/LaunchButton/LaunchButton.jsx b/awx/ui_next/src/components/LaunchButton/LaunchButton.jsx index 53f89b0063..ab292ee976 100644 --- a/awx/ui_next/src/components/LaunchButton/LaunchButton.jsx +++ b/awx/ui_next/src/components/LaunchButton/LaunchButton.jsx @@ -99,6 +99,7 @@ function LaunchButton({ resource, i18n, children, history }) { history.push(`/jobs/${job.id}/output`); } catch (launchError) { setError(launchError); + } finally { setIsLaunching(false); } }; @@ -151,6 +152,7 @@ function LaunchButton({ resource, i18n, children, history }) { } } catch (err) { setError(err); + } finally { setIsLaunching(false); } }; diff --git a/awx/ui_next/src/components/LaunchButton/LaunchButton.test.jsx b/awx/ui_next/src/components/LaunchButton/LaunchButton.test.jsx index 09af167081..9c2a3536f2 100644 --- a/awx/ui_next/src/components/LaunchButton/LaunchButton.test.jsx +++ b/awx/ui_next/src/components/LaunchButton/LaunchButton.test.jsx @@ -114,6 +114,49 @@ describe('LaunchButton', () => { expect(history.location.pathname).toEqual('/jobs/9000/output'); }); + test('should disable button to prevent duplicate clicks', async () => { + WorkflowJobTemplatesAPI.readLaunch.mockResolvedValue({ + data: { + can_start_without_user_input: true, + }, + }); + const history = createMemoryHistory({ + initialEntries: ['/jobs/9000'], + }); + WorkflowJobTemplatesAPI.launch.mockImplementation(async () => { + // return asynchronously so isLaunching isn't set back to false in the + // same tick + await sleep(10); + return { + data: { + id: 9000, + }, + }; + }); + const wrapper = mountWithContexts( + + {({ handleLaunch, isLaunching }) => ( +