import React from 'react';
import { mount } from 'enzyme';

import CodeEditor from '.';

describe('<CodeEditor/>', () => {
  const getClientRectSpy = jest.fn(() => ({ width: 100 }));
  Range.prototype.getBoundingClientRect = getClientRectSpy;
  Range.prototype.getClientRects = getClientRectSpy;

  const node = mount(<CodeEditor code="console.log('Hello, world.');" lang="js" />);
  const cm = node.find('Controlled');

  it('should display a <CodeEditor> element', () => {
    expect(node.children('.CodeEditor')).toHaveLength(1);
  });

  it('should highlight code', () => {
    expect(cm.html()).toContain('cm-variable');
  });

  it('should set CodeMirror options', () => {
    expect('options' in cm.props()).toBe(true);
  });

  it('should set a sanitized language mode', () => {
    expect(node.props().lang).toBe('js');
    expect(cm.props().options.mode).toBe('javascript');
  });

  it.todo('should set dark & light themes');
});
