UNPKG

react-spatial

Version:

Components to build React map apps.

107 lines (91 loc) 3.14 kB
import React from 'react'; import { configure, shallow, mount } from 'enzyme'; import Adapter from 'enzyme-adapter-react-16'; import renderer from 'react-test-renderer'; import PermalinkInput from './PermalinkInput'; configure({ adapter: new Adapter() }); describe('PermalinkInput', function () { test('matches snapshot', function () { var component = renderer.create( React.createElement( PermalinkInput, { value: "http://url.test" }) ); expect(component.toJSON()).toMatchSnapshot(); component.getInstance().setState({ permalinkValue: 'http://url.test' }); expect(component.toJSON()).toMatchSnapshot(); }); describe('when interacts,', function () { var getShortenedUrl = null; beforeEach(function () { getShortenedUrl = jest.fn(function (val) { return new Promise(function (resolve) { return resolve(val); }); }); }); test('Promise resolution set input value.', function () { var wrapper = shallow( React.createElement( PermalinkInput, { getShortenedUrl: getShortenedUrl }) ); wrapper.setProps({ value: 'http://url.test' }); wrapper .instance() .updatePermalinkValue() .then(function () { var input = wrapper .find('input') .first() .getElement(); expect(input.props.value).toBe('http://url.test'); }); }); test('getShortenedUrl is called to set value.', function () { shallow( React.createElement( PermalinkInput, { getShortenedUrl: getShortenedUrl, value: "http://url.test" }) ); expect(getShortenedUrl).toHaveBeenCalledTimes(1); expect(getShortenedUrl).toHaveBeenCalledWith('http://url.test'); }); test('select value on input click.', function () { document.execCommand = jest.fn(); var wrapper = mount( React.createElement( PermalinkInput, { getShortenedUrl: getShortenedUrl, value: "http://url.test" }) ); var spy = jest.spyOn(PermalinkInput, 'selectInput'); expect(spy).toHaveBeenCalledTimes(0); wrapper .instance() .updatePermalinkValue() .then(function () { wrapper.update(); wrapper .find('input') .first() .simulate('click'); expect(spy).toHaveBeenCalledTimes(1); }); }); test('click button copy the value.', function () { document.execCommand = jest.fn(); var wrapper = mount( React.createElement( PermalinkInput, { getShortenedUrl: getShortenedUrl, value: "http://url.test" }) ); var spy = jest.spyOn(wrapper.instance(), 'onClickCopyButton'); expect(spy).toHaveBeenCalledTimes(0); wrapper .instance() .updatePermalinkValue() .then(function () { wrapper.update(); wrapper .find('.tm-permalink-bt') .first() .simulate('click'); expect(spy).toHaveBeenCalledTimes(1); }); }); }); }); //# sourceMappingURL=PermalinkInput.test.js.map