ManageIQ/manageiq-ui-classic

View on GitHub
app/javascript/spec/code-editor/code-editor.spec.js

Summary

Maintainability
A
0 mins
Test Coverage
import React from 'react';
import { shallow, mount } from 'enzyme';
import { shallowToJson } from 'enzyme-to-json';

import CodeEditor from '../../components/code-editor';

jest.mock('@@ddf', () => ({
  useFieldApi: props => ({ meta: {}, input: {}, ...props }),
}));

describe('CodeEditor component', () => {
  let initialProps;
  beforeEach(() => {
    initialProps = {
      onChange: jest.fn(),
      labelText: 'foo',
    };
  });

  it('should render correctly', () => {
    const wrapper = shallow(<CodeEditor {...initialProps} />);
    expect(shallowToJson(wrapper)).toMatchSnapshot();
  });

  it('should render mode switches', () => {
    const wrapper = shallow(<CodeEditor {...initialProps} modes={['yaml', 'json']} />);
    expect(shallowToJson(wrapper)).toMatchSnapshot();
  });

  it('should mount and assign correct props to data driven variant', () => {
    const onChange = jest.fn();
    const wrapper = mount(<CodeEditor {...initialProps} onChange={onChange} />);
    wrapper.find(CodeEditor).props().onChange('foo');
    expect(onChange).toHaveBeenCalledTimes(1);
    expect(onChange).toHaveBeenCalledWith('foo');
  });
});