Skip to content

Commit cc45c1b

Browse files
committed
__unit-test__ all commented for jsdocs
1 parent 6a33662 commit cc45c1b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+18874
-50
lines changed

SmartClothingApp/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ android/
1717

1818
# Temporary files created by Metro to check the health of the file watcher
1919
.metro-health-check*
20+
21+
# Until format is fixed
22+
docs/

SmartClothingApp/__test__/__unit-test__/__actions-test__/appActions.unit.test.js

+104-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
/**
2+
* Unit tests for app actions in the Smart Clothing App.
3+
*
4+
* This test file includes test cases for actions related to app-level state management,
5+
* such as managing user metrics modal visibility, updating activity ring data, and
6+
* updating heart rate and sleep data date ranges. These tests ensure that each action
7+
* is dispatched correctly and that the appropriate payloads are passed to reducers.
8+
*
9+
* Mocks:
10+
* - Firebase Firestore methods (getDoc, setDoc, etc.)
11+
* - AsyncStorage (local storage mock)
12+
* - Firebase Authentication methods (updateEmail, updateProfile, etc.)
13+
*
14+
* Global mocks and setup are done via jest to simulate database, authentication,
15+
* and local storage services.
16+
*
17+
* Thunks for async actions are tested to verify proper dispatch behavior, with
18+
* mock data and conditions ensuring each action triggers as expected.
19+
*
20+
* @file appActions.unit.test.js
21+
*
22+
* Credit: Carlos Figueroa (github @cfiguer055)
23+
*/
24+
125
import configureMockStore from 'redux-mock-store';
226
import thunk from 'redux-thunk';
327
import {
@@ -16,11 +40,15 @@ import {
1640
UPDATE_SLEEP_DATA_DATE_RANGE,
1741
} from '../../../src/actions/types.js';
1842

19-
console.log(userMetricsDataModalVisible);
2043

44+
45+
46+
47+
// Middleware and store setup
2148
const middlewares = [thunk];
2249
const mockStore = configureMockStore(middlewares);
2350

51+
// Mock Firebase dependencies and AsyncStorage
2452
jest.mock('../../../src/utils/localStorage.js', () => ({
2553
AsyncStorage: jest.fn(),
2654
}));
@@ -57,8 +85,36 @@ jest.mock('firebase/auth', () => ({
5785

5886

5987

88+
/**
89+
* Unit tests for app actions in Smart Clothing app.
90+
*
91+
* Test suite: User Metrics Actions
92+
*
93+
* This suite tests all the actions related to user metrics in the app. It verifies that actions
94+
* like toggling the metrics modal visibility, updating activity rings, and updating date ranges
95+
* for heart rate and sleep data behave as expected.
96+
*
97+
* This suite of tests validates the Redux actions for the app, including those that:
98+
* - Modify the visibility of user metrics modals, update activity rings, and update
99+
* date ranges for heart rate and sleep data.
100+
* - It ensures that each action is dispatched correctly, and the reducers will be updated
101+
* as expected.
102+
*
103+
* Mocks are set up for Firebase Firestore and AsyncStorage to simulate database interactions.
104+
*
105+
* @test {userMetricsDataModalVisible} Action to update user metrics modal visibility.
106+
* @test {updateActivityRingsData} Action to update activity rings data.
107+
* @test {updateHeartRateDateRangeData} Action to update heart rate data range.
108+
*/
60109
describe('User Metrics Actions', () => {
61110

111+
/**
112+
* Test case: Should create an action to toggle user metrics data modal visibility
113+
*
114+
* This test validates that the `userMetricsDataModalVisible` action creator produces
115+
* the correct action object when passed the visibility state and sign-up screen flag.
116+
* @test {userMetricsDataModalVisible}
117+
*/
62118
it('should create an action to toggle user metrics data modal visibility', () => {
63119
const expectedAction = {
64120
type: USER_METRICS_DATA_MODAL_VISIBLE,
@@ -70,6 +126,13 @@ describe('User Metrics Actions', () => {
70126
expect(userMetricsDataModalVisible(true, true)).toEqual(expectedAction);
71127
});
72128

129+
/**
130+
* Test case: Should create an action to update activity ring data for a specific day
131+
*
132+
* This test ensures that `updateActivityRingsData` generates an action with the correct
133+
* payload, including the day of the week and the activity ring data (ring1, ring2, ring3).
134+
* @test {updateActivityRingsData}
135+
*/
73136
it('should create an action to toggle activity ring data', () => {
74137
const day = "Monday"
75138
const ringData = { ring1: '1.0', ring2: '1.0', ring3: '1.0' };
@@ -85,6 +148,13 @@ describe('User Metrics Actions', () => {
85148
expect(updateActivityRingsData(day, ringData)).toEqual(expectedAction);
86149
});
87150

151+
/**
152+
* Test case: Should create an action to update heart rate date range
153+
*
154+
* This test validates that the `updateHeartRateDateRangeData` action creator produces
155+
* the correct action object with the start and end dates for the heart rate data.
156+
* @test {updateHeartRateDateRangeData}
157+
*/
88158
it('should create an action to update heart rate date range', () => {
89159
const startDate = '2024-01-01';
90160
const endDate = '2024-01-07';
@@ -95,6 +165,13 @@ describe('User Metrics Actions', () => {
95165
expect(updateHeartRateDateRangeData(startDate, endDate)).toEqual(expectedAction);
96166
});
97167

168+
/**
169+
* Test case: Should create an action to update sleep data date range
170+
*
171+
* This test ensures that `updateSleepDataDateRangeData` correctly dispatches an action
172+
* with the provided start and end dates for the sleep data.
173+
* @test {updateSleepDataDateRangeData}
174+
*/
98175
it('should create an action to update sleep data date range', () => {
99176
const startDate = '2024-01-01';
100177
const endDate = '2024-01-07';
@@ -105,6 +182,14 @@ describe('User Metrics Actions', () => {
105182
expect(updateSleepDataDateRangeData(startDate, endDate)).toEqual(expectedAction);
106183
});
107184

185+
/**
186+
* Test case: Should dispatch actions to update activity rings data for each day of the week
187+
*
188+
* This test simulates the `updateActivityRings` thunk, which dispatches activity ring data
189+
* for each day of the week. It ensures that all actions are dispatched with the correct
190+
* data after the asynchronous operation completes.
191+
* @test {updateActivityRings}
192+
*/
108193
it('should dispatch actions to update activity rings data', async () => {
109194
const store = mockStore({});
110195
const daysOfWeek = [
@@ -124,17 +209,27 @@ describe('User Metrics Actions', () => {
124209
}
125210
}));
126211

212+
// Dispatch the thunk action
127213
await store.dispatch(updateActivityRings());
128214
const actions = store.getActions();
129215

216+
// Verify that each action is dispatched correctly
130217
expectedActions.forEach((expectedAction, index) => {
131218
expect(actions[index]).toEqual(expectedAction);
132219
});
133220

221+
// Restore Math.random to its original implementation
134222
Math.random.mockRestore();
135-
136223
}, 10000);
137224

225+
/**
226+
* Test case: Should dispatch actions to update heart rate data date range
227+
*
228+
* This test validates the `updateHeartRateDateRange` thunk, ensuring that the start and
229+
* end dates for the heart rate data are correctly dispatched.
230+
* @test {updateHeartRateDateRange}
231+
*/
232+
138233
it('should dispatch actions to update heart rate data date range', async () => {
139234
const store = mockStore({});
140235

@@ -156,6 +251,13 @@ describe('User Metrics Actions', () => {
156251

157252
}, 10000);
158253

254+
/**
255+
* Test case: Should dispatch actions to update sleep data date range
256+
*
257+
* This test ensures that `updateSleepDataDateRange` correctly dispatches the action
258+
* with the provided start and end dates for the sleep data.
259+
* @test {updateSleepDataDateRange}
260+
*/
159261
it('should dispatch actions to update sleep data date range', async () => {
160262
const store = mockStore({});
161263

0 commit comments

Comments
 (0)