Skip to content

Commit e793a8f

Browse files
committed
appActions and nav-test directory - 4 fails
1 parent 813711e commit e793a8f

File tree

6 files changed

+141
-27
lines changed

6 files changed

+141
-27
lines changed

.github/workflows/main.yml

+9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
1+
# Define the name of the workflow
12
name: Test React Native App testing
23

4+
5+
# Specify the events that trigger the workflow
36
on:
7+
# Trigger the workflow when a pull request is opened, synchronized, or reopened
48
pull_request:
9+
# Allow manually triggering the workflow from the GitHub Actions interface
510
workflow_dispatch:
11+
# Trigger the workflow when code is pushed to branches named "testing"
612
push:
713
branches: [testing]
814

15+
16+
# Define the jobs to run as part of the workflow
917
jobs:
1018
tests:
19+
# Specify the type of runner that the job will run on. "ubuntu-latest" indicates the job will run on the latest version of Ubuntu
1120
runs-on: ubuntu-latest
1221

1322
strategy:

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import { act } from 'react-test-renderer';
77
import { getByText, getByProps, waitFor } from '@testing-library/react-native';
88
import {NavigationContainer} from '@react-navigation/native';
99
import {createStackNavigator} from '@react-navigation/stack';
10-
import configureStore from '../../src/store.js';
10+
import configureStore from '../../../src/store.js';
1111
import {Provider as StoreProvider } from 'react-redux';
1212
import {PaperProvider} from "react-native-paper";
13-
import HomeScreen from '../../src/screens/HomeScreen/index.jsx'
14-
import SettingsScreen from '../../src/screens/Settings/index.jsx'
13+
import HomeScreen from '../../../src/screens/HomeScreen/index.jsx'
14+
import SettingsScreen from '../../../src/screens/Settings/index.jsx'
1515

1616

1717

@@ -74,9 +74,9 @@ jest.mock('firebase/firestore', () => ({
7474
}),
7575
}))
7676

