@@ -15,6 +15,7 @@ import configureMockStore from 'redux-mock-store';
15
15
import thunk from 'redux-thunk' ;
16
16
import App from '../../App' ; // Assuming App is the root component
17
17
import AppHeader from '../../src/components/AppHeader' ;
18
+ import ProfileScreen from '../../src/screens/Profile' ;
18
19
19
20
import AppTheme from '../../src/constants/themes' ;
20
21
@@ -32,6 +33,7 @@ const mockStore = configureMockStore(middlewares);
32
33
jest . mock ( '../../src/utils/localStorage.js' , ( ) => ( {
33
34
AsyncStorage : jest . fn ( ) ,
34
35
storeUID : jest . fn ( ) ,
36
+ getUID : jest . fn ( ) ,
35
37
} ) ) ;
36
38
37
39
jest . mock ( '../../firebaseConfig' , ( ) => ( {
@@ -43,6 +45,15 @@ jest.mock('../../firebaseConfig', () => ({
43
45
} ,
44
46
} ) ) ;
45
47
48
+ jest . mock ( '../../firebaseConfig' , ( ) => ( {
49
+ auth : {
50
+ signOut : jest . fn ( ( ) => Promise . resolve ( ) ) ,
51
+ currentUser : {
52
+ displayName : 'John Doe' ,
53
+ } ,
54
+ }
55
+ } ) ) ;
56
+
46
57
jest . mock ( 'firebase/auth' , ( ) => ( {
47
58
createUserWithEmailAndPassword : jest . fn ( ) ,
48
59
updateEmail : jest . fn ( ) ,
@@ -65,20 +76,7 @@ jest.mock('firebase/firestore', () => ({
65
76
setDoc : jest . fn ( ) ,
66
77
doc : jest . fn ( ( ) => ( { setDoc : jest . fn ( ) } ) ) ,
67
78
updateDoc : jest . fn ( ) ,
68
- getDoc : jest . fn ( ) . mockReturnValue ( {
69
- exists : jest . fn ( ) . mockReturnValue ( true ) , // Mock 'exists' as a function
70
- data : jest . fn ( ) . mockReturnValue ( {
71
- height : "6541" ,
72
- weight : "55" ,
73
- age : "666" ,
74
- gender : "male" ,
75
- sports : "running" ,
76
- dob : {
77
- seconds : 1627852800 , // Example timestamp for July 2, 2021
78
- nanoseconds : 0 , // Firestore Timestamps include nanoseconds, but it's often okay to mock them as 0 in tests
79
- } ,
80
- } ) , // Mock 'data' as a function
81
- } ) ,
79
+ getDoc : jest . fn ( ) ,
82
80
} ) ) ;
83
81
84
82
@@ -104,14 +102,6 @@ jest.mock('victory-native', () => {
104
102
useChartPressState : MockUseChartPressState ,
105
103
} ;
106
104
} ) ;
107
- // jest.mock('../../src/actions/appActions', () => ({
108
- // userMetricsDataModalVisible: jest.fn().mockReturnValue({
109
- // type: 'USER_METRICS_DATA_MODAL_VISIBLE',
110
- // payload: {
111
- // visibility: false,
112
- // isFromSignUpScreen: false,
113
- // }}),
114
- // }));
115
105
116
106
// Mocks ViewSleepData
117
107
jest . mock ( 'd3' , ( ) => ( {
@@ -138,36 +128,51 @@ jest.mock('@react-navigation/native', () => {
138
128
goBack : jest . fn ( ) ,
139
129
} ) ,
140
130
useRoute : ( ) => ( {
141
- name : 'Previous Screen' ,
131
+ //name: 'Previous Screen',
132
+ params : {
133
+ previousScreenTitle : 'Home' ,
134
+ } ,
142
135
} ) ,
143
136
} ;
144
137
} ) ;
145
138
146
139
147
140
148
141
149
- const initialState = {
150
- auth : {
151
- uid : '123' ,
152
- displayName : 'John Doe' ,
153
- } ,
154
- user : {
155
- profile : { } ,
156
- metrics : { } ,
157
- } ,
158
- } ;
142
+
143
+
159
144
160
145
describe ( 'User Actions Integration Test' , ( ) => {
161
146
let store ;
162
147
163
148
beforeEach ( ( ) => {
164
- store = mockStore ( initialState ) ;
149
+ jest . spyOn ( console , 'error' ) . mockImplementation ( ( message ) => {
150
+ if ( message . includes ( 'Warning: An update to' ) ) {
151
+ return ;
152
+ }
153
+ console . error ( message ) ;
154
+ } ) ;
155
+
156
+ jest . useFakeTimers ( ) ;
157
+
165
158
} ) ;
166
159
167
160
it ( 'should log out the user' , async ( ) => {
161
+ const initialState = {
162
+ auth : {
163
+ uid : '123' ,
164
+ displayName : 'John Doe' ,
165
+ } ,
166
+ user : {
167
+ profile : { } ,
168
+ metrics : { } ,
169
+ } ,
170
+ } ;
171
+
172
+ store = mockStore ( initialState ) ;
168
173
store . dispatch = jest . fn ( store . dispatch ) ;
169
174
170
- const { getByTestId, queryByText, getAllByTestId , getByText , getAllByRole , debug } = render (
175
+ const { getByTestId, queryByText, debug } = render (
171
176
< Provider store = { store } >
172
177
< PaperProvider >
173
178
< NavigationContainer >
@@ -179,7 +184,7 @@ describe('User Actions Integration Test', () => {
179
184
</ Provider >
180
185
) ;
181
186
182
- debug ( ) ; // Log the rendered output to inspect the component tree
187
+ // debug(); // Log the rendered output to inspect the component tree
183
188
184
189
const menuButton = getByTestId ( "menu-action" ) ;
185
190
@@ -215,6 +220,84 @@ describe('User Actions Integration Test', () => {
215
220
} ) ;
216
221
} ) ;
217
222
223
+
224
+ it ( 'should update the user profile' , async ( ) => {
225
+ store . dispatch = jest . fn ( store . dispatch ) ;
226
+
227
+ const initialState = {
228
+ uuid : null ,
229
+ firstName : null ,
230
+ lastName : null ,
231
+ email : null ,
232
+ authError : null ,
233
+ user : {
234
+ userMetricsData : {
235
+ gender : "No Data" ,
236
+ dob : new Date ( ) ,
237
+ height : "No Data" ,
238
+ weight : "No Data" ,
239
+ sports : "No Data" ,
240
+ } ,
241
+ }
242
+ } ;
243
+
244
+ store = mockStore ( initialState ) ;
245
+ store . dispatch = jest . fn ( store . dispatch ) ;
246
+
247
+ const { getByTestId, queryByText, debug } = render (
248
+ < Provider store = { store } >
249
+ < PaperProvider >
250
+ < NavigationContainer >
251
+ < View >
252
+ < ProfileScreen route = { { params : { previousScreenTitle : 'Home' } } } />
253
+ </ View >
254
+ </ NavigationContainer >
255
+ </ PaperProvider >
256
+ </ Provider >
257
+ ) ;
258
+
259
+ debug ( ) ;
260
+
261
+ const editPersonalButton = getByTestId ( "edit-personal-button" ) ;
262
+ await act ( ( ) => {
263
+ fireEvent . press ( editPersonalButton ) ;
264
+ } ) ;
265
+
266
+ await waitFor ( ( ) => {
267
+ expect ( getByTestId ( "personal-modal-content" ) ) . not . toBeNull ( ) ;
268
+ } ) ;
269
+
270
+ const firstNameInput = getByTestId ( "first-name-input" ) ;
271
+ await act ( ( ) => {
272
+ fireEvent . changeText ( firstNameInput , 'John' ) ;
273
+ } ) ;
274
+
275
+ const lastNameInput = getByTestId ( "last-name-input" ) ;
276
+ await act ( ( ) => {
277
+ fireEvent . changeText ( lastNameInput , 'Doe' ) ;
278
+ } ) ;
279
+
280
+ let savePersonalButton
281
+ await waitFor ( ( ) => {
282
+ savePersonalButton = getByTestId ( "save-personal-button" ) ;
283
+ } ) ;
284
+ await act ( ( ) => {
285
+ fireEvent . press ( savePersonalButton ) ;
286
+ } ) ;
287
+
288
+ //const lastNadfameInput = getByTestId("last-ndfasdfasdame-input");
289
+
290
+ await waitFor ( ( ) => {
291
+ expect ( store . dispatch ) . toHaveBeenCalledWith ( expect . any ( Function ) ) ;
292
+ const actions = store . getActions ( ) ;
293
+ expect ( actions ) . toContainEqual ( {
294
+ type : 'UPDATE_PROFILE' ,
295
+ payload : [ 'John' , 'Doe' ] ,
296
+ } ) ;
297
+ } ) ;
298
+ } ) ;
299
+
300
+
218
301
// it('should update the user profile', async () => {
219
302
// store.dispatch = jest.fn(store.dispatch);
220
303
0 commit comments