diff --git a/awx/ui_next/src/screens/Template/JobTemplateEdit/JobTemplateEdit.jsx b/awx/ui_next/src/screens/Template/JobTemplateEdit/JobTemplateEdit.jsx index 6f109604b5..fa0ad134cb 100644 --- a/awx/ui_next/src/screens/Template/JobTemplateEdit/JobTemplateEdit.jsx +++ b/awx/ui_next/src/screens/Template/JobTemplateEdit/JobTemplateEdit.jsx @@ -49,6 +49,7 @@ function JobTemplateEdit({ template }) { webhook_credential, webhook_key, webhook_url, + execution_environment, ...remainingValues } = values; @@ -56,11 +57,9 @@ function JobTemplateEdit({ template }) { setIsLoading(true); remainingValues.project = values.project.id; remainingValues.webhook_credential = webhook_credential?.id || null; + remainingValues.execution_environment = execution_environment?.id || null; try { - await JobTemplatesAPI.update(template.id, { - ...remainingValues, - execution_environment: values.execution_environment?.id, - }); + await JobTemplatesAPI.update(template.id, remainingValues); await Promise.all([ submitLabels(labels, template?.organization), submitInstanceGroups(instanceGroups, initialInstanceGroups), diff --git a/awx/ui_next/src/screens/Template/JobTemplateEdit/JobTemplateEdit.test.jsx b/awx/ui_next/src/screens/Template/JobTemplateEdit/JobTemplateEdit.test.jsx index 642c679969..0836d35bd5 100644 --- a/awx/ui_next/src/screens/Template/JobTemplateEdit/JobTemplateEdit.test.jsx +++ b/awx/ui_next/src/screens/Template/JobTemplateEdit/JobTemplateEdit.test.jsx @@ -13,6 +13,7 @@ import { LabelsAPI, ProjectsAPI, InventoriesAPI, + ExecutionEnvironmentsAPI, } from '../../../api'; import JobTemplateEdit from './JobTemplateEdit'; @@ -49,6 +50,12 @@ const mockJobTemplate = { scm_branch: '', skip_tags: '', summary_fields: { + execution_environment: { + id: 1, + name: 'Default EE', + description: '', + image: 'quay.io/ansible/awx-ee', + }, user_capabilities: { edit: true, }, @@ -81,6 +88,7 @@ const mockJobTemplate = { related: { webhook_receiver: '/api/v2/workflow_job_templates/57/gitlab/', }, + execution_environment: 1, }; const mockRelatedCredentials = { @@ -176,6 +184,15 @@ const mockInstanceGroups = [ }, ]; +const mockExecutionEnvironment = [ + { + id: 1, + name: 'Default EE', + description: '', + image: 'quay.io/ansible/awx-ee', + }, +]; + JobTemplatesAPI.readCredentials.mockResolvedValue({ data: mockRelatedCredentials, }); @@ -197,6 +214,10 @@ CredentialsAPI.read.mockResolvedValue({ }); CredentialTypesAPI.loadAllTypes.mockResolvedValue([]); +ExecutionEnvironmentsAPI.read.mockResolvedValue({ + data: mockExecutionEnvironment, +}); + describe('', () => { beforeEach(() => { LabelsAPI.read.mockResolvedValue({ data: { results: [] } }); @@ -266,6 +287,8 @@ describe('', () => { id: 1, organization: 1, }); + + wrapper.find('ExecutionEnvironmentLookup').invoke('onChange')(null); }); wrapper.update(); await act(async () => { @@ -277,6 +300,7 @@ describe('', () => { ...mockJobTemplate, project: mockJobTemplate.project, ...updatedTemplateData, + execution_environment: null, }; delete expected.summary_fields; delete expected.id; diff --git a/awx/ui_next/src/screens/Template/WorkflowJobTemplateEdit/WorkflowJobTemplateEdit.jsx b/awx/ui_next/src/screens/Template/WorkflowJobTemplateEdit/WorkflowJobTemplateEdit.jsx index cb963e634f..dd47118316 100644 --- a/awx/ui_next/src/screens/Template/WorkflowJobTemplateEdit/WorkflowJobTemplateEdit.jsx +++ b/awx/ui_next/src/screens/Template/WorkflowJobTemplateEdit/WorkflowJobTemplateEdit.jsx @@ -17,11 +17,13 @@ function WorkflowJobTemplateEdit({ template }) { organization, webhook_credential, webhook_key, + execution_environment, ...templatePayload } = values; templatePayload.inventory = inventory?.id || null; templatePayload.organization = organization?.id || null; templatePayload.webhook_credential = webhook_credential?.id || null; + templatePayload.execution_environment = execution_environment?.id || null; const formOrgId = organization?.id || inventory?.summary_fields?.organization.id || null; @@ -29,10 +31,7 @@ function WorkflowJobTemplateEdit({ template }) { await Promise.all( await submitLabels(labels, formOrgId, template.organization) ); - await WorkflowJobTemplatesAPI.update(template.id, { - ...templatePayload, - execution_environment: values.execution_environment?.id, - }); + await WorkflowJobTemplatesAPI.update(template.id, templatePayload); history.push(`/templates/workflow_job_template/${template.id}/details`); } catch (err) { setFormSubmitError(err); diff --git a/awx/ui_next/src/screens/Template/WorkflowJobTemplateEdit/WorkflowJobTemplateEdit.test.jsx b/awx/ui_next/src/screens/Template/WorkflowJobTemplateEdit/WorkflowJobTemplateEdit.test.jsx index 81ae43e817..3e5d0fb0e3 100644 --- a/awx/ui_next/src/screens/Template/WorkflowJobTemplateEdit/WorkflowJobTemplateEdit.test.jsx +++ b/awx/ui_next/src/screens/Template/WorkflowJobTemplateEdit/WorkflowJobTemplateEdit.test.jsx @@ -6,6 +6,7 @@ import { WorkflowJobTemplatesAPI, OrganizationsAPI, LabelsAPI, + ExecutionEnvironmentsAPI, } from '../../../api'; import { mountWithContexts } from '../../../../testUtils/enzymeHelpers'; import WorkflowJobTemplateEdit from './WorkflowJobTemplateEdit'; @@ -14,12 +15,19 @@ jest.mock('../../../api/models/WorkflowJobTemplates'); jest.mock('../../../api/models/Labels'); jest.mock('../../../api/models/Organizations'); jest.mock('../../../api/models/Inventories'); +jest.mock('../../../api/models/ExecutionEnvironments'); const mockTemplate = { id: 6, name: 'Foo', description: 'Foo description', summary_fields: { + execution_environment: { + id: 1, + name: 'Default EE', + description: '', + image: 'quay.io/ansible/awx-ee', + }, inventory: { id: 1, name: 'Inventory 1' }, organization: { id: 1, name: 'Organization 1' }, labels: { @@ -32,7 +40,18 @@ const mockTemplate = { scm_branch: 'devel', limit: '5000', variables: '---', + execution_environment: 1, }; + +const mockExecutionEnvironment = [ + { + id: 1, + name: 'Default EE', + description: '', + image: 'quay.io/ansible/awx-ee', + }, +]; + describe('', () => { let wrapper; let history; @@ -48,6 +67,9 @@ describe('', () => { }, }); OrganizationsAPI.read.mockResolvedValue({ results: [{ id: 1 }] }); + ExecutionEnvironmentsAPI.read.mockResolvedValue({ + data: mockExecutionEnvironment, + }); await act(async () => { history = createMemoryHistory({ @@ -100,6 +122,7 @@ describe('', () => { .find('LabelSelect') .find('SelectToggle') .simulate('click'); + wrapper.find('ExecutionEnvironmentLookup').invoke('onChange')(null); }); wrapper.update(); @@ -142,6 +165,7 @@ describe('', () => { ask_limit_on_launch: false, ask_scm_branch_on_launch: false, ask_variables_on_launch: false, + execution_environment: null, }); wrapper.update(); await expect(WorkflowJobTemplatesAPI.disassociateLabel).toBeCalledWith(6, {