Merge pull request #9489 from nixocio/ui_issue_9487

Fix diassociate EE from JT and WFJT 

Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
softwarefactory-project-zuul[bot] 2021-03-09 15:25:54 +00:00 committed by GitHub
commit 2601631f28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 8 deletions

View File

@ -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),

View File

@ -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('<JobTemplateEdit />', () => {
beforeEach(() => {
LabelsAPI.read.mockResolvedValue({ data: { results: [] } });
@ -266,6 +287,8 @@ describe('<JobTemplateEdit />', () => {
id: 1,
organization: 1,
});
wrapper.find('ExecutionEnvironmentLookup').invoke('onChange')(null);
});
wrapper.update();
await act(async () => {
@ -277,6 +300,7 @@ describe('<JobTemplateEdit />', () => {
...mockJobTemplate,
project: mockJobTemplate.project,
...updatedTemplateData,
execution_environment: null,
};
delete expected.summary_fields;
delete expected.id;

View File

@ -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);

View File

@ -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('<WorkflowJobTemplateEdit/>', () => {
let wrapper;
let history;
@ -48,6 +67,9 @@ describe('<WorkflowJobTemplateEdit/>', () => {
},
});
OrganizationsAPI.read.mockResolvedValue({ results: [{ id: 1 }] });
ExecutionEnvironmentsAPI.read.mockResolvedValue({
data: mockExecutionEnvironment,
});
await act(async () => {
history = createMemoryHistory({
@ -100,6 +122,7 @@ describe('<WorkflowJobTemplateEdit/>', () => {
.find('LabelSelect')
.find('SelectToggle')
.simulate('click');
wrapper.find('ExecutionEnvironmentLookup').invoke('onChange')(null);
});
wrapper.update();
@ -142,6 +165,7 @@ describe('<WorkflowJobTemplateEdit/>', () => {
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, {