Skip to content

Commit 39868ad

Browse files
authored
Merge pull request #172 from CreateThrive/feature/react-hook-form
Feature: react-hook-form
2 parents f3cdc2c + cce5bdb commit 39868ad

File tree

65 files changed

+6322
-5407
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+6322
-5407
lines changed

.eslintrc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@
3939
"Request": true,
4040
"fetch": true,
4141
"reducerTester": true,
42-
"mountWithProviders": true,
43-
"shallowWithProviders": true
42+
"renderWithProviders": true
4443
},
4544
"parser": "babel-eslint",
4645
"settings": {

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,14 @@ React Firebase Admin is our in-house admin dashboard boilerplate, used in many o
9090
- [Format.js](https://formatjs.io/) (★ 11.7k) libraries for internationalization (see [docs](https://formatjs.io/docs/basic-internationalization-principles)).
9191
- [date-fns](https://date-fns.org/) (★ 22.3k) date utility library (see [docs](https://date-fns.org/docs/Getting-Started)).
9292
- [cross-env](https://github.com/kentcdodds/cross-env) (★ 4.9k) run scripts that set and use environment variables across platforms (see [docs](https://www.npmjs.com/package/cross-env)).
93+
- [React Hook Form](https://github.com/react-hook-form/react-hook-form) (★ 14.6k) Performant, flexible and extensible forms with easy to use validation.
94+
- [yup](https://github.com/jquense/yup) (★ 11k) schema builder for value parsing and validation.
9395
- [Inquirer](https://github.com/SBoudrias/Inquirer.js/) (★ 12.2k) A collection of common interactive command line user interfaces (see [docs](https://github.com/SBoudrias/Inquirer.js/#documentation)).
9496

9597
### Unit Testing
9698

9799
- [Jest](https://jestjs.io/) (★ 29.9k) as testing framework (see [docs](https://jestjs.io/docs/en/getting-started)).
98-
- [Enzyme](https://airbnb.io/enzyme/) (★ 18.5k) to test react components in Jest.
100+
- [React Testing Library](https://testing-library.com/docs/react-testing-library/intro) (★ 12.7k) to test react components in Jest.
99101
- [Redux-mock-store](https://github.com/dmitry-zaets/redux-mock-store) (★ 2.1k) to test redux actions, reducers and store state in Jest.
100102

101103
### Linting

functions/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"sourceMap": true,
88
"strict": true,
99
"target": "es2017",
10-
"resolveJsonModule": true
10+
"resolveJsonModule": true,
11+
"skipLibCheck": true
1112
},
1213
"compileOnSave": true,
1314
"include": ["src"]

package-lock.json

Lines changed: 2012 additions & 1343 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6+
"@hookform/resolvers": "^0.1.0",
67
"bulma": "^0.9.0",
78
"classnames": "^2.2.6",
89
"date-fns": "^2.15.0",
910
"firebase": "^7.18",
11+
"mutationobserver-shim": "^0.3.7",
1012
"prop-types": "^15.7.2",
1113
"react": "^16.13.1",
1214
"react-datepicker": "^3.0.0",
1315
"react-dom": "^16.13.1",
1416
"react-firebaseui": "^4.1.0",
17+
"react-hook-form": "^6.7.0",
1518
"react-intl": "^5.6.5",
1619
"react-redux": "^7.2.1",
1720
"react-redux-toastr": "^7.6.4",
@@ -22,7 +25,8 @@
2225
"redux": "^4.0.5",
2326
"redux-act": "^1.8.0",
2427
"redux-persist": "^6.0.0",
25-
"redux-thunk": "^2.3.0"
28+
"redux-thunk": "^2.3.0",
29+
"yup": "^0.29.3"
2630
},
2731
"scripts": {
2832
"start": "react-scripts start",
@@ -52,14 +56,13 @@
5256
]
5357
},
5458
"devDependencies": {
59+
"@testing-library/jest-dom": "^5.11.4",
60+
"@testing-library/react": "^11.0.2",
5561
"babel-eslint": "^10.1.0",
5662
"babel-loader": "^8.1.0",
5763
"cross-env": "^7.0.2",
5864
"deep-freeze": "^0.0.1",
5965
"dotenv": "^8.2.0",
60-
"enzyme": "^3.11.0",
61-
"enzyme-adapter-react-16": "^1.15.3",
62-
"enzyme-to-json": "^3.4.4",
6366
"eslint": "^6.8.0",
6467
"eslint-config-airbnb": "^18.2.0",
6568
"eslint-config-prettier": "^6.11.0",
@@ -84,9 +87,6 @@
8487
}
8588
},
8689
"jest": {
87-
"snapshotSerializers": [
88-
"enzyme-to-json/serializer"
89-
],
9090
"collectCoverageFrom": [
9191
"src/**/*.{js,jsx}"
9292
],

src/components/ConfirmationModal/ConfirmationModal.test.js

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { shallow } from 'enzyme';
2+
import { render, fireEvent } from '@testing-library/react';
33

44
import ConfirmationModal from '.';
55

@@ -13,7 +13,7 @@ describe('<ConfirmationModal /> rendering', () => {
1313
});
1414

1515
it('should render without crashing', () => {
16-
const component = shallow(
16+
const component = render(
1717
<ConfirmationModal
1818
isActive
1919
confirmButtonMessage="test message"
@@ -25,11 +25,11 @@ describe('<ConfirmationModal /> rendering', () => {
2525
/>
2626
);
2727

28-
expect(component).toMatchSnapshot();
28+
expect(component.asFragment()).toMatchSnapshot();
2929
});
3030

3131
it('should set the active modifier if the isActive prop is passed down', () => {
32-
const component = shallow(
32+
const component = render(
3333
<ConfirmationModal
3434
isActive
3535
confirmButtonMessage="test message"
@@ -41,11 +41,13 @@ describe('<ConfirmationModal /> rendering', () => {
4141
/>
4242
);
4343

44-
expect(component.exists('div.modal.is-active')).toBeTruthy();
44+
expect(
45+
component.container.querySelector('div.modal.is-active')
46+
).toBeTruthy();
4547
});
4648

4749
it('should not set the active modifier if the isActive prop is not passed down', () => {
48-
const component = shallow(
50+
const component = render(
4951
<ConfirmationModal
5052
confirmButtonMessage="test message"
5153
onConfirmation={onConfirm}
@@ -56,11 +58,11 @@ describe('<ConfirmationModal /> rendering', () => {
5658
/>
5759
);
5860

59-
expect(component.exists('div.modal.is-active')).toBeFalsy();
61+
expect(component.container.querySelector('div.modal.is-active')).toBeNull();
6062
});
6163

6264
it('should call onConfirm when the confirmation button is clicked', () => {
63-
const component = shallow(
65+
const component = render(
6466
<ConfirmationModal
6567
isActive
6668
confirmButtonMessage="confirm test message"
@@ -72,13 +74,12 @@ describe('<ConfirmationModal /> rendering', () => {
7274
/>
7375
);
7476

75-
component.find('button[children="confirm test message"]').simulate('click');
76-
77+
fireEvent.click(component.getByText('confirm test message'));
7778
expect(onConfirm).toHaveBeenCalled();
7879
});
7980

8081
it('should call onCancel when the cancel button is clicked', () => {
81-
const component = shallow(
82+
const component = render(
8283
<ConfirmationModal
8384
isActive
8485
confirmButtonMessage="test message"
@@ -90,13 +91,13 @@ describe('<ConfirmationModal /> rendering', () => {
9091
/>
9192
);
9293

93-
component.find('button[children="cancel test message"]').simulate('click');
94+
fireEvent.click(component.getByText('cancel test message'));
9495

9596
expect(onCancel).toHaveBeenCalled();
9697
});
9798

9899
it('should set the title of the modal', () => {
99-
const component = shallow(
100+
const component = render(
100101
<ConfirmationModal
101102
isActive
102103
confirmButtonMessage="test message"
@@ -108,11 +109,11 @@ describe('<ConfirmationModal /> rendering', () => {
108109
/>
109110
);
110111

111-
expect(component.exists('p[children="test title"]')).toBeTruthy();
112+
expect(component.getByText('test title')).toBeTruthy();
112113
});
113114

114115
it('should set the body of the modal', () => {
115-
const component = shallow(
116+
const component = render(
116117
<ConfirmationModal
117118
isActive
118119
confirmButtonMessage="test message"
@@ -124,11 +125,11 @@ describe('<ConfirmationModal /> rendering', () => {
124125
/>
125126
);
126127

127-
expect(component.exists('section[children="test body"]')).toBeTruthy();
128+
expect(component.getByText('test body')).toBeTruthy();
128129
});
129130

130131
it('should set the confirm button message', () => {
131-
const component = shallow(
132+
const component = render(
132133
<ConfirmationModal
133134
isActive
134135
confirmButtonMessage="confirm test message"
@@ -140,13 +141,11 @@ describe('<ConfirmationModal /> rendering', () => {
140141
/>
141142
);
142143

143-
expect(
144-
component.exists('button[children="confirm test message"]')
145-
).toBeTruthy();
144+
expect(component.getByText('confirm test message')).toBeTruthy();
146145
});
147146

148147
it('should set the cancel button message', () => {
149-
const component = shallow(
148+
const component = render(
150149
<ConfirmationModal
151150
isActive
152151
confirmButtonMessage="test message"
@@ -158,8 +157,6 @@ describe('<ConfirmationModal /> rendering', () => {
158157
/>
159158
);
160159

161-
expect(
162-
component.exists('button[children="cancel test message"]')
163-
).toBeTruthy();
160+
expect(component.getByText('cancel test message')).toBeTruthy();
164161
});
165162
});
Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,47 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`<ConfirmationModal /> rendering should render without crashing 1`] = `
4-
<div
5-
className="modal is-active"
6-
>
4+
<DocumentFragment>
75
<div
8-
className="modal-background"
9-
onClick={[MockFunction]}
10-
/>
11-
<div
12-
className="modal-card"
6+
class="modal is-active"
137
>
14-
<header
15-
className="modal-card-head"
8+
<div
9+
class="modal-background"
10+
/>
11+
<div
12+
class="modal-card"
1613
>
17-
<p
18-
className="modal-card-title"
14+
<header
15+
class="modal-card-head"
1916
>
20-
test title
21-
</p>
22-
</header>
23-
<section
24-
className="modal-card-body"
25-
>
26-
test body
27-
</section>
28-
<footer
29-
className="modal-card-foot"
30-
>
31-
<button
32-
className="button is-danger undefined"
33-
onClick={[MockFunction]}
34-
type="button"
17+
<p
18+
class="modal-card-title"
19+
>
20+
test title
21+
</p>
22+
</header>
23+
<section
24+
class="modal-card-body"
3525
>
36-
test message
37-
</button>
38-
<button
39-
className="button"
40-
onClick={[MockFunction]}
41-
type="button"
26+
test body
27+
</section>
28+
<footer
29+
class="modal-card-foot"
4230
>
43-
test message
44-
</button>
45-
</footer>
31+
<button
32+
class="button is-danger undefined"
33+
type="button"
34+
>
35+
test message
36+
</button>
37+
<button
38+
class="button"
39+
type="button"
40+
>
41+
test message
42+
</button>
43+
</footer>
44+
</div>
4645
</div>
47-
</div>
46+
</DocumentFragment>
4847
`;

src/components/ConfirmationModal/index.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const ConfirmationModal = ({
1111
confirmButtonMessage,
1212
onConfirmation,
1313
cancelButtonMessage,
14-
onCancel
14+
onCancel,
1515
}) => {
1616
const modifiers = isActive && 'is-active';
1717
const loadingModifier = isLoading && 'is-loading';
@@ -57,7 +57,7 @@ ConfirmationModal.propTypes = {
5757
confirmButtonMessage: PropTypes.string.isRequired,
5858
onConfirmation: PropTypes.func.isRequired,
5959
cancelButtonMessage: PropTypes.string.isRequired,
60-
onCancel: PropTypes.func.isRequired
60+
onCancel: PropTypes.func.isRequired,
6161
};
6262

6363
export default ConfirmationModal;

0 commit comments

Comments
 (0)