2019-01-03 16:00:55 +03:00
|
|
|
import React from 'react';
|
|
|
|
import { mount } from 'enzyme';
|
|
|
|
import { mountToJson } from 'enzyme-to-json';
|
|
|
|
import { Editor } from '../src';
|
|
|
|
import 'codemirror/mode/javascript/javascript';
|
|
|
|
|
2020-08-08 23:26:39 +03:00
|
|
|
describe('Editor', function () {
|
2019-01-03 16:00:55 +03:00
|
|
|
const getBoundingClientRect = jest.fn();
|
|
|
|
const getClientRects = jest.fn();
|
2020-08-08 22:46:01 +03:00
|
|
|
|
|
|
|
// See https://github.com/jsdom/jsdom/issues/3002
|
|
|
|
document.createRange = () => {
|
|
|
|
const range = new Range();
|
|
|
|
|
|
|
|
range.getBoundingClientRect = getBoundingClientRect;
|
|
|
|
|
|
|
|
range.getClientRects = () => {
|
|
|
|
getClientRects();
|
|
|
|
return {
|
|
|
|
item: () => null,
|
|
|
|
length: 0,
|
2020-08-08 23:26:39 +03:00
|
|
|
[Symbol.iterator]: jest.fn(),
|
2020-08-08 22:46:01 +03:00
|
|
|
};
|
2019-01-03 16:00:55 +03:00
|
|
|
};
|
2020-08-08 22:46:01 +03:00
|
|
|
|
|
|
|
return range;
|
2019-01-03 16:00:55 +03:00
|
|
|
};
|
2020-09-13 07:02:24 +03:00
|
|
|
const wrapper = mount(<Editor value="var a = 1;" />);
|
2019-01-03 16:00:55 +03:00
|
|
|
|
|
|
|
it('renders correctly', () => {
|
|
|
|
expect(mountToJson(wrapper)).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls getBoundingClientRect', () => {
|
|
|
|
expect(getBoundingClientRect).toBeCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls getClientRects', () => {
|
|
|
|
expect(getClientRects).toBeCalled();
|
|
|
|
});
|
|
|
|
});
|