fix JT form tests

This commit is contained in:
Keith Grant
2019-09-06 14:27:02 -07:00
parent be6f5e18ae
commit 820605b0ca
4 changed files with 42 additions and 30 deletions

View File

@@ -16,7 +16,7 @@ function ExpandingContainer({ isExpanded, children }) {
ref.current.addEventListener('transitionend', () => { ref.current.addEventListener('transitionend', () => {
setHideOverflow(!isExpanded); setHideOverflow(!isExpanded);
}); });
}) });
useEffect(() => { useEffect(() => {
setContentHeight(ref.current.scrollHeight); setContentHeight(ref.current.scrollHeight);
}); });

View File

@@ -18,17 +18,18 @@ describe('<TagMultiSelect />', () => {
expect(wrapper.find('MultiSelect').prop('options')).toEqual([]); expect(wrapper.find('MultiSelect').prop('options')).toEqual([]);
}); });
// NOTE: this test throws a warning which *should* be go away once we upgrade
// to React 16.8 (https://github.com/airbnb/enzyme/blob/master/docs/api/ReactWrapper/invoke.md)
it('should trigger onChange', () => { it('should trigger onChange', () => {
const onChange = jest.fn(); const onChange = jest.fn();
const wrapper = mount( const wrapper = mount(
<TagMultiSelect value="foo,bar" onChange={onChange} /> <TagMultiSelect value="foo,bar" onChange={onChange} />
); );
const input = wrapper.find('TextInput'); const select = wrapper.find('MultiSelect');
input.invoke('onChange')('baz'); select.invoke('onChange')([
input.invoke('onKeyDown')({ key: 'Tab' }); { name: 'foo' },
{ name: 'bar' },
{ name: 'baz' },
]);
expect(onChange).toHaveBeenCalledWith('foo,bar,baz'); expect(onChange).toHaveBeenCalledWith('foo,bar,baz');
}); });
}); });

View File

@@ -6,6 +6,27 @@ import { JobTemplatesAPI, LabelsAPI } from '@api';
jest.mock('@api'); jest.mock('@api');
const jobTemplateData = {
name: 'Foo',
description: 'Baz',
job_type: 'run',
inventory: 1,
project: 2,
playbook: 'Bar',
forks: 0,
limit: '',
verbosity: '0',
job_slice_count: 1,
timeout: 0,
job_tags: '',
skip_tags: '',
diff_mode: false,
allow_callbacks: false,
allow_simultaneous: false,
use_fact_cache: false,
host_config_key: '',
};
describe('<JobTemplateAdd />', () => { describe('<JobTemplateAdd />', () => {
const defaultProps = { const defaultProps = {
description: '', description: '',
@@ -62,18 +83,7 @@ describe('<JobTemplateAdd />', () => {
done(); done();
}); });
test.only('handleSubmit should post to api', async done => { test('handleSubmit should post to api', async done => {
const jobTemplateData = {
description: 'Baz',
inventory: 1,
job_type: 'run',
name: 'Foo',
playbook: 'Bar',
project: 2,
verbosity: '0',
job_tags: '',
skip_tags: '',
};
JobTemplatesAPI.create.mockResolvedValueOnce({ JobTemplatesAPI.create.mockResolvedValueOnce({
data: { data: {
id: 1, id: 1,
@@ -102,17 +112,6 @@ describe('<JobTemplateAdd />', () => {
const history = { const history = {
push: jest.fn(), push: jest.fn(),
}; };
const jobTemplateData = {
description: 'Baz',
inventory: 1,
job_type: 'run',
name: 'Foo',
playbook: 'Bar',
project: 2,
verbosity: '0',
job_tags: '',
skip_tags: '',
};
JobTemplatesAPI.create.mockResolvedValueOnce({ JobTemplatesAPI.create.mockResolvedValueOnce({
data: { data: {
id: 1, id: 1,
@@ -124,7 +123,9 @@ describe('<JobTemplateAdd />', () => {
context: { router: { history } }, context: { router: { history } },
}); });
await wrapper.find('JobTemplateForm').invoke('handleSubmit')(jobTemplateData); await wrapper.find('JobTemplateForm').invoke('handleSubmit')(
jobTemplateData
);
await sleep(0); await sleep(0);
expect(history.push).toHaveBeenCalledWith( expect(history.push).toHaveBeenCalledWith(
'/templates/job_template/1/details' '/templates/job_template/1/details'

View File

@@ -15,8 +15,18 @@ const mockJobTemplate = {
project: 3, project: 3,
playbook: 'Baz', playbook: 'Baz',
type: 'job_template', type: 'job_template',
forks: 0,
limit: '',
verbosity: '0',
job_slice_count: 1,
timeout: 0,
job_tags: '', job_tags: '',
skip_tags: '', skip_tags: '',
diff_mode: false,
allow_callbacks: false,
allow_simultaneous: false,
use_fact_cache: false,
host_config_key: '',
summary_fields: { summary_fields: {
user_capabilities: { user_capabilities: {
edit: true, edit: true,