Skip to content

Commit 117d600

Browse files
committed
appActions 4/4 pass
1 parent 741d57c commit 117d600

File tree

3 files changed

+62
-30
lines changed

3 files changed

+62
-30
lines changed

SmartClothingApp/__test__/__integration-test__/navigation-test__/HomeToProfile.test.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from 'react';
22
import { NavigationContainer } from '@react-navigation/native';
33
import { createStackNavigator } from '@react-navigation/stack';
4-
import HomeScreen from '../../src/screens/HomeScreen/index.jsx';
5-
import ProfileScreen from '../../src/screens/Profile/index.jsx';
6-
import configureStore from '../../src/store.js';
4+
import HomeScreen from '../../../src/screens/HomeScreen/index.jsx';
5+
import ProfileScreen from '../../../src/screens/Profile/index.jsx';
6+
import configureStore from '../../../src/store.js';
77
import {Provider as StoreProvider } from 'react-redux';
88
import {PaperProvider} from "react-native-paper";
99
import { render } from '@testing-library/react-native';
@@ -16,7 +16,7 @@ import { act } from 'react-test-renderer';
1616
const Stack = createStackNavigator();
1717

1818
// Mock Firebase Authentication
19-
jest.mock('../../firebaseConfig.js', () => ({
19+
jest.mock('../../../firebaseConfig.js', () => ({
2020
auth: {
2121
loginWithEmail: jest.fn(() => Promise.resolve()),
2222
startLoginWithEmail: jest.fn(() => Promise.resolve()),
@@ -43,7 +43,7 @@ jest.mock('firebase/auth', () => ({
4343
getDatabase: jest.fn(),
4444
}))
4545

46-
jest.mock('../../src/utils/localStorage.js', () => ({
46+
jest.mock('../../../src/utils/localStorage.js', () => ({
4747
AsyncStorage: jest.fn(),
4848
storeUID: jest.fn(),
4949
getUID: jest.fn(),
@@ -67,10 +67,10 @@ jest.mock('firebase/firestore', () => ({
6767
}),
6868
}))
6969

70-
jest.mock('react-native-vector-icons/MaterialIcons', () => require('../__mocks__/react-native-vector-icons').MaterialIcons);
71-
jest.mock('react-native-vector-icons/FontAwesome5', () => require('../__mocks__/react-native-vector-icons').FontAwesome5);
72-
jest.mock('@shopify/react-native-skia', () => require('../__mocks__/@shopify__react-native-skia'));
73-
jest.mock('../../src/components/visualizations/ActivityRings/Ring.jsx', () => {
70+
jest.mock('react-native-vector-icons/MaterialIcons', () => require('../../__mocks__/react-native-vector-icons.js').MaterialIcons);
71+
jest.mock('react-native-vector-icons/FontAwesome5', () => require('../../__mocks__/react-native-vector-icons.js').FontAwesome5);
72+
jest.mock('@shopify/react-native-skia', () => require('../../__mocks__/@shopify__react-native-skia.js'));
73+
jest.mock('../../../src/components/visualizations/ActivityRings/Ring.jsx', () => {
7474
return jest.fn(({ ring, center, strokeWidth, scale }) => (
7575
<div>
7676
Mock Ring Component - {ring.size}, {center.x}, {center.y}, {strokeWidth}, {scale}

SmartClothingApp/__test__/__integration-test__/navigation-test__/HomeToSettings.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import SettingsScreen from '../../../src/screens/Settings/index.jsx'
1616

1717

1818
// Mock Firebase Authentication
19-
jest.mock('../../firebaseConfig.js', () => ({
19+
jest.mock('../../../firebaseConfig.js', () => ({
2020
auth: {
2121
loginWithEmail: jest.fn(() => Promise.resolve()),
2222
startLoginWithEmail: jest.fn(() => Promise.resolve()),
@@ -36,7 +36,7 @@ jest.mock('../../firebaseConfig.js', () => ({
3636
},
3737
}));
3838

39-
jest.mock('../../src/utils/localStorage.js', () => ({
39+
jest.mock('../../../src/utils/localStorage.js', () => ({
4040
AsyncStorage: jest.fn(),
4141
storeUID: jest.fn(),
4242
getUID: jest.fn(),
@@ -77,7 +77,7 @@ jest.mock('firebase/firestore', () => ({
7777
jest.mock('react-native-vector-icons/MaterialIcons', () => require('../../__mocks__/react-native-vector-icons.js').MaterialIcons);
7878
jest.mock('react-native-vector-icons/FontAwesome5', () => require('../../__mocks__/react-native-vector-icons.js').FontAwesome5);
7979
jest.mock('@shopify/react-native-skia', () => require('../../__mocks__/@shopify__react-native-skia.js'));
80-
jest.mock('../../src/components/visualizations/ActivityRings/Ring.jsx', () => {
80+
jest.mock('../../../src/components/visualizations/ActivityRings/Ring.jsx', () => {
8181
return jest.fn(({ ring, center, strokeWidth, scale }) => (
8282
<div>
8383
Mock Ring Component - {ring.size}, {center.x}, {center.y}, {strokeWidth}, {scale}

SmartClothingApp/__test__/appActions.test.js

+50-18
Original file line numberDiff line numberDiff line change
@@ -5,47 +5,52 @@ import {
55
updateActivityRings,
66
updateHeartRateDateRangeData,
77
updateSleepDataDateRangeData,
8-
} from '../src/actions/userActions.js';
8+
} from '../src/actions/appActions.js';
99
import {
1010
USER_METRICS_DATA_MODAL_VISIBLE,
1111
UPDATE_ACTIVITY_RINGS_DATA,
1212
UPDATE_HEART_RATE_DATE_RANGE,
1313
UPDATE_SLEEP_DATA_DATE_RANGE,
1414
} from '../src/actions/types.js';
1515

16+
console.log(userMetricsDataModalVisible);
17+
1618
const middlewares = [thunk];
1719
const mockStore = configureMockStore(middlewares);
1820

1921
jest.mock('../src/utils/localStorage.js', () => ({
2022
AsyncStorage: jest.fn(),
2123
}));
22-
jest.mock('firebase/firestore', () => ({
24+
25+
jest.mock('firebase/firestore', () => ({
2326
collection: jest.fn(),
2427
addDoc: jest.fn(),
2528
setDoc: jest.fn(),
2629
doc: jest.fn(),
2730
updateDoc: jest.fn(),
2831
getDoc: jest.fn(),
29-
updateEmail: jest.fn(),
30-
}));
31-
jest.mock('../firebaseConfig.js', () => ({
32+
//updateEmail: jest.fn(),
33+
}));
34+
35+
jest.mock('../firebaseConfig.js', () => ({
3236
auth: {
33-
signOut: jest.fn(() => Promise.resolve()),
37+
//signOut: jest.fn(() => Promise.resolve()),
3438
currentUser: {
3539
displayName: 'John Doe',
3640
},
3741
},
3842
}));
39-
jest.mock('firebase/auth', () => ({
43+
44+
jest.mock('firebase/auth', () => ({
4045
createUserWithEmailAndPassword: jest.fn(),
4146
updateEmail: jest.fn(),
4247
signInWithEmailAndPassword: jest.fn(),
43-
updateProfile: jest.fn(() => Promise.resolve()), // Mock the updateProfile function
48+
updateProfile: jest.fn(),
4449
sendPasswordResetEmail: jest.fn(),
4550
auth: {
4651
updateEmail: jest.fn(),
4752
},
48-
}));
53+
}));
4954

5055

5156

@@ -63,25 +68,52 @@ describe('User Metrics Actions', () => {
6368

6469
it('should dispatch actions to update activity rings data', async () => {
6570
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' };
6876

6977
// Mock the random value generator if necessary or ensure predictable output for tests
7078
jest.spyOn(Math, 'random').mockReturnValue(0.5);
7179

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

7988
await store.dispatch(updateActivityRings());
8089
expect(store.getActions()).toContainEqual(expectedActions[0]);
8190

8291
// Restore the original implementation
8392
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);
85117

86118
it('should create an action to update heart rate date range', () => {
87119
const startDate = '2024-01-01';

0 commit comments

Comments
 (0)