@@ -2,9 +2,12 @@ import configureMockStore from 'redux-mock-store';
2
2
import thunk from 'redux-thunk' ;
3
3
import {
4
4
userMetricsDataModalVisible ,
5
- updateActivityRings ,
5
+ updateActivityRingsData ,
6
6
updateHeartRateDateRangeData ,
7
7
updateSleepDataDateRangeData ,
8
+ updateActivityRings ,
9
+ updateHeartRateDateRange ,
10
+ updateSleepDataDateRange
8
11
} from '../src/actions/appActions.js' ;
9
12
import {
10
13
USER_METRICS_DATA_MODAL_VISIBLE ,
@@ -55,6 +58,7 @@ jest.mock('firebase/auth', () => ({
55
58
56
59
57
60
describe ( 'User Metrics Actions' , ( ) => {
61
+
58
62
it ( 'should create an action to toggle user metrics data modal visibility' , ( ) => {
59
63
const expectedAction = {
60
64
type : USER_METRICS_DATA_MODAL_VISIBLE ,
@@ -65,6 +69,41 @@ describe('User Metrics Actions', () => {
65
69
} ;
66
70
expect ( userMetricsDataModalVisible ( true , true ) ) . toEqual ( expectedAction ) ;
67
71
} ) ;
72
+
73
+ it ( 'should create an action to toggle activity ring data' , ( ) => {
74
+ const day = "Monday"
75
+ const ringData = { ring1 : '1.0' , ring2 : '1.0' , ring3 : '1.0' } ;
76
+
77
+ const expectedAction = {
78
+ type : UPDATE_ACTIVITY_RINGS_DATA ,
79
+ payload : {
80
+ day : day ,
81
+ rings : ringData
82
+ }
83
+ }
84
+
85
+ expect ( updateActivityRingsData ( day , ringData ) ) . toEqual ( expectedAction ) ;
86
+ } ) ;
87
+
88
+ it ( 'should create an action to update heart rate date range' , ( ) => {
89
+ const startDate = '2024-01-01' ;
90
+ const endDate = '2024-01-07' ;
91
+ const expectedAction = {
92
+ type : UPDATE_HEART_RATE_DATE_RANGE ,
93
+ payload : { startDate, endDate } ,
94
+ } ;
95
+ expect ( updateHeartRateDateRangeData ( startDate , endDate ) ) . toEqual ( expectedAction ) ;
96
+ } ) ;
97
+
98
+ it ( 'should create an action to update sleep data date range' , ( ) => {
99
+ const startDate = '2024-01-01' ;
100
+ const endDate = '2024-01-07' ;
101
+ const expectedAction = {
102
+ type : UPDATE_SLEEP_DATA_DATE_RANGE ,
103
+ payload : { startDate, endDate } ,
104
+ } ;
105
+ expect ( updateSleepDataDateRangeData ( startDate , endDate ) ) . toEqual ( expectedAction ) ;
106
+ } ) ;
68
107
69
108
it ( 'should dispatch actions to update activity rings data' , async ( ) => {
70
109
const store = mockStore ( { } ) ;
@@ -86,52 +125,55 @@ describe('User Metrics Actions', () => {
86
125
} ) ) ;
87
126
88
127
await store . dispatch ( updateActivityRings ( ) ) ;
89
- expect ( store . getActions ( ) ) . toContainEqual ( expectedActions [ 0 ] ) ;
128
+ const actions = store . getActions ( ) ;
129
+
130
+ expectedActions . forEach ( ( expectedAction , index ) => {
131
+ expect ( actions [ index ] ) . toEqual ( expectedAction ) ;
132
+ } ) ;
90
133
91
- // Restore the original implementation
92
134
Math . random . mockRestore ( ) ;
135
+
93
136
} , 10000 ) ;
94
137
138
+ it ( 'should dispatch actions to update heart rate data date range' , async ( ) => {
139
+ const store = mockStore ( { } ) ;
95
140
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' };
141
+ const startDate = new Date ( 2024 , 6 , 9 )
142
+ const endDate = new Date ( 2024 , 6 , 15 )
100
143
101
- // // Mock the random value generator if necessary or ensure predictable output for tests
102
- // jest.spyOn(Math, 'random').mockReturnValue(0.5);
144
+ const expectedAction = {
145
+ type : UPDATE_HEART_RATE_DATE_RANGE ,
146
+ payload : {
147
+ startDate : startDate ,
148
+ endDate : endDate
149
+ }
150
+ }
103
151
104
- // const expectedActions = [
105
- // {
106
- // type: UPDATE_ACTIVITY_RINGS_DATA,
107
- // payload: { day, rings: ringData },
108
- // },
109
- // ];
152
+ await store . dispatch ( updateHeartRateDateRange ( startDate , endDate ) ) ;
153
+ const actions = store . getActions ( ) ;
110
154
111
- // await store.dispatch(updateActivityRings());
112
- // expect(store.getActions()).toContainEqual(expectedActions[0]);
155
+ expect ( actions [ 0 ] ) . toEqual ( expectedAction ) ;
113
156
114
- // // Restore the original implementation
115
- // Math.random.mockRestore();
116
- // }, 10000);
157
+ } , 10000 ) ;
117
158
118
- it ( 'should create an action to update heart rate date range' , ( ) => {
119
- const startDate = '2024-01-01' ;
120
- const endDate = '2024-01-07' ;
121
- const expectedAction = {
122
- type : UPDATE_HEART_RATE_DATE_RANGE ,
123
- payload : { startDate, endDate } ,
124
- } ;
125
- expect ( updateHeartRateDateRangeData ( startDate , endDate ) ) . toEqual ( expectedAction ) ;
126
- } ) ;
159
+ it ( 'should dispatch actions to update sleep data date range' , async ( ) => {
160
+ const store = mockStore ( { } ) ;
161
+
162
+ const startDate = new Date ( 2024 , 6 , 9 )
163
+ const endDate = new Date ( 2024 , 6 , 15 )
127
164
128
- it ( 'should create an action to update sleep data date range' , ( ) => {
129
- const startDate = '2024-01-01' ;
130
- const endDate = '2024-01-07' ;
131
165
const expectedAction = {
132
166
type : UPDATE_SLEEP_DATA_DATE_RANGE ,
133
- payload : { startDate, endDate } ,
134
- } ;
135
- expect ( updateSleepDataDateRangeData ( startDate , endDate ) ) . toEqual ( expectedAction ) ;
136
- } ) ;
167
+ payload : {
168
+ startDate : startDate ,
169
+ endDate : endDate
170
+ }
171
+ }
172
+
173
+ await store . dispatch ( updateSleepDataDateRange ( startDate , endDate ) ) ;
174
+ const actions = store . getActions ( ) ;
175
+
176
+ expect ( actions [ 0 ] ) . toEqual ( expectedAction ) ;
177
+
178
+ } , 10000 ) ;
137
179
} ) ;
0 commit comments