From be6f5e18ae52c5119128bce554b54f7b17fb4969 Mon Sep 17 00:00:00 2001 From: Keith Grant Date: Fri, 6 Sep 2019 11:35:24 -0700 Subject: [PATCH] fixing JT Form tests post-rebase --- .../CollapsibleSection.test.jsx | 26 +++++++++++++++++++ .../ExpandCollapse/ExpandCollapse.jsx | 2 ++ .../JobTemplateAdd/JobTemplateAdd.jsx | 2 +- .../JobTemplateAdd/JobTemplateAdd.test.jsx | 12 ++++++--- .../JobTemplateEdit/JobTemplateEdit.test.jsx | 2 ++ .../Template/shared/JobTemplateForm.test.jsx | 2 +- 6 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 awx/ui_next/src/components/CollapsibleSection/CollapsibleSection.test.jsx diff --git a/awx/ui_next/src/components/CollapsibleSection/CollapsibleSection.test.jsx b/awx/ui_next/src/components/CollapsibleSection/CollapsibleSection.test.jsx new file mode 100644 index 0000000000..d3b5d09930 --- /dev/null +++ b/awx/ui_next/src/components/CollapsibleSection/CollapsibleSection.test.jsx @@ -0,0 +1,26 @@ +import React from 'react'; +import { shallow } from 'enzyme'; +import CollapsibleSection from './CollapsibleSection'; + +describe('', () => { + it('should render contents', () => { + const wrapper = shallow( + foo + ); + expect(wrapper.find('Button > *').prop('isExpanded')).toEqual(false); + expect(wrapper.find('ExpandingContainer').prop('isExpanded')).toEqual( + false + ); + expect(wrapper.find('ExpandingContainer').prop('children')).toEqual('foo'); + }); + + it('should toggle when clicked', () => { + const wrapper = shallow( + foo + ); + expect(wrapper.find('Button > *').prop('isExpanded')).toEqual(false); + wrapper.find('Button').simulate('click'); + expect(wrapper.find('Button > *').prop('isExpanded')).toEqual(true); + expect(wrapper.find('ExpandingContainer').prop('isExpanded')).toEqual(true); + }); +}); diff --git a/awx/ui_next/src/components/ExpandCollapse/ExpandCollapse.jsx b/awx/ui_next/src/components/ExpandCollapse/ExpandCollapse.jsx index 6d06c8acd6..7ffce947d8 100644 --- a/awx/ui_next/src/components/ExpandCollapse/ExpandCollapse.jsx +++ b/awx/ui_next/src/components/ExpandCollapse/ExpandCollapse.jsx @@ -29,6 +29,8 @@ const ToolbarItem = styled(PFToolbarItem)` } `; +// TODO: Recommend renaming this component to avoid confusion +// with ExpandingContainer class ExpandCollapse extends React.Component { render() { const { isCompact, onCompact, onExpand, i18n } = this.props; diff --git a/awx/ui_next/src/screens/Template/JobTemplateAdd/JobTemplateAdd.jsx b/awx/ui_next/src/screens/Template/JobTemplateAdd/JobTemplateAdd.jsx index c8f1a6894d..85bec5dfff 100644 --- a/awx/ui_next/src/screens/Template/JobTemplateAdd/JobTemplateAdd.jsx +++ b/awx/ui_next/src/screens/Template/JobTemplateAdd/JobTemplateAdd.jsx @@ -58,7 +58,7 @@ function JobTemplateAdd({ history, i18n }) { ]); } - function submitInstanceGroups(templateId, addedGroups) { + function submitInstanceGroups(templateId, addedGroups = []) { const associatePromises = addedGroups.map(group => JobTemplatesAPI.associateInstanceGroup(templateId, group.id) ); diff --git a/awx/ui_next/src/screens/Template/JobTemplateAdd/JobTemplateAdd.test.jsx b/awx/ui_next/src/screens/Template/JobTemplateAdd/JobTemplateAdd.test.jsx index f5c68c7cf5..e9a3572ffd 100644 --- a/awx/ui_next/src/screens/Template/JobTemplateAdd/JobTemplateAdd.test.jsx +++ b/awx/ui_next/src/screens/Template/JobTemplateAdd/JobTemplateAdd.test.jsx @@ -62,7 +62,7 @@ describe('', () => { done(); }); - test('handleSubmit should post to api', async done => { + test.only('handleSubmit should post to api', async done => { const jobTemplateData = { description: 'Baz', inventory: 1, @@ -70,6 +70,9 @@ describe('', () => { name: 'Foo', playbook: 'Bar', project: 2, + verbosity: '0', + job_tags: '', + skip_tags: '', }; JobTemplatesAPI.create.mockResolvedValueOnce({ data: { @@ -106,6 +109,9 @@ describe('', () => { name: 'Foo', playbook: 'Bar', project: 2, + verbosity: '0', + job_tags: '', + skip_tags: '', }; JobTemplatesAPI.create.mockResolvedValueOnce({ data: { @@ -118,7 +124,7 @@ describe('', () => { context: { router: { history } }, }); - await wrapper.find('JobTemplateForm').prop('handleSubmit')(jobTemplateData); + await wrapper.find('JobTemplateForm').invoke('handleSubmit')(jobTemplateData); await sleep(0); expect(history.push).toHaveBeenCalledWith( '/templates/job_template/1/details' @@ -134,7 +140,7 @@ describe('', () => { context: { router: { history } }, }); await waitForElement(wrapper, 'EmptyStateBody', el => el.length === 0); - wrapper.find('button[aria-label="Cancel"]').prop('onClick')(); + wrapper.find('button[aria-label="Cancel"]').invoke('onClick')(); expect(history.push).toHaveBeenCalledWith('/templates'); done(); }); 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 1020dc6901..8be8a1eb74 100644 --- a/awx/ui_next/src/screens/Template/JobTemplateEdit/JobTemplateEdit.test.jsx +++ b/awx/ui_next/src/screens/Template/JobTemplateEdit/JobTemplateEdit.test.jsx @@ -15,6 +15,8 @@ const mockJobTemplate = { project: 3, playbook: 'Baz', type: 'job_template', + job_tags: '', + skip_tags: '', summary_fields: { user_capabilities: { edit: true, diff --git a/awx/ui_next/src/screens/Template/shared/JobTemplateForm.test.jsx b/awx/ui_next/src/screens/Template/shared/JobTemplateForm.test.jsx index 938e2035bb..cc079ef9c1 100644 --- a/awx/ui_next/src/screens/Template/shared/JobTemplateForm.test.jsx +++ b/awx/ui_next/src/screens/Template/shared/JobTemplateForm.test.jsx @@ -177,7 +177,7 @@ describe('', () => { }); test('handleNewLabel should arrange new labels properly', async () => { - const event = { key: 'Enter' }; + const event = { key: 'Enter', preventDefault: () => {} }; const wrapper = mountWithContexts(