fix LaunchButton tests

This commit is contained in:
Keith Grant
2020-03-31 10:09:33 -07:00
parent e60e6c7d08
commit 4f51c1d2c9
2 changed files with 23 additions and 16 deletions

View File

@@ -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() {

View File

@@ -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(
<LaunchButton resource={resource}>{children}</LaunchButton>