mirror of
https://github.com/ansible/awx.git
synced 2026-05-23 08:37:48 -02:30
fix LaunchButton tests
This commit is contained in:
@@ -25,7 +25,8 @@ function canLaunchWithoutPrompt(launchData) {
|
|||||||
!launchData.ask_limit_on_launch &&
|
!launchData.ask_limit_on_launch &&
|
||||||
!launchData.ask_scm_branch_on_launch &&
|
!launchData.ask_scm_branch_on_launch &&
|
||||||
!launchData.survey_enabled &&
|
!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) {
|
async launchWithParams(params) {
|
||||||
const { history, resource } = this.props;
|
try {
|
||||||
const launchJob =
|
const { history, resource } = this.props;
|
||||||
resource.type === 'workflow_job_template'
|
const jobPromise =
|
||||||
? WorkflowJobTemplatesAPI.launch(resource.id, params)
|
resource.type === 'workflow_job_template'
|
||||||
: JobTemplatesAPI.launch(resource.id, params);
|
? WorkflowJobTemplatesAPI.launch(resource.id, params)
|
||||||
|
: JobTemplatesAPI.launch(resource.id, params);
|
||||||
|
|
||||||
const { data: job } = await launchJob;
|
const { data: job } = await jobPromise;
|
||||||
history.push(
|
history.push(
|
||||||
`/${
|
`/${
|
||||||
resource.type === 'workflow_job_template' ? 'jobs/workflow' : 'jobs'
|
resource.type === 'workflow_job_template' ? 'jobs/workflow' : 'jobs'
|
||||||
}/${job.id}/output`
|
}/${job.id}/output`
|
||||||
);
|
);
|
||||||
|
} catch (launchError) {
|
||||||
|
this.setState({ launchError });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleRelaunch() {
|
async handleRelaunch() {
|
||||||
|
|||||||
@@ -60,9 +60,10 @@ describe('LaunchButton', () => {
|
|||||||
button.prop('onClick')();
|
button.prop('onClick')();
|
||||||
expect(JobTemplatesAPI.readLaunch).toHaveBeenCalledWith(1);
|
expect(JobTemplatesAPI.readLaunch).toHaveBeenCalledWith(1);
|
||||||
await sleep(0);
|
await sleep(0);
|
||||||
expect(JobTemplatesAPI.launch).toHaveBeenCalledWith(1);
|
expect(JobTemplatesAPI.launch).toHaveBeenCalledWith(1, null);
|
||||||
expect(history.location.pathname).toEqual('/jobs/9000/output');
|
expect(history.location.pathname).toEqual('/jobs/9000/output');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should launch the correct job type', async () => {
|
test('should launch the correct job type', async () => {
|
||||||
WorkflowJobTemplatesAPI.readLaunch.mockResolvedValue({
|
WorkflowJobTemplatesAPI.readLaunch.mockResolvedValue({
|
||||||
data: {
|
data: {
|
||||||
@@ -72,7 +73,7 @@ describe('LaunchButton', () => {
|
|||||||
const history = createMemoryHistory({
|
const history = createMemoryHistory({
|
||||||
initialEntries: ['/jobs/9000'],
|
initialEntries: ['/jobs/9000'],
|
||||||
});
|
});
|
||||||
JobTemplatesAPI.launch.mockResolvedValue({
|
WorkflowJobTemplatesAPI.launch.mockResolvedValue({
|
||||||
data: {
|
data: {
|
||||||
id: 9000,
|
id: 9000,
|
||||||
},
|
},
|
||||||
@@ -96,9 +97,10 @@ describe('LaunchButton', () => {
|
|||||||
button.prop('onClick')();
|
button.prop('onClick')();
|
||||||
expect(WorkflowJobTemplatesAPI.readLaunch).toHaveBeenCalledWith(1);
|
expect(WorkflowJobTemplatesAPI.readLaunch).toHaveBeenCalledWith(1);
|
||||||
await sleep(0);
|
await sleep(0);
|
||||||
expect(WorkflowJobTemplatesAPI.launch).toHaveBeenCalledWith(1);
|
expect(WorkflowJobTemplatesAPI.launch).toHaveBeenCalledWith(1, null);
|
||||||
expect(history.location.pathname).toEqual('/jobs/9000');
|
expect(history.location.pathname).toEqual('/jobs/workflow/9000/output');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('displays error modal after unsuccessful launch', async () => {
|
test('displays error modal after unsuccessful launch', async () => {
|
||||||
const wrapper = mountWithContexts(
|
const wrapper = mountWithContexts(
|
||||||
<LaunchButton resource={resource}>{children}</LaunchButton>
|
<LaunchButton resource={resource}>{children}</LaunchButton>
|
||||||
|
|||||||
Reference in New Issue
Block a user