@@ -5,47 +5,52 @@ import {
5
5
updateActivityRings ,
6
6
updateHeartRateDateRangeData ,
7
7
updateSleepDataDateRangeData ,
8
- } from '../src/actions/userActions .js' ;
8
+ } from '../src/actions/appActions .js' ;
9
9
import {
10
10
USER_METRICS_DATA_MODAL_VISIBLE ,
11
11
UPDATE_ACTIVITY_RINGS_DATA ,
12
12
UPDATE_HEART_RATE_DATE_RANGE ,
13
13
UPDATE_SLEEP_DATA_DATE_RANGE ,
14
14
} from '../src/actions/types.js' ;
15
15
16
+ console . log ( userMetricsDataModalVisible ) ;
17
+
16
18
const middlewares = [ thunk ] ;
17
19
const mockStore = configureMockStore ( middlewares ) ;
18
20
19
21
jest . mock ( '../src/utils/localStorage.js' , ( ) => ( {
20
22
AsyncStorage : jest . fn ( ) ,
21
23
} ) ) ;
22
- jest . mock ( 'firebase/firestore' , ( ) => ( {
24
+
25
+ jest . mock ( 'firebase/firestore' , ( ) => ( {
23
26
collection : jest . fn ( ) ,
24
27
addDoc : jest . fn ( ) ,
25
28
setDoc : jest . fn ( ) ,
26
29
doc : jest . fn ( ) ,
27
30
updateDoc : jest . fn ( ) ,
28
31
getDoc : jest . fn ( ) ,
29
- updateEmail : jest . fn ( ) ,
30
- } ) ) ;
31
- jest . mock ( '../firebaseConfig.js' , ( ) => ( {
32
+ //updateEmail: jest.fn(),
33
+ } ) ) ;
34
+
35
+ jest . mock ( '../firebaseConfig.js' , ( ) => ( {
32
36
auth : {
33
- signOut : jest . fn ( ( ) => Promise . resolve ( ) ) ,
37
+ // signOut: jest.fn(() => Promise.resolve()),
34
38
currentUser : {
35
39
displayName : 'John Doe' ,
36
40
} ,
37
41
} ,
38
42
} ) ) ;
39
- jest . mock ( 'firebase/auth' , ( ) => ( {
43
+
44
+ jest . mock ( 'firebase/auth' , ( ) => ( {
40
45
createUserWithEmailAndPassword : jest . fn ( ) ,
41
46
updateEmail : jest . fn ( ) ,
42
47
signInWithEmailAndPassword : jest . fn ( ) ,
43
- updateProfile : jest . fn ( ( ) => Promise . resolve ( ) ) , // Mock the updateProfile function
48
+ updateProfile : jest . fn ( ) ,
44
49
sendPasswordResetEmail : jest . fn ( ) ,
45
50
auth : {
46
51
updateEmail : jest . fn ( ) ,
47
52
} ,
48
- } ) ) ;
53
+ } ) ) ;
49
54
50
55
51
56
@@ -63,25 +68,52 @@ describe('User Metrics Actions', () => {
63
68
64
69
it ( 'should dispatch actions to update activity rings data' , async ( ) => {
65
70
const store = mockStore ( { } ) ;
66
- const day = 'Monday' ;
67
- const ringData = { ring1 : '1.0' , ring2 : '1.5' , ring3 : '0.5' } ;
71
+ const daysOfWeek = [
72
+ 'Sunday' , 'Monday' , 'Tuesday' , 'Wednesday' , 'Thursday' , 'Friday' , 'Saturday'
73
+ ] ;
74
+
75
+ const ringData = { ring1 : '1.0' , ring2 : '1.0' , ring3 : '1.0' } ;
68
76
69
77
// Mock the random value generator if necessary or ensure predictable output for tests
70
78
jest . spyOn ( Math , 'random' ) . mockReturnValue ( 0.5 ) ;
71
79
72
- const expectedActions = [
73
- {
74
- type : UPDATE_ACTIVITY_RINGS_DATA ,
75
- payload : { day, rings : ringData } ,
76
- } ,
77
- ] ;
80
+ const expectedActions = daysOfWeek . map ( day => ( {
81
+ type : UPDATE_ACTIVITY_RINGS_DATA ,
82
+ payload : {
83
+ day,
84
+ rings : ringData
85
+ }
86
+ } ) ) ;
78
87
79
88
await store . dispatch ( updateActivityRings ( ) ) ;
80
89
expect ( store . getActions ( ) ) . toContainEqual ( expectedActions [ 0 ] ) ;
81
90
82
91
// Restore the original implementation
83
92
Math . random . mockRestore ( ) ;
84
- } ) ;
93
+ } , 10000 ) ;
94
+
95
+
96
+ // it('should dispatch actions to update activity rings data', async () => {
97
+ // const store = mockStore({});
98
+ // const day = 'Monday';
99
+ // const ringData = { ring1: '1.0', ring2: '1.5', ring3: '0.5' };
100
+
101
+ // // Mock the random value generator if necessary or ensure predictable output for tests
102
+ // jest.spyOn(Math, 'random').mockReturnValue(0.5);
103
+
104
+ // const expectedActions = [
105
+ // {
106
+ // type: UPDATE_ACTIVITY_RINGS_DATA,
107
+ // payload: { day, rings: ringData },
108
+ // },
109
+ // ];
110
+
111
+ // await store.dispatch(updateActivityRings());
112
+ // expect(store.getActions()).toContainEqual(expectedActions[0]);
113
+
114
+ // // Restore the original implementation
115
+ // Math.random.mockRestore();
116
+ // }, 10000);
85
117
86
118
it ( 'should create an action to update heart rate date range' , ( ) => {
87
119
const startDate = '2024-01-01' ;
0 commit comments