mirror of
https://github.com/SomboChea/ui
synced 2024-09-29 04:47:47 +07:00
67d7188cf5
* chore: update material-ui@4.x * test: update test for ActionBar and TestField * chore: add types * chore: update types * test: update test for Author * chore: fixed bunch of unit test * chore: remove unused import * chore: remove comments * chore: replace shallow my mount * chore: update git hooks * chore: fix styles * chore: update dependencies * chore: remove types material-ui
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import React from 'react';
|
|
import { mount } from 'enzyme';
|
|
|
|
import CopyToClipBoard from './CopyToClipBoard';
|
|
import { CopyIcon } from './styles';
|
|
|
|
describe('<CopyToClipBoard /> component', () => {
|
|
let wrapper;
|
|
|
|
beforeEach(() => {
|
|
wrapper = mount(<CopyToClipBoard text={'copy text'} />);
|
|
});
|
|
|
|
test('render the component', () => {
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
});
|
|
|
|
test('should call the DOM APIs for copy to clipboard utility', () => {
|
|
const event = {
|
|
preventDefault: jest.fn(),
|
|
};
|
|
|
|
// @ts-ignore: Property 'getSelection' does not exist on type 'Global'.
|
|
global.getSelection = jest.fn(() => ({
|
|
removeAllRanges: () => {},
|
|
addRange: () => {},
|
|
}));
|
|
|
|
// @ts-ignore: Property 'document/getSelection' does not exist on type 'Global'.
|
|
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');
|
|
});
|
|
});
|