1
1
import React from 'react' ;
2
- import TestRenderer from 'react-test-renderer' ;
2
+ import TestRenderer , { act } from 'react-test-renderer' ;
3
3
import { render , fireEvent } from '@testing-library/react' ;
4
4
import { Router } from 'react-router' ;
5
5
import { MemoryRouter } from 'react-router-dom' ;
@@ -26,29 +26,38 @@ describe('routes/Settings.tsx', () => {
26
26
updateSetting . mockReset ( ) ;
27
27
} ) ;
28
28
29
- it ( 'should render itself & its children' , ( ) => {
30
- const tree = TestRenderer . create (
31
- < AppContext . Provider value = { { settings : mockSettings } } >
32
- < MemoryRouter >
33
- < SettingsRoute />
34
- </ MemoryRouter >
35
- </ AppContext . Provider > ,
36
- ) ;
29
+ it ( 'should render itself & its children' , async ( ) => {
30
+ let tree : TestRenderer ;
31
+
32
+ await act ( async ( ) => {
33
+ tree = TestRenderer . create (
34
+ < AppContext . Provider value = { { settings : mockSettings } } >
35
+ < MemoryRouter >
36
+ < SettingsRoute />
37
+ </ MemoryRouter >
38
+ </ AppContext . Provider > ,
39
+ ) ;
40
+ } ) ;
37
41
expect ( tree ) . toMatchSnapshot ( ) ;
38
42
} ) ;
39
43
40
- it ( 'should press the logout' , ( ) => {
44
+ it ( 'should press the logout' , async ( ) => {
41
45
const logoutMock = jest . fn ( ) ;
42
-
43
- const { getByLabelText } = render (
44
- < AppContext . Provider
45
- value = { { settings : mockSettings , logout : logoutMock } }
46
- >
47
- < Router location = { history . location } navigator = { history } >
48
- < SettingsRoute />
49
- </ Router >
50
- </ AppContext . Provider > ,
51
- ) ;
46
+ let getByLabelText ;
47
+
48
+ await act ( async ( ) => {
49
+ const { getByLabelText : getByLabelTextLocal } = render (
50
+ < AppContext . Provider
51
+ value = { { settings : mockSettings , logout : logoutMock } }
52
+ >
53
+ < Router location = { history . location } navigator = { history } >
54
+ < SettingsRoute />
55
+ </ Router >
56
+ </ AppContext . Provider > ,
57
+ ) ;
58
+
59
+ getByLabelText = getByLabelTextLocal ;
60
+ } ) ;
52
61
53
62
fireEvent . click ( getByLabelText ( 'Logout' ) ) ;
54
63
@@ -59,26 +68,37 @@ describe('routes/Settings.tsx', () => {
59
68
expect ( mockNavigate ) . toHaveBeenNthCalledWith ( 1 , - 1 ) ;
60
69
} ) ;
61
70
62
- it ( 'should go back by pressing the icon' , ( ) => {
63
- const { getByLabelText } = render (
64
- < AppContext . Provider value = { { settings : mockSettings } } >
65
- < Router location = { history . location } navigator = { history } >
66
- < SettingsRoute />
67
- </ Router >
68
- </ AppContext . Provider > ,
69
- ) ;
71
+ it ( 'should go back by pressing the icon' , async ( ) => {
72
+ let getByLabelText ;
73
+
74
+ await act ( async ( ) => {
75
+ const { getByLabelText : getByLabelTextLocal } = render (
76
+ < AppContext . Provider value = { { settings : mockSettings } } >
77
+ < Router location = { history . location } navigator = { history } >
78
+ < SettingsRoute />
79
+ </ Router >
80
+ </ AppContext . Provider > ,
81
+ ) ;
82
+
83
+ getByLabelText = getByLabelTextLocal ;
84
+ } ) ;
70
85
fireEvent . click ( getByLabelText ( 'Go Back' ) ) ;
71
86
expect ( mockNavigate ) . toHaveBeenNthCalledWith ( 1 , - 1 ) ;
72
87
} ) ;
73
88
74
- it ( 'should toggle the showOnlyParticipating checkbox' , ( ) => {
75
- const { getByLabelText } = render (
76
- < AppContext . Provider value = { { settings : mockSettings , updateSetting } } >
77
- < MemoryRouter >
78
- < SettingsRoute />
79
- </ MemoryRouter >
80
- </ AppContext . Provider > ,
81
- ) ;
89
+ it ( 'should toggle the showOnlyParticipating checkbox' , async ( ) => {
90
+ let getByLabelText ;
91
+
92
+ await act ( async ( ) => {
93
+ const { getByLabelText : getByLabelTextLocal } = render (
94
+ < AppContext . Provider value = { { settings : mockSettings , updateSetting } } >
95
+ < MemoryRouter >
96
+ < SettingsRoute />
97
+ </ MemoryRouter >
98
+ </ AppContext . Provider > ,
99
+ ) ;
100
+ getByLabelText = getByLabelTextLocal ;
101
+ } ) ;
82
102
83
103
fireEvent . click ( getByLabelText ( 'Show only participating' ) , {
84
104
target : { checked : true } ,
@@ -88,14 +108,19 @@ describe('routes/Settings.tsx', () => {
88
108
expect ( updateSetting ) . toHaveBeenCalledWith ( 'participating' , false ) ;
89
109
} ) ;
90
110
91
- it ( 'should toggle the playSound checkbox' , ( ) => {
92
- const { getByLabelText } = render (
93
- < AppContext . Provider value = { { settings : mockSettings , updateSetting } } >
94
- < MemoryRouter >
95
- < SettingsRoute />
96
- </ MemoryRouter >
97
- </ AppContext . Provider > ,
98
- ) ;
111
+ it ( 'should toggle the playSound checkbox' , async ( ) => {
112
+ let getByLabelText ;
113
+
114
+ await act ( async ( ) => {
115
+ const { getByLabelText : getByLabelTextLocal } = render (
116
+ < AppContext . Provider value = { { settings : mockSettings , updateSetting } } >
117
+ < MemoryRouter >
118
+ < SettingsRoute />
119
+ </ MemoryRouter >
120
+ </ AppContext . Provider > ,
121
+ ) ;
122
+ getByLabelText = getByLabelTextLocal ;
123
+ } ) ;
99
124
100
125
fireEvent . click ( getByLabelText ( 'Play sound' ) , {
101
126
target : { checked : true } ,
@@ -105,14 +130,19 @@ describe('routes/Settings.tsx', () => {
105
130
expect ( updateSetting ) . toHaveBeenCalledWith ( 'playSound' , false ) ;
106
131
} ) ;
107
132
108
- it ( 'should toggle the showNotifications checkbox' , ( ) => {
109
- const { getByLabelText } = render (
110
- < AppContext . Provider value = { { settings : mockSettings , updateSetting } } >
111
- < MemoryRouter >
112
- < SettingsRoute />
113
- </ MemoryRouter >
114
- </ AppContext . Provider > ,
115
- ) ;
133
+ it ( 'should toggle the showNotifications checkbox' , async ( ) => {
134
+ let getByLabelText ;
135
+
136
+ await act ( async ( ) => {
137
+ const { getByLabelText : getByLabelTextLocal } = render (
138
+ < AppContext . Provider value = { { settings : mockSettings , updateSetting } } >
139
+ < MemoryRouter >
140
+ < SettingsRoute />
141
+ </ MemoryRouter >
142
+ </ AppContext . Provider > ,
143
+ ) ;
144
+ getByLabelText = getByLabelTextLocal ;
145
+ } ) ;
116
146
117
147
fireEvent . click ( getByLabelText ( 'Show notifications' ) , {
118
148
target : { checked : true } ,
@@ -122,14 +152,19 @@ describe('routes/Settings.tsx', () => {
122
152
expect ( updateSetting ) . toHaveBeenCalledWith ( 'showNotifications' , false ) ;
123
153
} ) ;
124
154
125
- it ( 'should toggle the onClickMarkAsRead checkbox' , ( ) => {
126
- const { getByLabelText } = render (
127
- < AppContext . Provider value = { { settings : mockSettings , updateSetting } } >
128
- < MemoryRouter >
129
- < SettingsRoute />
130
- </ MemoryRouter >
131
- </ AppContext . Provider > ,
132
- ) ;
155
+ it ( 'should toggle the onClickMarkAsRead checkbox' , async ( ) => {
156
+ let getByLabelText ;
157
+
158
+ await act ( async ( ) => {
159
+ const { getByLabelText : getByLabelTextLocal } = render (
160
+ < AppContext . Provider value = { { settings : mockSettings , updateSetting } } >
161
+ < MemoryRouter >
162
+ < SettingsRoute />
163
+ </ MemoryRouter >
164
+ </ AppContext . Provider > ,
165
+ ) ;
166
+ getByLabelText = getByLabelTextLocal ;
167
+ } ) ;
133
168
134
169
fireEvent . click ( getByLabelText ( 'Mark as read on click' ) , {
135
170
target : { checked : true } ,
@@ -139,14 +174,19 @@ describe('routes/Settings.tsx', () => {
139
174
expect ( updateSetting ) . toHaveBeenCalledWith ( 'markOnClick' , false ) ;
140
175
} ) ;
141
176
142
- it ( 'should toggle the openAtStartup checkbox' , ( ) => {
143
- const { getByLabelText } = render (
144
- < AppContext . Provider value = { { settings : mockSettings , updateSetting } } >
145
- < MemoryRouter >
146
- < SettingsRoute />
147
- </ MemoryRouter >
148
- </ AppContext . Provider > ,
149
- ) ;
177
+ it ( 'should toggle the openAtStartup checkbox' , async ( ) => {
178
+ let getByLabelText ;
179
+
180
+ await act ( async ( ) => {
181
+ const { getByLabelText : getByLabelTextLocal } = render (
182
+ < AppContext . Provider value = { { settings : mockSettings , updateSetting } } >
183
+ < MemoryRouter >
184
+ < SettingsRoute />
185
+ </ MemoryRouter >
186
+ </ AppContext . Provider > ,
187
+ ) ;
188
+ getByLabelText = getByLabelTextLocal ;
189
+ } ) ;
150
190
151
191
fireEvent . click ( getByLabelText ( 'Open at startup' ) , {
152
192
target : { checked : true } ,
@@ -156,43 +196,60 @@ describe('routes/Settings.tsx', () => {
156
196
expect ( updateSetting ) . toHaveBeenCalledWith ( 'openAtStartup' , false ) ;
157
197
} ) ;
158
198
159
- it ( 'should change the appearance radio group' , ( ) => {
160
- const { getByLabelText } = render (
161
- < AppContext . Provider value = { { settings : mockSettings , updateSetting } } >
162
- < MemoryRouter >
163
- < SettingsRoute />
164
- </ MemoryRouter >
165
- </ AppContext . Provider > ,
166
- ) ;
199
+ it ( 'should change the appearance radio group' , async ( ) => {
200
+ let getByLabelText ;
201
+
202
+ await act ( async ( ) => {
203
+ const { getByLabelText : getByLabelTextLocal } = render (
204
+ < AppContext . Provider value = { { settings : mockSettings , updateSetting } } >
205
+ < MemoryRouter >
206
+ < SettingsRoute />
207
+ </ MemoryRouter >
208
+ </ AppContext . Provider > ,
209
+ ) ;
210
+ getByLabelText = getByLabelTextLocal ;
211
+ } ) ;
167
212
168
213
fireEvent . click ( getByLabelText ( 'Light' ) ) ;
169
214
170
215
expect ( updateSetting ) . toHaveBeenCalledTimes ( 1 ) ;
171
216
expect ( updateSetting ) . toHaveBeenCalledWith ( 'appearance' , 'LIGHT' ) ;
172
217
} ) ;
173
218
174
- it ( 'should go to the enterprise login route' , ( ) => {
175
- const { getByLabelText } = render (
176
- < AppContext . Provider value = { { settings : mockSettings } } >
177
- < Router location = { history . location } navigator = { history } >
178
- < SettingsRoute />
179
- </ Router >
180
- </ AppContext . Provider > ,
181
- ) ;
219
+ it ( 'should go to the enterprise login route' , async ( ) => {
220
+ let getByLabelText ;
221
+
222
+ await act ( async ( ) => {
223
+ const { getByLabelText : getByLabelTextLocal } = render (
224
+ < AppContext . Provider value = { { settings : mockSettings } } >
225
+ < Router location = { history . location } navigator = { history } >
226
+ < SettingsRoute />
227
+ </ Router >
228
+ </ AppContext . Provider > ,
229
+ ) ;
230
+ getByLabelText = getByLabelTextLocal ;
231
+ } ) ;
232
+
182
233
fireEvent . click ( getByLabelText ( 'Login with GitHub Enterprise' ) ) ;
183
234
expect ( mockNavigate ) . toHaveBeenNthCalledWith ( 1 , '/login-enterprise' , {
184
235
replace : true ,
185
236
} ) ;
186
237
} ) ;
187
238
188
- it ( 'should quit the app' , ( ) => {
189
- const { getByLabelText } = render (
190
- < AppContext . Provider value = { { settings : mockSettings } } >
191
- < MemoryRouter >
192
- < SettingsRoute />
193
- </ MemoryRouter >
194
- </ AppContext . Provider > ,
195
- ) ;
239
+ it ( 'should quit the app' , async ( ) => {
240
+ let getByLabelText ;
241
+
242
+ await act ( async ( ) => {
243
+ const { getByLabelText : getByLabelTextLocal } = render (
244
+ < AppContext . Provider value = { { settings : mockSettings } } >
245
+ < MemoryRouter >
246
+ < SettingsRoute />
247
+ </ MemoryRouter >
248
+ </ AppContext . Provider > ,
249
+ ) ;
250
+ getByLabelText = getByLabelTextLocal ;
251
+ } ) ;
252
+
196
253
fireEvent . click ( getByLabelText ( 'Quit Gitify' ) ) ;
197
254
expect ( ipcRenderer . send ) . toHaveBeenCalledWith ( 'app-quit' ) ;
198
255
} ) ;
0 commit comments