mirror of
https://github.com/ansible/awx.git
synced 2026-04-05 01:59:25 -02:30
fix JT form tests
This commit is contained in:
@@ -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);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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'
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user