diff --git a/config/jest/setupTests.ts b/config/jest/setupTests.ts
index 5893b1ca..cec71a7a 100644
--- a/config/jest/setupTests.ts
+++ b/config/jest/setupTests.ts
@@ -4,4 +4,5 @@ import ResizeObserver from 'resize-observer-polyfill';
(global as any).ResizeObserver = ResizeObserver;
(global as any).scrollTo = () => {};
+(global as any).prompt = () => {};
(global as any).matchMedia = (media: string) => ({ matches: false, media });
diff --git a/test/utils/CopyToClipboardIcon.test.tsx b/test/utils/CopyToClipboardIcon.test.tsx
index f286e724..23cfb1c4 100644
--- a/test/utils/CopyToClipboardIcon.test.tsx
+++ b/test/utils/CopyToClipboardIcon.test.tsx
@@ -1,27 +1,30 @@
-import { shallow, ShallowWrapper } from 'enzyme';
-import CopyToClipboard from 'react-copy-to-clipboard';
-import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
-import { faCopy as copyIcon } from '@fortawesome/free-regular-svg-icons';
+import { render } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
import { CopyToClipboardIcon } from '../../src/utils/CopyToClipboardIcon';
describe('', () => {
- let wrapper: ShallowWrapper;
- const onCopy = () => {};
-
- beforeEach(() => {
- wrapper = shallow();
+ const onCopy = jest.fn();
+ const setUp = (text = 'foo') => ({
+ user: userEvent.setup(),
+ ...render(),
});
- afterEach(() => wrapper?.unmount());
+
+ afterEach(jest.clearAllMocks);
it('wraps expected components', () => {
- const copyToClipboard = wrapper.find(CopyToClipboard);
- const icon = wrapper.find(FontAwesomeIcon);
+ const { container } = setUp();
+ expect(container).toMatchSnapshot();
+ });
- expect(copyToClipboard).toHaveLength(1);
- expect(copyToClipboard.prop('text')).toEqual('foo');
- expect(copyToClipboard.prop('onCopy')).toEqual(onCopy);
- expect(icon).toHaveLength(1);
- expect(icon.prop('icon')).toEqual(copyIcon);
- expect(icon.prop('className')).toEqual('ms-2 copy-to-clipboard-icon');
+ it.each([
+ ['text'],
+ ['bar'],
+ ['baz'],
+ ])('copies content to clipboard when clicked', async (text) => {
+ const { user, container } = setUp(text);
+
+ expect(onCopy).not.toHaveBeenCalled();
+ container.firstElementChild && await user.click(container.firstElementChild);
+ expect(onCopy).toHaveBeenCalledWith(text, false);
});
});
diff --git a/test/utils/DateInput.test.tsx b/test/utils/DateInput.test.tsx
index 4a0ab9c0..a37a39da 100644
--- a/test/utils/DateInput.test.tsx
+++ b/test/utils/DateInput.test.tsx
@@ -1,35 +1,34 @@
-import { shallow, ShallowWrapper } from 'enzyme';
-import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
+import { render, screen, waitFor } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
import { Mock } from 'ts-mockery';
import { DateInput, DateInputProps } from '../../src/utils/DateInput';
describe('', () => {
- let wrapped: ShallowWrapper;
-
- const createComponent = (props: Partial = {}) => {
- wrapped = shallow((props)} />);
-
- return wrapped;
- };
-
- afterEach(() => wrapped?.unmount());
-
- it('wraps a DatePicker', () => {
- wrapped = createComponent();
+ const setUp = (props: Partial = {}) => ({
+ user: userEvent.setup(),
+ ...render((props)} />),
});
it('shows calendar icon when input is not clearable', () => {
- wrapped = createComponent({ isClearable: false });
- expect(wrapped.find(FontAwesomeIcon)).toHaveLength(1);
+ setUp({ isClearable: false });
+ expect(screen.getByRole('img', { hidden: true })).toBeInTheDocument();
});
it('shows calendar icon when input is clearable but selected value is nil', () => {
- wrapped = createComponent({ isClearable: true, selected: null });
- expect(wrapped.find(FontAwesomeIcon)).toHaveLength(1);
+ setUp({ isClearable: true, selected: null });
+ expect(screen.getByRole('img', { hidden: true })).toBeInTheDocument();
});
it('does not show calendar icon when input is clearable', () => {
- wrapped = createComponent({ isClearable: true, selected: new Date() });
- expect(wrapped.find(FontAwesomeIcon)).toHaveLength(0);
+ setUp({ isClearable: true, selected: new Date() });
+ expect(screen.queryByRole('img', { hidden: true })).not.toBeInTheDocument();
+ });
+
+ it('shows popper on element click', async () => {
+ const { user, container } = setUp({ placeholderText: 'foo' });
+
+ expect(container.querySelector('.react-datepicker')).not.toBeInTheDocument();
+ await user.click(screen.getByPlaceholderText('foo'));
+ await waitFor(() => expect(container.querySelector('.react-datepicker')).toBeInTheDocument());
});
});
diff --git a/test/utils/__snapshots__/CopyToClipboardIcon.test.tsx.snap b/test/utils/__snapshots__/CopyToClipboardIcon.test.tsx.snap
new file mode 100644
index 00000000..de841e3e
--- /dev/null
+++ b/test/utils/__snapshots__/CopyToClipboardIcon.test.tsx.snap
@@ -0,0 +1,21 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[` wraps expected components 1`] = `
+
+`;