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', () => {
setHideOverflow(!isExpanded);
});
})
});
useEffect(() => {
setContentHeight(ref.current.scrollHeight);
});

View File

@ -18,17 +18,18 @@ describe('<TagMultiSelect />', () => {
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', () => {
const onChange = jest.fn();
const wrapper = mount(
<TagMultiSelect value="foo,bar" onChange={onChange} />
);
const input = wrapper.find('TextInput');
input.invoke('onChange')('baz');
input.invoke('onKeyDown')({ key: 'Tab' });
const select = wrapper.find('MultiSelect');
select.invoke('onChange')([
{ name: 'foo' },
{ name: 'bar' },
{ name: 'baz' },
]);
expect(onChange).toHaveBeenCalledWith('foo,bar,baz');
});
});

View File

@ -6,6 +6,27 @@ import { JobTemplatesAPI, LabelsAPI } from '@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 />', () => {
const defaultProps = {
description: '',
@ -62,18 +83,7 @@ describe('<JobTemplateAdd />', () => {
done();
});
test.only('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: '',
};
test('handleSubmit should post to api', async done => {
JobTemplatesAPI.create.mockResolvedValueOnce({
data: {
id: 1,
@ -102,17 +112,6 @@ describe('<JobTemplateAdd />', () => {
const history = {
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({
data: {
id: 1,
@ -124,7 +123,9 @@ describe('<JobTemplateAdd />', () => {
context: { router: { history } },
});
await wrapper.find('JobTemplateForm').invoke('handleSubmit')(jobTemplateData);
await wrapper.find('JobTemplateForm').invoke('handleSubmit')(
jobTemplateData
);
await sleep(0);
expect(history.push).toHaveBeenCalledWith(
'/templates/job_template/1/details'

View File

@ -15,8 +15,18 @@ const mockJobTemplate = {
project: 3,
playbook: 'Baz',
type: 'job_template',
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: '',
summary_fields: {
user_capabilities: {
edit: true,