Fixes navigation bug in InventoryAdd Adds SCM Branch field on JTForm

This commit is contained in:
Alex Corey 2020-01-14 12:01:02 -05:00
parent 5e4c997c41
commit 46a7ca4dc3
6 changed files with 41 additions and 3 deletions

View File

@ -57,7 +57,9 @@ function InventoryAdd() {
);
await Promise.all(associatePromises);
}
const url = history.location.pathname.search('smart')
const url = history.location.pathname.startsWith(
'/inventories/smart_inventory'
)
? `/inventories/smart_inventory/${inventoryId}/details`
: `/inventories/inventory/${inventoryId}/details`;

View File

@ -41,8 +41,7 @@ describe('<InventoryAdd />', () => {
test('Initially renders successfully', () => {
expect(wrapper.length).toBe(1);
});
test('handleSubmit should call the api', async () => {
test('handleSubmit should call the api and redirect to details page', async () => {
const instanceGroups = [{ name: 'Bizz', id: 1 }, { name: 'Buzz', id: 2 }];
await waitForElement(wrapper, 'isLoading', el => el.length === 0);
@ -64,6 +63,7 @@ describe('<InventoryAdd />', () => {
IG.id
)
);
expect(history.location.pathname).toBe('/inventories/inventory/13/details');
});
test('handleCancel should return the user back to the inventories list', async () => {

View File

@ -196,6 +196,12 @@ class JobTemplateDetail extends Component {
) : (
renderMissingDataDetail(i18n._(t`Project`))
)}
{template.scm_branch && (
<Detail
label={i18n._(t`SCM Branch`)}
value={template.scm_branch}
/>
)}
<Detail label={i18n._(t`Playbook`)} value={playbook} />
<Detail label={i18n._(t`Forks`)} value={forks || '0'} />
<Detail label={i18n._(t`Limit`)} value={limit} />

View File

@ -143,4 +143,19 @@ describe('<JobTemplateDetail />', () => {
template.summary_fields.credentials[0]
);
});
test('should render SCM_Branch', async () => {
const mockTemplate = { ...template };
mockTemplate.scm_branch = 'Foo branch';
const wrapper = mountWithContexts(
<JobTemplateDetail template={mockTemplate} />
);
await waitForElement(
wrapper,
'JobTemplateDetail',
el => el.state('hasContentLoading') === false
);
const SCMBranch = wrapper.find('Detail[label="SCM Branch"]');
expect(SCMBranch.prop('value')).toBe('Foo branch');
});
});

View File

@ -124,6 +124,9 @@ class JobTemplateForm extends Component {
handleProjectUpdate(project) {
const { setFieldValue } = this.props;
setFieldValue('project', project.id);
if (!project.allow_override) {
setFieldValue('scm_branch', null);
}
this.setState({ project });
}
@ -269,6 +272,14 @@ class JobTemplateForm extends Component {
/>
)}
</Field>
{project && project.allow_override && (
<FormField
id="scm_branch"
name="scm_branch"
type="text"
label={i18n._(t`SCM Branch`)}
/>
)}
<Field
name="playbook"
validate={required(i18n._(t`Select a value for this field`), i18n)}
@ -583,6 +594,7 @@ const FormikApp = withFormik({
job_type: template.job_type || 'run',
inventory: template.inventory || '',
project: template.project || '',
scm_branch: template.scm_branch || '',
playbook: template.playbook || '',
labels: summary_fields.labels.results || [],
forks: template.forks || 0,

View File

@ -17,6 +17,7 @@ describe('<JobTemplateForm />', () => {
project: 3,
playbook: 'Baz',
type: 'job_template',
scm_branch: 'Foo',
summary_fields: {
inventory: {
id: 2,
@ -26,6 +27,7 @@ describe('<JobTemplateForm />', () => {
project: {
id: 3,
name: 'qux',
allow_override: true,
},
labels: { results: [{ name: 'Sushi', id: 1 }, { name: 'Major', id: 2 }] },
credentials: [
@ -145,6 +147,7 @@ describe('<JobTemplateForm />', () => {
wrapper.find('ProjectLookup').invoke('onChange')({
id: 4,
name: 'project',
allow_override: true,
});
wrapper.find('AnsibleSelect[name="playbook"]').simulate('change', {
target: { value: 'new baz type', name: 'playbook' },