mirror of
https://github.com/ansible/awx.git
synced 2026-02-26 23:46:05 -03:30
add more code editor tests
This commit is contained in:
@@ -7,15 +7,23 @@ describe('CodeEditor', () => {
|
|||||||
document.body.createTextRange = jest.fn();
|
document.body.createTextRange = jest.fn();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should pass value and mode through to ace editor', () => {
|
||||||
|
const onChange = jest.fn();
|
||||||
|
const wrapper = mount(
|
||||||
|
<CodeEditor value={'---\nfoo: bar'} onChange={onChange} mode="yaml" />
|
||||||
|
);
|
||||||
|
const aceEditor = wrapper.find('AceEditor');
|
||||||
|
expect(aceEditor.prop('mode')).toEqual('yaml');
|
||||||
|
expect(aceEditor.prop('setOptions').readOnly).toEqual(false);
|
||||||
|
expect(aceEditor.prop('value')).toEqual('---\nfoo: bar');
|
||||||
|
});
|
||||||
|
|
||||||
it('should trigger onChange prop', () => {
|
it('should trigger onChange prop', () => {
|
||||||
const onChange = jest.fn();
|
const onChange = jest.fn();
|
||||||
const wrapper = mount(
|
const wrapper = mount(
|
||||||
<CodeEditor value="---" onChange={onChange} mode="yaml" />
|
<CodeEditor value="---" onChange={onChange} mode="yaml" />
|
||||||
);
|
);
|
||||||
const aceEditor = wrapper.find('AceEditor');
|
const aceEditor = wrapper.find('AceEditor');
|
||||||
expect(aceEditor.prop('mode')).toEqual('yaml');
|
|
||||||
expect(aceEditor.prop('setOptions').readOnly).toEqual(false);
|
|
||||||
expect(aceEditor.prop('value')).toEqual('---');
|
|
||||||
aceEditor.prop('onChange')('newvalue');
|
aceEditor.prop('onChange')('newvalue');
|
||||||
expect(onChange).toHaveBeenCalledWith('newvalue');
|
expect(onChange).toHaveBeenCalledWith('newvalue');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ describe('VariablesField', () => {
|
|||||||
expect(codeEditor.prop('value')).toEqual(value);
|
expect(codeEditor.prop('value')).toEqual(value);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render yaml/json toggles', async () => {
|
it('should toggle between yaml/json', async () => {
|
||||||
const value = '---\n';
|
const value = '---\nfoo: bar\nbaz: 3';
|
||||||
const wrapper = mountWithContexts(
|
const wrapper = mountWithContexts(
|
||||||
<Formik initialValues={{ variables: value }}>
|
<Formik initialValues={{ variables: value }}>
|
||||||
{() => (
|
{() => (
|
||||||
@@ -40,7 +40,9 @@ describe('VariablesField', () => {
|
|||||||
});
|
});
|
||||||
wrapper.update();
|
wrapper.update();
|
||||||
expect(wrapper.find('CodeEditor').prop('mode')).toEqual('javascript');
|
expect(wrapper.find('CodeEditor').prop('mode')).toEqual('javascript');
|
||||||
expect(wrapper.find('CodeEditor').prop('value')).toEqual('{}');
|
expect(wrapper.find('CodeEditor').prop('value')).toEqual(
|
||||||
|
'{\n "foo": "bar",\n "baz": 3\n}'
|
||||||
|
);
|
||||||
const buttons2 = wrapper.find('Button');
|
const buttons2 = wrapper.find('Button');
|
||||||
expect(buttons2.at(0).prop('variant')).toEqual('secondary');
|
expect(buttons2.at(0).prop('variant')).toEqual('secondary');
|
||||||
expect(buttons2.at(1).prop('variant')).toEqual('primary');
|
expect(buttons2.at(1).prop('variant')).toEqual('primary');
|
||||||
@@ -49,6 +51,9 @@ describe('VariablesField', () => {
|
|||||||
});
|
});
|
||||||
wrapper.update();
|
wrapper.update();
|
||||||
expect(wrapper.find('CodeEditor').prop('mode')).toEqual('yaml');
|
expect(wrapper.find('CodeEditor').prop('mode')).toEqual('yaml');
|
||||||
|
expect(wrapper.find('CodeEditor').prop('value')).toEqual(
|
||||||
|
'foo: bar\nbaz: 3\n'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set Formik error if yaml is invalid', async () => {
|
it('should set Formik error if yaml is invalid', async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user