diff --git a/awx/ui_next/src/screens/Template/WorkflowJobTemplateAdd/WorkflowJobTemplateAdd.test.jsx b/awx/ui_next/src/screens/Template/WorkflowJobTemplateAdd/WorkflowJobTemplateAdd.test.jsx index e60535e4da..c76b71a4f1 100644 --- a/awx/ui_next/src/screens/Template/WorkflowJobTemplateAdd/WorkflowJobTemplateAdd.test.jsx +++ b/awx/ui_next/src/screens/Template/WorkflowJobTemplateAdd/WorkflowJobTemplateAdd.test.jsx @@ -15,9 +15,11 @@ jest.mock('@api/models/Inventories'); describe('', () => { let wrapper; let history; + const handleSubmit = jest.fn(); + const handleCancel = jest.fn(); beforeEach(async () => { WorkflowJobTemplatesAPI.create.mockResolvedValue({ data: { id: 1 } }); - OrganizationsAPI.read.mockResolvedValue({ results: [{ id: 1 }] }); + OrganizationsAPI.read.mockResolvedValue({ data: { results: [{ id: 1 }] } }); LabelsAPI.read.mockResolvedValue({ data: { results: [ @@ -36,7 +38,12 @@ describe('', () => { wrapper = mountWithContexts( } + component={() => ( + + )} />, { context: { @@ -63,16 +70,49 @@ describe('', () => { test('calls workflowJobTemplatesAPI with correct information on submit', async () => { await act(async () => { - await wrapper.find('WorkflowJobTemplateForm').invoke('handleSubmit')({ - name: 'Alex', - labels: [{ name: 'Foo', id: 1 }, { name: 'bar', id: 2 }], - organizationId: 1, + wrapper.find('input#wfjt-name').simulate('change', { + target: { value: 'Alex', name: 'name' }, }); + + wrapper + .find('LabelSelect') + .find('SelectToggle') + .simulate('click'); }); - expect(WorkflowJobTemplatesAPI.create).toHaveBeenCalledWith({ + + wrapper.update(); + + act(() => { + wrapper + .find('SelectOption') + .find('button') + .at(2) + .prop('onClick')(); + }); + + wrapper.update(); + await act(async () => { + wrapper.find('form').simulate('submit'); + }); + await expect(WorkflowJobTemplatesAPI.create).toHaveBeenCalledWith({ name: 'Alex', + allow_simultaneous: false, + ask_inventory_on_launch: false, + ask_limit_on_launch: false, + ask_scm_branch_on_launch: false, + ask_variables_on_launch: false, + description: '', + extra_vars: '---', + inventory: undefined, + limit: '', + organization: undefined, + scm_branch: '', + webhook_credential: undefined, + webhook_service: '', + webhook_url: '', }); - expect(WorkflowJobTemplatesAPI.associateLabel).toHaveBeenCalledTimes(2); + + expect(WorkflowJobTemplatesAPI.associateLabel).toHaveBeenCalledTimes(1); }); test('handleCancel navigates the user to the /templates', async () => { @@ -95,10 +135,16 @@ describe('', () => { WorkflowJobTemplatesAPI.create.mockRejectedValue(error); await act(async () => { - wrapper.find('WorkflowJobTemplateForm').invoke('handleSubmit')({ - name: 'Foo', + wrapper.find('input#wfjt-name').simulate('change', { + target: { value: 'Alex', name: 'name' }, }); }); + + wrapper.update(); + await act(async () => { + wrapper.find('form').simulate('submit'); + }); + expect(WorkflowJobTemplatesAPI.create).toHaveBeenCalled(); wrapper.update(); expect(wrapper.find('WorkflowJobTemplateForm').prop('submitError')).toEqual( 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 7ec426e096..9acf279c1e 100644 --- a/awx/ui_next/src/screens/Template/WorkflowJobTemplateEdit/WorkflowJobTemplateEdit.test.jsx +++ b/awx/ui_next/src/screens/Template/WorkflowJobTemplateEdit/WorkflowJobTemplateEdit.test.jsx @@ -29,10 +29,15 @@ const mockTemplate = { describe('', () => { let wrapper; let history; + beforeEach(async () => { LabelsAPI.read.mockResolvedValue({ data: { - results: [{ name: 'Label 1', id: 1 }, { name: 'Label 2', id: 2 }], + results: [ + { name: 'Label 1', id: 1 }, + { name: 'Label 2', id: 2 }, + { name: 'Label 3', id: 3 }, + ], }, }); OrganizationsAPI.read.mockResolvedValue({ results: [{ id: 1 }] }); @@ -71,29 +76,67 @@ describe('', () => { }); test('api is called to properly to save the updated template.', async () => { - await act(async () => { - await wrapper.find('WorkflowJobTemplateForm').invoke('handleSubmit')({ - id: 6, - name: 'Alex', - description: 'Apollo and Athena', - inventory: 1, - organization: 1, - labels: [{ name: 'Label 2', id: 2 }, { name: 'Generated Label' }], - scm_branch: 'master', - limit: '5000', - variables: '---', + act(() => { + wrapper.find('input#wfjt-name').simulate('change', { + target: { value: 'Alex', name: 'name' }, }); + wrapper.find('input#wfjt-description').simulate('change', { + target: { value: 'Apollo and Athena', name: 'description' }, + }); + wrapper.find('input#wfjt-description').simulate('change', { + target: { value: 'master', name: 'scm_branch' }, + }); + wrapper.find('input#wfjt-description').simulate('change', { + target: { value: '5000', name: 'limit' }, + }); + wrapper + .find('LabelSelect') + .find('SelectToggle') + .simulate('click'); + }); + + wrapper.update(); + + act(() => { + wrapper + .find('SelectOption') + .find('button') + .at(2) + .prop('onClick')(); + }); + + wrapper.update(); + + act(() => + wrapper + .find('SelectOption') + .find('button') + .at(0) + .prop('onClick')() + ); + + wrapper.update(); + + await act(async () => { + wrapper.find('WorkflowJobTemplateForm').invoke('handleSubmit')(); }); expect(WorkflowJobTemplatesAPI.update).toHaveBeenCalledWith(6, { - id: 6, name: 'Alex', description: 'Apollo and Athena', inventory: 1, organization: 1, scm_branch: 'master', limit: '5000', - variables: '---', + extra_vars: '---', + webhook_credential: null, + webhook_url: '', + webhook_service: '', + allow_simultaneous: false, + ask_inventory_on_launch: false, + ask_limit_on_launch: false, + ask_scm_branch_on_launch: false, + ask_variables_on_launch: false, }); wrapper.update(); await expect(WorkflowJobTemplatesAPI.disassociateLabel).toBeCalledWith(6, { diff --git a/awx/ui_next/src/screens/Template/shared/WorkflowJobTemplateForm.test.jsx b/awx/ui_next/src/screens/Template/shared/WorkflowJobTemplateForm.test.jsx index 3bf15e6fd3..f123abe91b 100644 --- a/awx/ui_next/src/screens/Template/shared/WorkflowJobTemplateForm.test.jsx +++ b/awx/ui_next/src/screens/Template/shared/WorkflowJobTemplateForm.test.jsx @@ -74,7 +74,7 @@ describe('', () => { template={mockTemplate} handleCancel={handleCancel} handleSubmit={handleSubmit} - webhook_key="sdfghjklmnbvcdsew435678iokjhgfd" + webhookKey="sdfghjklmnbvcdsew435678iokjhgfd" /> )} />, @@ -106,13 +106,14 @@ describe('', () => { const fields = [ 'FormField[name="name"]', 'FormField[name="description"]', - 'Field[name="organization"]', - 'Field[name="inventory"]', + 'FormGroup[label="Organization"]', + 'FormGroup[label="Inventory"]', 'FormField[name="limit"]', 'FormField[name="scm_branch"]', - 'Field[name="labels"]', + 'FormGroup[label="Labels"]', 'VariablesField', ]; + const assertField = field => { expect(wrapper.find(`${field}`).length).toBe(1); }; @@ -191,7 +192,7 @@ describe('', () => { ).toBe('sdfghjklmnbvcdsew435678iokjhgfd'); await act(() => wrapper - .find('FormGroup[name="webhook_key"]') + .find('FormGroup[name="webhookKey"]') .find('Button[variant="tertiary"]') .prop('onClick')() ); @@ -201,8 +202,7 @@ describe('', () => { ).toContain('/api/v2/workflow_job_templates/57/gitlab/'); wrapper.update(); - - expect(wrapper.find('Field[name="webhook_service"]').length).toBe(1); + expect(wrapper.find('FormGroup[name="webhook_service"]').length).toBe(1); act(() => wrapper.find('AnsibleSelect').prop('onChange')({}, 'gitlab')); wrapper.update();