mirror of
https://github.com/ansible/awx.git
synced 2026-01-12 10:30:03 -03:30
add more code editor tests
This commit is contained in:
parent
143d41fb2a
commit
4e55c98bc6
@ -7,15 +7,23 @@ describe('CodeEditor', () => {
|
||||
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', () => {
|
||||
const onChange = jest.fn();
|
||||
const wrapper = mount(
|
||||
<CodeEditor value="---" 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('---');
|
||||
aceEditor.prop('onChange')('newvalue');
|
||||
expect(onChange).toHaveBeenCalledWith('newvalue');
|
||||
});
|
||||
|
||||
@ -22,8 +22,8 @@ describe('VariablesField', () => {
|
||||
expect(codeEditor.prop('value')).toEqual(value);
|
||||
});
|
||||
|
||||
it('should render yaml/json toggles', async () => {
|
||||
const value = '---\n';
|
||||
it('should toggle between yaml/json', async () => {
|
||||
const value = '---\nfoo: bar\nbaz: 3';
|
||||
const wrapper = mountWithContexts(
|
||||
<Formik initialValues={{ variables: value }}>
|
||||
{() => (
|
||||
@ -40,7 +40,9 @@ describe('VariablesField', () => {
|
||||
});
|
||||
wrapper.update();
|
||||
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');
|
||||
expect(buttons2.at(0).prop('variant')).toEqual('secondary');
|
||||
expect(buttons2.at(1).prop('variant')).toEqual('primary');
|
||||
@ -49,6 +51,9 @@ describe('VariablesField', () => {
|
||||
});
|
||||
wrapper.update();
|
||||
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 () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user