fixing JT Form tests post-rebase

This commit is contained in:
Keith Grant 2019-09-06 11:35:24 -07:00
parent 9777b79818
commit be6f5e18ae
6 changed files with 41 additions and 5 deletions

View File

@ -0,0 +1,26 @@
import React from 'react';
import { shallow } from 'enzyme';
import CollapsibleSection from './CollapsibleSection';
describe('<CollapsibleSection>', () => {
it('should render contents', () => {
const wrapper = shallow(
<CollapsibleSection label="Advanced">foo</CollapsibleSection>
);
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(
<CollapsibleSection label="Advanced">foo</CollapsibleSection>
);
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);
});
});

View File

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

View File

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

View File

@ -62,7 +62,7 @@ describe('<JobTemplateAdd />', () => {
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('<JobTemplateAdd />', () => {
name: 'Foo',
playbook: 'Bar',
project: 2,
verbosity: '0',
job_tags: '',
skip_tags: '',
};
JobTemplatesAPI.create.mockResolvedValueOnce({
data: {
@ -106,6 +109,9 @@ describe('<JobTemplateAdd />', () => {
name: 'Foo',
playbook: 'Bar',
project: 2,
verbosity: '0',
job_tags: '',
skip_tags: '',
};
JobTemplatesAPI.create.mockResolvedValueOnce({
data: {
@ -118,7 +124,7 @@ describe('<JobTemplateAdd />', () => {
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('<JobTemplateAdd />', () => {
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();
});

View File

@ -15,6 +15,8 @@ const mockJobTemplate = {
project: 3,
playbook: 'Baz',
type: 'job_template',
job_tags: '',
skip_tags: '',
summary_fields: {
user_capabilities: {
edit: true,

View File

@ -177,7 +177,7 @@ describe('<JobTemplateForm />', () => {
});
test('handleNewLabel should arrange new labels properly', async () => {
const event = { key: 'Enter' };
const event = { key: 'Enter', preventDefault: () => {} };
const wrapper = mountWithContexts(
<JobTemplateForm
template={mockData}