mirror of
https://github.com/ansible/awx.git
synced 2026-02-24 22:46:01 -03:30
add LaunchButton test to cover disabled launch button behavior
This commit is contained in:
@@ -99,6 +99,7 @@ function LaunchButton({ resource, i18n, children, history }) {
|
|||||||
history.push(`/jobs/${job.id}/output`);
|
history.push(`/jobs/${job.id}/output`);
|
||||||
} catch (launchError) {
|
} catch (launchError) {
|
||||||
setError(launchError);
|
setError(launchError);
|
||||||
|
} finally {
|
||||||
setIsLaunching(false);
|
setIsLaunching(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -151,6 +152,7 @@ function LaunchButton({ resource, i18n, children, history }) {
|
|||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError(err);
|
setError(err);
|
||||||
|
} finally {
|
||||||
setIsLaunching(false);
|
setIsLaunching(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -114,6 +114,49 @@ describe('LaunchButton', () => {
|
|||||||
expect(history.location.pathname).toEqual('/jobs/9000/output');
|
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(
|
||||||
|
<LaunchButton
|
||||||
|
resource={{
|
||||||
|
id: 1,
|
||||||
|
type: 'workflow_job_template',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{({ handleLaunch, isLaunching }) => (
|
||||||
|
<button type="submit" onClick={handleLaunch} disabled={isLaunching} />
|
||||||
|
)}
|
||||||
|
</LaunchButton>,
|
||||||
|
{
|
||||||
|
context: {
|
||||||
|
router: { history },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
const button = wrapper.find('button');
|
||||||
|
await act(() => button.prop('onClick')());
|
||||||
|
wrapper.update();
|
||||||
|
|
||||||
|
expect(wrapper.find('button').prop('disabled')).toEqual(true);
|
||||||
|
});
|
||||||
|
|
||||||
test('should relaunch job correctly', async () => {
|
test('should relaunch job correctly', async () => {
|
||||||
JobsAPI.readRelaunch.mockResolvedValue({
|
JobsAPI.readRelaunch.mockResolvedValue({
|
||||||
data: {
|
data: {
|
||||||
|
|||||||
Reference in New Issue
Block a user