2018-09-24 22:04:37 +02:00
|
|
|
/**
|
|
|
|
* @prettier
|
|
|
|
* @flow
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
2018-10-01 07:06:30 +02:00
|
|
|
import { shallow } from 'enzyme';
|
2018-09-24 22:04:37 +02:00
|
|
|
|
|
|
|
import CopyToClipBoard from '../../../../src/webui/components/CopyToClipBoard';
|
2018-10-01 07:06:30 +02:00
|
|
|
import { CopyIcon } from '../../../../src/webui/components/CopyToClipBoard/styles';
|
2018-09-24 22:04:37 +02:00
|
|
|
|
|
|
|
describe('<CopyToClipBoard /> component', () => {
|
|
|
|
let wrapper;
|
|
|
|
let props;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
props = {
|
|
|
|
text: 'copy text',
|
|
|
|
};
|
|
|
|
wrapper = shallow(<CopyToClipBoard {...props} />);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('render the component', () => {
|
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should call the DOM APIs for copy to clipboard utility', () => {
|
|
|
|
const event = {
|
|
|
|
preventDefault: jest.fn(),
|
|
|
|
};
|
|
|
|
|
|
|
|
global.getSelection = jest.fn(() => ({
|
|
|
|
removeAllRanges: () => {},
|
|
|
|
addRange: () => {},
|
|
|
|
}));
|
|
|
|
|
2018-10-01 07:06:30 +02:00
|
|
|
const { document, getSelection } = global;
|
2018-09-24 22:04:37 +02:00
|
|
|
|
|
|
|
wrapper.find(CopyIcon).simulate('click', event);
|
|
|
|
expect(event.preventDefault).toHaveBeenCalled();
|
|
|
|
expect(document.createRange).toHaveBeenCalled();
|
|
|
|
expect(getSelection).toHaveBeenCalled();
|
|
|
|
expect(document.execCommand).toHaveBeenCalledWith('copy');
|
|
|
|
});
|
|
|
|
});
|