Skip to content

Commit

Permalink
reorganized __test__ folder structure // all tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
cfiguer055 committed Oct 10, 2024
1 parent ebd90d2 commit 6a33662
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,26 @@ describe('ViewInsights', () => {
}
console.error(message);
});

jest.useFakeTimers();


// Use modern fake timers
jest.useFakeTimers('modern');

// Set a fixed system time
jest.setSystemTime(new Date('2024-06-25T00:00:00Z'));

store = configureStore();


// Mock the DateTimePicker
jest.mock('@react-native-community/datetimepicker', () => 'DateTimePicker');

});

afterEach(() => {
jest.clearAllMocks();
// Restore real timers and clear mocks after each test
jest.useRealTimers();
jest.clearAllMocks();
});



it('renders correctly', () => {
let component;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ import {
updateActivityRings,
updateHeartRateDateRange,
updateSleepDataDateRange
} from '../src/actions/appActions.js';
} from '../../../src/actions/appActions.js';
import {
USER_METRICS_DATA_MODAL_VISIBLE,
UPDATE_ACTIVITY_RINGS_DATA,
UPDATE_HEART_RATE_DATE_RANGE,
UPDATE_SLEEP_DATA_DATE_RANGE,
} from '../src/actions/types.js';
} from '../../../src/actions/types.js';

console.log(userMetricsDataModalVisible);

const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);

