this.handleClose()} />
+
this.handleClose()}
+ />
{title}
{description}
diff --git a/ui/components/app/info-box/info-box.test.js b/ui/components/app/info-box/info-box.test.js
index 0d81f7372..3bcad6dc2 100644
--- a/ui/components/app/info-box/info-box.test.js
+++ b/ui/components/app/info-box/info-box.test.js
@@ -1,35 +1,26 @@
import React from 'react';
-import sinon from 'sinon';
-import { shallow } from 'enzyme';
+import { fireEvent } from '@testing-library/react';
+import { renderWithProvider } from '../../../../test/lib/render-helpers';
import InfoBox from './info-box.component';
describe('InfoBox', () => {
- let wrapper;
-
const props = {
title: 'Title',
description: 'Description',
- onClose: sinon.spy(),
+ onClose: jest.fn(),
};
- beforeEach(() => {
- wrapper = shallow(
);
+ it('should match snapshot', () => {
+ const { container } = renderWithProvider(
);
+ expect(container).toMatchSnapshot();
});
- it('renders title from props', () => {
- const title = wrapper.find('.info-box__title');
- expect(title.text()).toStrictEqual(props.title);
- });
+ it('should call handleClose on info close element', () => {
+ const { queryByTestId } = renderWithProvider(
);
+ const infoBoxClose = queryByTestId('info-box-close');
- it('renders description from props', () => {
- const description = wrapper.find('.info-box__description');
- expect(description.text()).toStrictEqual(props.description);
- });
-
- it('closes info box', () => {
- const close = wrapper.find('.info-box__close');
- close.simulate('click');
- expect(props.onClose.calledOnce).toStrictEqual(true);
+ fireEvent.click(infoBoxClose);
+ expect(props.onClose).toHaveBeenCalled();
});
});
diff --git a/ui/components/app/modal/__snapshots__/modal.component.test.js.snap b/ui/components/app/modal/__snapshots__/modal.component.test.js.snap
new file mode 100644
index 000000000..afd63d7dc
--- /dev/null
+++ b/ui/components/app/modal/__snapshots__/modal.component.test.js.snap
@@ -0,0 +1,157 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`Modal Component should render a modal with a cancel and a submit button 1`] = `
+
+`;
+
+exports[`Modal Component should render a modal with a header 1`] = `
+
+`;
+
+exports[`Modal Component should render a modal with a submit button 1`] = `
+
+`;
+
+exports[`Modal Component should render a modal with children 1`] = `
+
+`;
+
+exports[`Modal Component should render a modal with different button types 1`] = `
+
+`;
diff --git a/ui/components/app/modal/modal-content/__snapshots__/modal-content.component.test.js.snap b/ui/components/app/modal/modal-content/__snapshots__/modal-content.component.test.js.snap
new file mode 100644
index 000000000..4b678cce1
--- /dev/null
+++ b/ui/components/app/modal/modal-content/__snapshots__/modal-content.component.test.js.snap
@@ -0,0 +1,20 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`ModalContent Component should match snapshot 1`] = `
+
+
+
+ Modal Title
+
+
+ Modal Description
+
+
+
+`;
diff --git a/ui/components/app/modal/modal-content/modal-content.component.test.js b/ui/components/app/modal/modal-content/modal-content.component.test.js
index ec7bc725d..0a9701630 100644
--- a/ui/components/app/modal/modal-content/modal-content.component.test.js
+++ b/ui/components/app/modal/modal-content/modal-content.component.test.js
@@ -1,40 +1,15 @@
import React from 'react';
-import { shallow } from 'enzyme';
-import ModalContent from './modal-content.component';
+import { renderWithProvider } from '../../../../../test/lib/render-helpers';
+import ModalContent from '.';
describe('ModalContent Component', () => {
- it('should render a title', () => {
- const wrapper = shallow(
);
+ const props = {
+ title: 'Modal Title',
+ description: 'Modal Description',
+ };
+ it('should match snapshot', () => {
+ const { container } = renderWithProvider(
);
- expect(wrapper.find('.modal-content__title')).toHaveLength(1);
- expect(wrapper.find('.modal-content__title').text()).toStrictEqual(
- 'Modal Title',
- );
- expect(wrapper.find('.modal-content__description')).toHaveLength(0);
- });
-
- it('should render a description', () => {
- const wrapper = shallow(
);
-
- expect(wrapper.find('.modal-content__title')).toHaveLength(0);
- expect(wrapper.find('.modal-content__description')).toHaveLength(1);
- expect(wrapper.find('.modal-content__description').text()).toStrictEqual(
- 'Modal Description',
- );
- });
-
- it('should render both a title and a description', () => {
- const wrapper = shallow(
-
,
- );
-
- expect(wrapper.find('.modal-content__title')).toHaveLength(1);
- expect(wrapper.find('.modal-content__title').text()).toStrictEqual(
- 'Modal Title',
- );
- expect(wrapper.find('.modal-content__description')).toHaveLength(1);
- expect(wrapper.find('.modal-content__description').text()).toStrictEqual(
- 'Modal Description',
- );
+ expect(container).toMatchSnapshot();
});
});
diff --git a/ui/components/app/modal/modal.component.js b/ui/components/app/modal/modal.component.js
index 14335c634..e2896a030 100644
--- a/ui/components/app/modal/modal.component.js
+++ b/ui/components/app/modal/modal.component.js
@@ -50,7 +50,11 @@ export default class Modal extends PureComponent {
{headerText && (
)}
diff --git a/ui/components/app/modal/modal.component.test.js b/ui/components/app/modal/modal.component.test.js
index 646c9b11a..21fae44f4 100644
--- a/ui/components/app/modal/modal.component.test.js
+++ b/ui/components/app/modal/modal.component.test.js
@@ -1,133 +1,103 @@
import React from 'react';
-import { mount, shallow } from 'enzyme';
-import sinon from 'sinon';
-import Button from '../../ui/button';
+import { fireEvent } from '@testing-library/react';
+import { renderWithProvider } from '../../../../test/lib/render-helpers';
import Modal from './modal.component';
describe('Modal Component', () => {
it('should render a modal with a submit button', () => {
- const wrapper = shallow(
);
+ const { container } = renderWithProvider(
);
- expect(wrapper.find('.modal-container')).toHaveLength(1);
- const buttons = wrapper.find(Button);
- expect(buttons).toHaveLength(1);
- expect(buttons.at(0).props().type).toStrictEqual('primary');
+ expect(container).toMatchSnapshot();
});
it('should render a modal with a cancel and a submit button', () => {
- const handleCancel = sinon.spy();
- const handleSubmit = sinon.spy();
- const wrapper = shallow(
-
,
- );
+ const props = {
+ onCancel: jest.fn(),
+ cancelText: 'Cancel',
+ onSubmit: jest.fn(),
+ submitText: 'Submit',
+ };
+ const { container, queryByText } = renderWithProvider(
);
+ expect(container).toMatchSnapshot();
- const buttons = wrapper.find(Button);
- expect(buttons).toHaveLength(2);
- const cancelButton = buttons.at(0);
- const submitButton = buttons.at(1);
+ const cancelButton = queryByText(props.cancelText);
+ const submitButton = queryByText(props.submitText);
- expect(cancelButton.props().type).toStrictEqual('secondary');
- expect(cancelButton.props().children).toStrictEqual('Cancel');
- expect(handleCancel.callCount).toStrictEqual(0);
- cancelButton.simulate('click');
- expect(handleCancel.callCount).toStrictEqual(1);
+ expect(props.onCancel).not.toHaveBeenCalled();
+ fireEvent.click(cancelButton);
+ expect(props.onCancel).toHaveBeenCalled();
- expect(submitButton.props().type).toStrictEqual('primary');
- expect(submitButton.props().children).toStrictEqual('Submit');
- expect(handleSubmit.callCount).toStrictEqual(0);
- submitButton.simulate('click');
- expect(handleSubmit.callCount).toStrictEqual(1);
+ expect(props.onSubmit).not.toHaveBeenCalled();
+ fireEvent.click(submitButton);
+ expect(props.onSubmit).toHaveBeenCalled();
});
it('should render a modal with different button types', () => {
- const wrapper = shallow(
-
undefined}
- cancelText="Cancel"
- cancelType="default"
- onSubmit={() => undefined}
- submitText="Submit"
- submitType="confirm"
- />,
- );
+ const props = {
+ onCancel: () => undefined,
+ cancelText: 'Cancel',
+ cancelType: 'default',
+ onSubmit: () => undefined,
+ submitText: 'Submit',
+ submitType: 'confirm',
+ };
- const buttons = wrapper.find(Button);
- expect(buttons).toHaveLength(2);
- expect(buttons.at(0).props().type).toStrictEqual('default');
- expect(buttons.at(1).props().type).toStrictEqual('confirm');
+ const { container } = renderWithProvider();
+
+ expect(container).toMatchSnapshot();
});
it('should render a modal with children', () => {
- const wrapper = shallow(
- undefined}
- cancelText="Cancel"
- onSubmit={() => undefined}
- submitText="Submit"
- >
+ const props = {
+ onCancel: () => undefined,
+ cancelText: 'Cancel',
+ onSubmit: () => undefined,
+ submitText: 'Submit',
+ };
+ const { container } = renderWithProvider(
+
,
);
- expect(wrapper.find('.test-child')).toHaveLength(1);
+ expect(container).toMatchSnapshot();
});
it('should render a modal with a header', () => {
- const handleCancel = sinon.spy();
- const handleSubmit = sinon.spy();
- const wrapper = shallow(
- ,
- );
+ const props = {
+ onCancel: jest.fn(),
+ cancelText: 'Cancel',
+ onSubmit: jest.fn(),
+ submitText: 'Submit',
+ headerText: 'My Header',
+ onClose: jest.fn(),
+ };
- expect(wrapper.find('.modal-container__header')).toHaveLength(1);
- expect(wrapper.find('.modal-container__header-text').text()).toStrictEqual(
- 'My Header',
+ const { container, queryByTestId } = renderWithProvider(
+ ,
);
- expect(handleCancel.callCount).toStrictEqual(0);
- expect(handleSubmit.callCount).toStrictEqual(0);
- wrapper.find('.modal-container__header-close').simulate('click');
- expect(handleCancel.callCount).toStrictEqual(1);
- expect(handleSubmit.callCount).toStrictEqual(0);
+ expect(container).toMatchSnapshot();
+
+ const modalClose = queryByTestId('modal-header-close');
+ fireEvent.click(modalClose);
+ expect(props.onClose).toHaveBeenCalled();
});
it('should disable the submit button if submitDisabled is true', () => {
- const handleCancel = sinon.spy();
- const handleSubmit = sinon.spy();
- const wrapper = mount(
- ,
- );
+ const props = {
+ onCancel: jest.fn(),
+ cancelText: 'Cancel',
+ onSubmit: jest.fn(),
+ submitText: 'Submit',
+ submitDisabled: true,
+ headerText: 'My Header',
+ onClose: jest.fn(),
+ };
+ const { queryByText } = renderWithProvider();
+ const submitButton = queryByText(props.submitText);
- const buttons = wrapper.find(Button);
- expect(buttons).toHaveLength(2);
- const cancelButton = buttons.at(0);
- const submitButton = buttons.at(1);
+ expect(submitButton).toHaveAttribute('disabled');
- expect(handleCancel.callCount).toStrictEqual(0);
- cancelButton.simulate('click');
- expect(handleCancel.callCount).toStrictEqual(1);
-
- expect(submitButton.props().disabled).toStrictEqual(true);
- expect(handleSubmit.callCount).toStrictEqual(0);
- submitButton.simulate('click');
- expect(handleSubmit.callCount).toStrictEqual(0);
+ fireEvent.click(submitButton);
+ expect(props.onSubmit).not.toHaveBeenCalled();
});
});
diff --git a/ui/components/ui/unit-input/unit-input.component.js b/ui/components/ui/unit-input/unit-input.component.js
index de48c76b3..1a186e012 100644
--- a/ui/components/ui/unit-input/unit-input.component.js
+++ b/ui/components/ui/unit-input/unit-input.component.js
@@ -13,6 +13,7 @@ function removeLeadingZeroes(str) {
*/
export default class UnitInput extends PureComponent {
static propTypes = {
+ dataTestId: PropTypes.string,
children: PropTypes.node,
actionComponent: PropTypes.node,
error: PropTypes.bool,
@@ -80,8 +81,14 @@ export default class UnitInput extends PureComponent {
}
render() {
- const { error, placeholder, suffix, actionComponent, children } =
- this.props;
+ const {
+ error,
+ placeholder,
+ suffix,
+ actionComponent,
+ children,
+ dataTestId,
+ } = this.props;
const { value } = this.state;
return (
@@ -92,6 +99,7 @@ export default class UnitInput extends PureComponent {