Skip to content

Commit 38cee47

Browse files
committed
Merge branch 'feature/react-hook-form' of https://github.com/CreateThrive/react-firebase-admin into feature/react-hook-form
2 parents d76a3ee + 7b418c6 commit 38cee47

File tree

63 files changed

+6137
-5038
lines changed

Some content is hidden

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

63 files changed

+6137
-5038
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ React Firebase Admin is our in-house admin dashboard boilerplate, used in many o
9292
### Unit Testing
9393

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

9898
### 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: 1967 additions & 1352 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,13 @@
5656
]
5757
},
5858
"devDependencies": {
59+
"@testing-library/jest-dom": "^5.11.4",
60+
"@testing-library/react": "^11.0.2",
5961
"babel-eslint": "^10.1.0",
6062
"babel-loader": "^8.1.0",
6163
"cross-env": "^7.0.2",
6264
"deep-freeze": "^0.0.1",
6365
"dotenv": "^8.2.0",
64-
"enzyme": "^3.11.0",
65-
"enzyme-adapter-react-16": "^1.15.3",
66-
"enzyme-to-json": "^3.4.4",
6766
"eslint": "^6.8.0",
6867
"eslint-config-airbnb": "^18.2.0",
6968
"eslint-config-prettier": "^6.11.0",
@@ -88,9 +87,6 @@
8887
}
8988
},
9089
"jest": {
91-
"snapshotSerializers": [
92-
"enzyme-to-json/serializer"
93-
],
9490
"collectCoverageFrom": [
9591
"src/**/*.{js,jsx}"
9692
],

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;
Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
import React from 'react';
2-
import DatePicker from 'react-datepicker';
32

43
import DatePickerStyled from '.';
54

65
describe('<DatePickerStyled /> rendering', () => {
76
const onChange = jest.fn();
87

98
it('should render without crashing', () => {
10-
const { component } = shallowWithProviders(
9+
const { component } = renderWithProviders(
1110
<DatePickerStyled
1211
name="test"
1312
dateFormat="en-US"
14-
date={new Date('Thu Nov 12 2020 00:00:00 GMT-0000')}
13+
date={new Date('11/12/2020')}
1514
onChange={onChange}
1615
/>
1716
)({});
1817

19-
expect(component).toMatchSnapshot();
18+
expect(component.asFragment()).toMatchSnapshot();
2019
});
2120

2221
it('should render <DatePicker /> component correctly', () => {
23-
const { component } = mountWithProviders(
22+
const { component } = renderWithProviders(
2423
<DatePickerStyled
2524
name="test"
2625
dateFormat="en-US"
@@ -29,11 +28,11 @@ describe('<DatePickerStyled /> rendering', () => {
2928
/>
3029
)({});
3130

32-
expect(component.exists(DatePicker)).toBeTruthy();
31+
expect(component.container.querySelector('input')).toBeTruthy();
3332
});
3433

3534
it('should pass the date prop to <DatePicker selected={date} /> correctly', () => {
36-
const { component } = mountWithProviders(
35+
const { component } = renderWithProviders(
3736
<DatePickerStyled
3837
name="test"
3938
dateFormat="en-US"
@@ -42,8 +41,6 @@ describe('<DatePickerStyled /> rendering', () => {
4241
/>
4342
)({});
4443

45-
expect(component.find(DatePicker).prop('selected')).toEqual(
46-
new Date('11/12/2020')
47-
);
44+
expect(component.container.querySelector('input').value).toBe('11-12-20');
4845
});
4946
});

0 commit comments

Comments
 (0)