jest.mock('../src/utils/localStorage.js', () => ({
jest.mock('../../../src/utils/localStorage.js', () => ({
AsyncStorage: jest.fn(),
}));

Expand All @@ -35,7 +35,7 @@ jest.mock('firebase/firestore', () => ({
//updateEmail: jest.fn(),
}));

jest.mock('../firebaseConfig.js', () => ({
jest.mock('../../../firebaseConfig.js', () => ({
auth: {
//signOut: jest.fn(() => Promise.resolve()),
currentUser: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { auth, database } from '../firebaseConfig.js';
import { auth, database } from '../../../firebaseConfig.js';
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import { firebaseErrorsMessages } from '../src/utils/firebaseErrorsMessages.js';
import { firebaseErrorsMessages } from '../../../src/utils/firebaseErrorsMessages.js';
import { render, waitFor } from "@testing-library/react"
import flushPromises from 'flush-promises';
import { storeUID, storeMetrics } from "../src/utils/localStorage.js";
import { storeUID, storeMetrics } from "../../../src/utils/localStorage.js";
import {
setDoc,
getDoc,
Expand Down Expand Up @@ -33,7 +33,7 @@ import {
queryHeartRateData,
deleteAccount,
logout,
} from '../src/actions/userActions.js';
} from '../../../src/actions/userActions.js';
import {
LOGIN_WITH_EMAIL,
SIGNUP_WITH_EMAIL,
Expand All @@ -42,7 +42,7 @@ import {
UPDATE_USER_METRICS_DATA,
UPDATE_EMAIL_SUCCESS,
UPDATE_PASSWORD_SUCCESS,
} from '../src/actions/types';
} from '../../../src/actions/types.js';
import {
createUserWithEmailAndPassword,
signInWithEmailAndPassword,
Expand All @@ -54,14 +54,14 @@ import {
updatePassword,
signOut,
} from 'firebase/auth';
import { toastError } from "../src/actions/toastActions.js";
import { toastError } from "../../../src/actions/toastActions.js";
import {
userMetricsDataModalVisible
} from '../src/actions/appActions';
} from '../../../src/actions/appActions.js';
import { type } from '@testing-library/react-native/build/user-event/type/type.js';


jest.mock('../src/utils/localStorage.js', () => ({
jest.mock('../../../src/utils/localStorage.js', () => ({
AsyncStorage: jest.fn(),
storeUID: jest.fn(),
storeMetrics: jest.fn()
Expand All @@ -82,7 +82,7 @@ jest.mock('firebase/firestore', () => ({
deleteDoc: jest.fn(),
}));

jest.mock('../firebaseConfig.js', () => ({
jest.mock('../../../firebaseConfig.js', () => ({
auth: {
signOut: jest.fn(() => Promise.resolve()),
currentUser: {
Expand Down Expand Up @@ -114,14 +114,14 @@ jest.mock('firebase/auth', () => ({
},
}));

jest.mock('../src/actions/appActions', () => ({
jest.mock('../../../src/actions/appActions', () => ({
userMetricsDataModalVisible: jest.fn(() => ({
type: 'USER_METRICS_DATA_MODAL_VISIBLE',
payload: { visibility: true, isFromSignUpScreen: true },
})),
}));

jest.mock('../src/actions/toastActions', () => ({
jest.mock('../../../src/actions/toastActions', () => ({
toastError: jest.fn((message) => ({
type: 'showErrorToast',
payload: message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,29 @@ import { fireEvent, render, screen, waitFor } from '@testing-library/react-nativ
import { Provider } from 'react-redux';
import { NavigationContainer, useNavigation } from '@react-navigation/native';
import renderer, { act } from 'react-test-renderer';
import AppHeader from '../../src/components/AppHeader/index.jsx'; // Adjust the import path as necessary
import configureStore from '../../src/store.js';
import AppHeader from '../../../src/components/AppHeader/index.jsx'; // Adjust the import path as necessary
import configureStore from '../../../src/store.js';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { createStackNavigator } from '@react-navigation/stack';

import { Provider as StoreProvider } from 'react-redux';
import { Provider as PaperProvider } from 'react-native-paper';

// Import your store, AppTheme, and AppRouter
import AppTheme from '../../src/constants/themes'; // Update path as necessary
import AppRouter from '../../src/navigation'; // Update path as necessary
import AppTheme from '../../../src/constants/themes.js'; // Update path as necessary
import AppRouter from '../../../src/navigation/index.js'; // Update path as necessary

import Settings from '../../src/screens/Settings/index.jsx'
import Settings from '../../../src/screens/Settings/index.jsx'


jest.mock('../../src/utils/localStorage.js', () => ({
jest.mock('../../../src/utils/localStorage.js', () => ({
AsyncStorage: jest.fn(),
storeUID: jest.fn(),
getUID: jest.fn(),
}));

// Mock Firebase Authentication
jest.mock('../../firebaseConfig.js', () => ({
jest.mock('../../../firebaseConfig.js', () => ({
auth: {
currentUser: {
uid: {
Expand Down Expand Up @@ -92,7 +92,7 @@ jest.mock('react-redux', () => ({
}));

// Mock userActions.js specifically if you want control over `startLogout` behavior
jest.mock('../../src/actions/userActions.js', () => ({
jest.mock('../../../src/actions/userActions.js', () => ({
startLogout: jest.fn().mockImplementation(() => jest.fn()), // Mock implementation if needed
}));

Expand All @@ -115,7 +115,7 @@ jest.mock('react-native-paper', () => ({
},
}));

jest.mock('@shopify/react-native-skia', () => require('./__mocks__/@shopify__react-native-skia.js'));
jest.mock('@shopify/react-native-skia', () => require('../../__mocks__/@shopify__react-native-skia.js'));

jest.mock('victory-native', () => {
// Mock the specific components and functionalities you use
Expand All @@ -140,17 +140,17 @@ jest.mock('victory-native', () => {
ticks: jest.fn().mockReturnValue([0, 50, 100, 150, 200]),
}));

jest.mock('react-native-vector-icons/MaterialIcons', () => require('../__mocks__/react-native-vector-icons.js').MaterialIcons);
jest.mock('react-native-vector-icons/FontAwesome5', () => require('../__mocks__/react-native-vector-icons.js').FontAwesome5);
jest.mock('@shopify/react-native-skia', () => require('../__mocks__/@shopify__react-native-skia.js'));
jest.mock('../../src/components/visualizations/ActivityRings/Ring.jsx', () => {
jest.mock('react-native-vector-icons/MaterialIcons', () => require('../../__mocks__/react-native-vector-icons.js').MaterialIcons);
jest.mock('react-native-vector-icons/FontAwesome5', () => require('../../__mocks__/react-native-vector-icons.js').FontAwesome5);
jest.mock('@shopify/react-native-skia', () => require('../../__mocks__/@shopify__react-native-skia.js'));
jest.mock('../../../src/components/visualizations/ActivityRings/Ring.jsx', () => {
return jest.fn(({ ring, center, strokeWidth, scale }) => (
<div>
Mock Ring Component - {ring.size}, {center.x}, {center.y}, {strokeWidth}, {scale}
</div>
));
});
jest.mock('../../src/components/visualizations/ActivityChart/ActivityChart.jsx', () => {
jest.mock('../../../src/components/visualizations/ActivityChart/ActivityChart.jsx', () => {
const MockActivityChart = ({ color, name, type, goal, progress }) => (
<div data-testid="mock-activity-chart">
<div>{`Mock ActivityChart: ${name}`}</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import toastReducer from '../src/reducers/toastReducer';
import { ToastTypes } from '../src/actions/types.js';
import toastReducer from '../../../src/reducers/toastReducer.js';
import { ToastTypes } from '../../../src/actions/types.js';


describe('toastReducer', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import userReducer from '../src/reducers/userReducer';
import * as types from '../src/actions/types';
import userReducer from '../../../src/reducers/userReducer';
import * as types from '../../../src/actions/types';

// Mock the global Date object
//const MOCKED_DATE = new Date(2023, 0, 1); // Mocked date as January 1st, 2023
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Import the functions and AsyncStorage
import { storeUID, getUID, storeMetrics, getMetrics } from '../src/utils/localStorage.js'; // Update the path to where your functions are located
import { storeUID, getUID, storeMetrics, getMetrics } from '../../../src/utils/localStorage.js'; // Update the path to where your functions are located
import AsyncStorage from '@react-native-async-storage/async-storage';

// Mock AsyncStorage
Expand Down

0 comments on commit 6a33662

Please sign in to comment.