77-
jest.mock('react-native-vector-icons/MaterialIcons', () => require('../__mocks__/react-native-vector-icons').MaterialIcons);
78-
jest.mock('react-native-vector-icons/FontAwesome5', () => require('../__mocks__/react-native-vector-icons').FontAwesome5);
79-
jest.mock('@shopify/react-native-skia', () => require('../__mocks__/@shopify__react-native-skia'));
77+
jest.mock('react-native-vector-icons/MaterialIcons', () => require('../../__mocks__/react-native-vector-icons.js').MaterialIcons);
78+
jest.mock('react-native-vector-icons/FontAwesome5', () => require('../../__mocks__/react-native-vector-icons.js').FontAwesome5);
79+
jest.mock('@shopify/react-native-skia', () => require('../../__mocks__/@shopify__react-native-skia.js'));
8080
jest.mock('../../src/components/visualizations/ActivityRings/Ring.jsx', () => {
8181
return jest.fn(({ ring, center, strokeWidth, scale }) => (
8282
<div>

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

+10-10
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ import { act } from 'react-test-renderer';
77
import { getByText, getByProps, waitFor } from '@testing-library/react-native';
88
import {NavigationContainer} from '@react-navigation/native';
99
import {createStackNavigator} from '@react-navigation/stack';
10-
import configureStore from '../../src/store.js';
11-
import rootReducer from '../../src/store.js';
12-
import AppRouter from '../../src/navigation/index.js';
10+
import configureStore from '../../../src/store.js';
11+
import rootReducer from '../../../src/store.js';
12+
import AppRouter from '../../../src/navigation/index.js';
1313
import {Provider as StoreProvider } from 'react-redux';
1414
import {PaperProvider} from "react-native-paper";
1515

1616

1717

1818

19-
jest.mock('../../src/utils/localStorage.js', () => ({
19+
jest.mock('../../../src/utils/localStorage.js', () => ({
2020
AsyncStorage: jest.fn(),
2121
}));
2222

2323
// Mock Firebase Authentication
24-
jest.mock('../../firebaseConfig.js', () => ({
24+
jest.mock('../../../firebaseConfig.js', () => ({
2525
auth: {
2626
loginWithEmail: jest.fn(() => Promise.resolve()),
2727
startLoginWithEmail: jest.fn(() => Promise.resolve()),
@@ -57,7 +57,7 @@ jest.mock('firebase/auth', () => ({
5757
})),
5858
}))
5959

60-
jest.mock('../../src/utils/localStorage.js', () => ({
60+
jest.mock('../../../src/utils/localStorage.js', () => ({
6161
storeUID: jest.fn(),
6262
}))
6363

@@ -83,10 +83,10 @@ jest.mock('firebase/firestore', () => ({
8383
}),
8484
}))
8585

86-
jest.mock('react-native-vector-icons/MaterialIcons', () => require('../__mocks__/react-native-vector-icons').MaterialIcons);
87-
jest.mock('react-native-vector-icons/FontAwesome5', () => require('../__mocks__/react-native-vector-icons').FontAwesome5);
88-
jest.mock('@shopify/react-native-skia', () => require('../__mocks__/@shopify__react-native-skia'));
89-
jest.mock('../../src/components/visualizations/ActivityRings/Ring.jsx', () => {
86+
jest.mock('react-native-vector-icons/MaterialIcons', () => require('../../__mocks__/react-native-vector-icons.js').MaterialIcons);
87+
jest.mock('react-native-vector-icons/FontAwesome5', () => require('../../__mocks__/react-native-vector-icons.js').FontAwesome5);
88+
jest.mock('@shopify/react-native-skia', () => require('../../__mocks__/@shopify__react-native-skia.js'));
89+
jest.mock('../../../src/components/visualizations/ActivityRings/Ring.jsx', () => {
9090
return jest.fn(({ ring, center, strokeWidth, scale }) => (
9191
<div>
9292
Mock Ring Component - {ring.size}, {center.x}, {center.y}, {strokeWidth}, {scale}

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

+11-11
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ import { act } from 'react-test-renderer';
77
import { getByText, getByProps, waitFor } from '@testing-library/react-native';
88
import {NavigationContainer} from '@react-navigation/native';
99
import {createStackNavigator} from '@react-navigation/stack';
10-
import configureStore from '../../src/store.js';
11-
import rootReducer from '../../src/store.js';
12-
import AppRouter from '../../src/navigation/index.js';
10+
import configureStore from '../../../src/store.js';
11+
import rootReducer from '../../../src/store.js';
12+
import AppRouter from '../../../src/navigation/index.js';
1313
import {Provider as StoreProvider } from 'react-redux';
1414
import {PaperProvider} from "react-native-paper";
1515

1616

1717

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

40-
jest.mock('../../src/utils/localStorage.js', () => ({
40+
jest.mock('../../../src/utils/localStorage.js', () => ({
4141
AsyncStorage: jest.fn(),
4242
}));
4343

@@ -70,7 +70,7 @@ jest.mock('firebase/auth', () => ({
7070
// isFromSignUpScreen: true,
7171
// }),
7272
// }));
73-
jest.mock('../../src/actions/appActions.js', () => {
73+
jest.mock('../../../src/actions/appActions.js', () => {
7474
return {
7575
...jest.requireActual('../../src/actions/appActions.js'), // if you want to keep the original implementations of other functions
7676
userMetricsDataModalVisible: jest.fn((visibility, isFromSignUpScreen = true) => {
@@ -105,10 +105,10 @@ jest.mock('firebase/firestore', () => ({
105105
}),
106106
}))
107107

108-
jest.mock('react-native-vector-icons/MaterialIcons', () => require('../__mocks__/react-native-vector-icons').MaterialIcons);
109-
jest.mock('react-native-vector-icons/FontAwesome5', () => require('../__mocks__/react-native-vector-icons').FontAwesome5);
110-
jest.mock('@shopify/react-native-skia', () => require('../__mocks__/@shopify__react-native-skia'));
111-
jest.mock('../../src/components/visualizations/ActivityRings/Ring.jsx', () => {
108+
jest.mock('react-native-vector-icons/MaterialIcons', () => require('../../__mocks__/react-native-vector-icons.js').MaterialIcons);
109+
jest.mock('react-native-vector-icons/FontAwesome5', () => require('../../__mocks__/react-native-vector-icons.js').FontAwesome5);
110+
jest.mock('@shopify/react-native-skia', () => require('../../__mocks__/@shopify__react-native-skia.js'));
111+
jest.mock('../../../src/components/visualizations/ActivityRings/Ring.jsx', () => {
112112
return jest.fn(({ ring, center, strokeWidth, scale }) => (
113113
<div>
114114
Mock Ring Component - {ring.size}, {center.x}, {center.y}, {strokeWidth}, {scale}
@@ -127,7 +127,7 @@ jest.mock('victory-native', () => {
127127
useChartPressState: MockUseChartPressState,
128128
};
129129
});
130-
jest.mock('../../src/actions/appActions', () => ({
130+
jest.mock('../../../src/actions/appActions', () => ({
131131
userMetricsDataModalVisible: jest.fn().mockReturnValue({
132132
type: 'USER_METRICS_DATA_MODAL_VISIBLE',
133133
payload: {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import configureMockStore from 'redux-mock-store';
2+
import thunk from 'redux-thunk';
3+
import {
4+
userMetricsDataModalVisible,
5+
updateActivityRings,
6+
updateHeartRateDateRangeData,
7+
updateSleepDataDateRangeData,
8+
} from '../src/actions/userActions.js';
9+
import {
10+
USER_METRICS_DATA_MODAL_VISIBLE,
11+
UPDATE_ACTIVITY_RINGS_DATA,
12+
UPDATE_HEART_RATE_DATE_RANGE,
13+
UPDATE_SLEEP_DATA_DATE_RANGE,
14+
} from '../src/actions/types.js';
15+
16+
const middlewares = [thunk];
17+
const mockStore = configureMockStore(middlewares);
18+
19+
jest.mock('../src/utils/localStorage.js', () => ({
20+
AsyncStorage: jest.fn(),
21+
}));
22+
jest.mock('firebase/firestore', () => ({
23+
collection: jest.fn(),
24+
addDoc: jest.fn(),
25+
setDoc: jest.fn(),
26+
doc: jest.fn(),
27+
updateDoc: jest.fn(),
28+
getDoc: jest.fn(),
29+
updateEmail: jest.fn(),
30+
}));
31+
jest.mock('../firebaseConfig.js', () => ({
32+
auth: {
33+
signOut: jest.fn(() => Promise.resolve()),
34+
currentUser: {
35+
displayName: 'John Doe',
36+
},
37+
},
38+
}));
39+
jest.mock('firebase/auth', () => ({
40+
createUserWithEmailAndPassword: jest.fn(),
41+
updateEmail: jest.fn(),
42+
signInWithEmailAndPassword: jest.fn(),
43+
updateProfile: jest.fn(() => Promise.resolve()), // Mock the updateProfile function
44+
sendPasswordResetEmail: jest.fn(),
45+
auth: {
46+
updateEmail: jest.fn(),
47+
},
48+
}));
49+
50+
51+
52+
describe('User Metrics Actions', () => {
53+
it('should create an action to toggle user metrics data modal visibility', () => {
54+
const expectedAction = {
55+
type: USER_METRICS_DATA_MODAL_VISIBLE,
56+
payload: {
57+
visibility: true,
58+
isFromSignUpScreen: true,
59+
},
60+
};
61+
expect(userMetricsDataModalVisible(true, true)).toEqual(expectedAction);
62+
});
63+
64+
it('should dispatch actions to update activity rings data', async () => {
65+
const store = mockStore({});
66+
const day = 'Monday';
67+
const ringData = { ring1: '1.0', ring2: '1.5', ring3: '0.5' };
68+
69+
// Mock the random value generator if necessary or ensure predictable output for tests
70+
jest.spyOn(Math, 'random').mockReturnValue(0.5);
71+
72+
const expectedActions = [
73+
{
74+
type: UPDATE_ACTIVITY_RINGS_DATA,
75+
payload: { day, rings: ringData },
76+
},
77+
];
78+
79+
await store.dispatch(updateActivityRings());
80+
expect(store.getActions()).toContainEqual(expectedActions[0]);
81+
82+
// Restore the original implementation
83+
Math.random.mockRestore();
84+
});
85+
86+
it('should create an action to update heart rate date range', () => {
87+
const startDate = '2024-01-01';
88+
const endDate = '2024-01-07';
89+
const expectedAction = {
90+
type: UPDATE_HEART_RATE_DATE_RANGE,
91+
payload: { startDate, endDate },
92+
};
93+
expect(updateHeartRateDateRangeData(startDate, endDate)).toEqual(expectedAction);
94+
});
95+
96+
it('should create an action to update sleep data date range', () => {
97+
const startDate = '2024-01-01';
98+
const endDate = '2024-01-07';
99+
const expectedAction = {
100+
type: UPDATE_SLEEP_DATA_DATE_RANGE,
101+
payload: { startDate, endDate },
102+
};
103+
expect(updateSleepDataDateRangeData(startDate, endDate)).toEqual(expectedAction);
104+
});
105+
});

0 commit comments

Comments
 (0)