Skip to content

Commit 384a320

Browse files
committed
added 3 testcases to appActions - 7/7 Pass
1 parent 117d600 commit 384a320

File tree

1 file changed

+78
-36
lines changed

1 file changed

+78
-36
lines changed

SmartClothingApp/__test__/appActions.test.js

+78-36
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ import configureMockStore from 'redux-mock-store';
22
import thunk from 'redux-thunk';
33
import {
44
userMetricsDataModalVisible,
5-
updateActivityRings,
5+
updateActivityRingsData,
66
updateHeartRateDateRangeData,
77
updateSleepDataDateRangeData,
8+
updateActivityRings,
9+
updateHeartRateDateRange,
10+
updateSleepDataDateRange
811
} from '../src/actions/appActions.js';
912
import {
1013
USER_METRICS_DATA_MODAL_VISIBLE,
@@ -55,6 +58,7 @@ jest.mock('firebase/auth', () => ({
5558

5659

5760
describe('User Metrics Actions', () => {
61+
5862
it('should create an action to toggle user metrics data modal visibility', () => {
5963
const expectedAction = {
6064
type: USER_METRICS_DATA_MODAL_VISIBLE,
@@ -65,6 +69,41 @@ describe('User Metrics Actions', () => {
6569
};
6670
expect(userMetricsDataModalVisible(true, true)).toEqual(expectedAction);
6771
});
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+
});
68107

69108
it('should dispatch actions to update activity rings data', async () => {
70109
const store = mockStore({});
@@ -86,52 +125,55 @@ describe('User Metrics Actions', () => {
86125
}));
87126

88127
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+
});
90133

91-
// Restore the original implementation
92134
Math.random.mockRestore();
135+
93136
}, 10000);
94137

138+
it('should dispatch actions to update heart rate data date range', async () => {
139+
const store = mockStore({});
95140

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)
100143

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+
}
103151

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();
110154

111-
// await store.dispatch(updateActivityRings());
112-
// expect(store.getActions()).toContainEqual(expectedActions[0]);
155+
expect(actions[0]).toEqual(expectedAction);
113156

114-
// // Restore the original implementation
115-
// Math.random.mockRestore();
116-
// }, 10000);
157+
}, 10000);
117158

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)
127164

128-
it('should create an action to update sleep data date range', () => {
129-
const startDate = '2024-01-01';
130-
const endDate = '2024-01-07';
131165
const expectedAction = {
132166
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);
137179
});

0 commit comments

Comments
 (0)