From 46a7ca4dc36c0344ff74d4200e9a1d1ee3b321cd Mon Sep 17 00:00:00 2001 From: Alex Corey Date: Tue, 14 Jan 2020 12:01:02 -0500 Subject: [PATCH] Fixes navigation bug in InventoryAdd Adds SCM Branch field on JTForm --- .../Inventory/InventoryAdd/InventoryAdd.jsx | 4 +++- .../Inventory/InventoryAdd/InventoryAdd.test.jsx | 4 ++-- .../JobTemplateDetail/JobTemplateDetail.jsx | 6 ++++++ .../JobTemplateDetail/JobTemplateDetail.test.jsx | 15 +++++++++++++++ .../screens/Template/shared/JobTemplateForm.jsx | 12 ++++++++++++ .../Template/shared/JobTemplateForm.test.jsx | 3 +++ 6 files changed, 41 insertions(+), 3 deletions(-) diff --git a/awx/ui_next/src/screens/Inventory/InventoryAdd/InventoryAdd.jsx b/awx/ui_next/src/screens/Inventory/InventoryAdd/InventoryAdd.jsx index db7f5be27c..e01a336390 100644 --- a/awx/ui_next/src/screens/Inventory/InventoryAdd/InventoryAdd.jsx +++ b/awx/ui_next/src/screens/Inventory/InventoryAdd/InventoryAdd.jsx @@ -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`; diff --git a/awx/ui_next/src/screens/Inventory/InventoryAdd/InventoryAdd.test.jsx b/awx/ui_next/src/screens/Inventory/InventoryAdd/InventoryAdd.test.jsx index 1616d17499..26b0619a7d 100644 --- a/awx/ui_next/src/screens/Inventory/InventoryAdd/InventoryAdd.test.jsx +++ b/awx/ui_next/src/screens/Inventory/InventoryAdd/InventoryAdd.test.jsx @@ -41,8 +41,7 @@ describe('', () => { 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('', () => { IG.id ) ); + expect(history.location.pathname).toBe('/inventories/inventory/13/details'); }); test('handleCancel should return the user back to the inventories list', async () => { diff --git a/awx/ui_next/src/screens/Template/JobTemplateDetail/JobTemplateDetail.jsx b/awx/ui_next/src/screens/Template/JobTemplateDetail/JobTemplateDetail.jsx index 8783e93297..44390be54d 100644 --- a/awx/ui_next/src/screens/Template/JobTemplateDetail/JobTemplateDetail.jsx +++ b/awx/ui_next/src/screens/Template/JobTemplateDetail/JobTemplateDetail.jsx @@ -196,6 +196,12 @@ class JobTemplateDetail extends Component { ) : ( renderMissingDataDetail(i18n._(t`Project`)) )} + {template.scm_branch && ( + + )} diff --git a/awx/ui_next/src/screens/Template/JobTemplateDetail/JobTemplateDetail.test.jsx b/awx/ui_next/src/screens/Template/JobTemplateDetail/JobTemplateDetail.test.jsx index a06d1e8db5..7ae6b0319c 100644 --- a/awx/ui_next/src/screens/Template/JobTemplateDetail/JobTemplateDetail.test.jsx +++ b/awx/ui_next/src/screens/Template/JobTemplateDetail/JobTemplateDetail.test.jsx @@ -143,4 +143,19 @@ describe('', () => { template.summary_fields.credentials[0] ); }); + test('should render SCM_Branch', async () => { + const mockTemplate = { ...template }; + mockTemplate.scm_branch = 'Foo branch'; + + const wrapper = mountWithContexts( + + ); + await waitForElement( + wrapper, + 'JobTemplateDetail', + el => el.state('hasContentLoading') === false + ); + const SCMBranch = wrapper.find('Detail[label="SCM Branch"]'); + expect(SCMBranch.prop('value')).toBe('Foo branch'); + }); }); diff --git a/awx/ui_next/src/screens/Template/shared/JobTemplateForm.jsx b/awx/ui_next/src/screens/Template/shared/JobTemplateForm.jsx index b62f7603ec..74d5687f25 100644 --- a/awx/ui_next/src/screens/Template/shared/JobTemplateForm.jsx +++ b/awx/ui_next/src/screens/Template/shared/JobTemplateForm.jsx @@ -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 { /> )} + {project && project.allow_override && ( + + )} ', () => { project: 3, playbook: 'Baz', type: 'job_template', + scm_branch: 'Foo', summary_fields: { inventory: { id: 2, @@ -26,6 +27,7 @@ describe('', () => { project: { id: 3, name: 'qux', + allow_override: true, }, labels: { results: [{ name: 'Sushi', id: 1 }, { name: 'Major', id: 2 }] }, credentials: [ @@ -145,6 +147,7 @@ describe('', () => { 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' },