1
0
mirror of https://github.com/SomboChea/ui synced 2024-12-01 02:14:27 +07:00
verdaccio-ui/test/unit/components/copyToClipBoard.spec.js
Juan Picado @jotadeveloper 9d7be476ad chore: relocate unit test (#39)
add new json snapshot serializer
2019-05-01 21:02:46 +02:00

46 lines
1.1 KiB
JavaScript

/**
* @prettier
* @flow
*/
import React from 'react';
import { shallow } from 'enzyme';
import CopyToClipBoard from '../../../src/webui/components/CopyToClipBoard/index';
import { CopyIcon } from '../../../src/webui/components/CopyToClipBoard/styles';
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: () => {},
}));
const { document, getSelection } = global;
wrapper.find(CopyIcon).simulate('click', event);
expect(event.preventDefault).toHaveBeenCalled();
expect(document.createRange).toHaveBeenCalled();
expect(getSelection).toHaveBeenCalled();
expect(document.execCommand).toHaveBeenCalledWith('copy');
});
});