Skip to content

Commit

Permalink
test case pass push
Browse files Browse the repository at this point in the history
  • Loading branch information
yashb196 committed Dec 10, 2024
1 parent b2c0c36 commit f3530dd
Show file tree
Hide file tree
Showing 5 changed files with 243 additions and 105 deletions.
46 changes: 32 additions & 14 deletions __tests__/LoginScreen.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { Provider } from 'react-redux';
import { SafeAreaProvider } from 'react-native-safe-area-context'; // Make sure to import SafeAreaProvider
import configureStore from 'redux-mock-store';
import LoginScreen from '../lib/screens/loginScreens/LoginScreen';
import moxios from 'moxios'
import { shallow } from 'enzyme';
import moxios from 'moxios';

// Create a mock store
const mockStore = configureStore([]);
const store = mockStore({
Expand All @@ -23,6 +23,19 @@ jest.mock("firebase/auth", () => ({
initializeAuth: jest.fn(),
getReactNativePersistence: jest.fn(),
onAuthStateChanged: jest.fn(), // Mock onAuthStateChanged
signInWithEmailAndPassword: jest.fn(() =>
Promise.resolve({ user: { uid: '12345' } })
), // Mock signInWithEmailAndPassword
}));

jest.mock("firebase/storage", () => ({
getStorage: jest.fn(),
}));

jest.mock('firebase/firestore', () => ({
getFirestore: jest.fn(() => ({})), // Mock getFirestore to return an empty object
doc: jest.fn(() => ({})), // Mock doc to return an empty object
getDoc: jest.fn(() => Promise.resolve({ exists: () => false })), // Mock getDoc to resolve without a document
}));

// Silence console warnings during the test
Expand All @@ -32,14 +45,12 @@ beforeEach(() => {
jest.spyOn(console, 'log').mockImplementation(() => {});
jest.spyOn(console, 'error').mockImplementation(() => {});
jest.spyOn(console, 'warn').mockImplementation(() => {});
moxios.install()
moxios.install();
});

afterEach(() => {
console.log.mockRestore();
console.error.mockRestore();
console.warn.mockRestore(); // Restore console.warn after the tests
moxios.uninstall()
jest.restoreAllMocks();
moxios.uninstall();
});

describe('LoginScreen', () => {
Expand All @@ -58,24 +69,31 @@ describe('LoginScreen', () => {
expect(toJSON()).toMatchSnapshot();
});

it('renders input fields', async () => {
it('renders input fields and handles login', async () => {
const navigationMock = { navigate: jest.fn() };
const routeMock = { params: {} };

const { queryByTestId } = render(
const { getByTestId } = render(
<Provider store={store}>
<SafeAreaProvider>
<LoginScreen navigation={navigationMock} route={routeMock} />
</SafeAreaProvider>
</Provider>
);

// Simulate input and login button press
const email = queryByTestId('email-input');
const password = queryByTestId('password-input');
const loginButton = queryByTestId('login-button');
const emailInput = getByTestId('email-input');
const passwordInput = getByTestId('password-input');
const loginButton = getByTestId('login-button');

// Simulate user input
fireEvent.changeText(emailInput, '[email protected]');
fireEvent.changeText(passwordInput, 'password123');

// Simulate login button press
fireEvent.press(loginButton);

await waitFor(() => {
expect(navigationMock.navigate).toHaveBeenCalledWith('HomeTab');
});
});

});
21 changes: 18 additions & 3 deletions __tests__/MoreScreen.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { fireEvent, render } from '@testing-library/react-native';
import React from 'react';
import { fireEvent, render } from '@testing-library/react-native';
import { Provider } from 'react-redux';
import { NavigationContainer } from '@react-navigation/native';
import configureStore from 'redux-mock-store';
import MorePage from '../lib/screens/MorePage';

Expand All @@ -14,6 +15,19 @@ jest.mock("firebase/auth", () => ({
getReactNativePersistence: jest.fn(),
onAuthStateChanged: jest.fn(), // Mock onAuthStateChanged
}));


jest.mock('firebase/firestore', () => ({
getFirestore: jest.fn(),
doc: jest.fn(() => ({
get: jest.fn(() => Promise.resolve({ exists: false })),
})),
}));

jest.mock("firebase/storage", () => ({
getStorage: jest.fn(),
}));

jest.mock('expo-font', () => ({
loadAsync: jest.fn(() => Promise.resolve()),
isLoaded: jest.fn(() => true),
Expand All @@ -24,7 +38,6 @@ jest.mock('react-native/Libraries/Image/Image', () => ({
resolveAssetSource: jest.fn(() => ({ uri: 'mocked-asset-uri' })),
}));


jest.mock('react-native/Libraries/Settings/NativeSettingsManager', () => ({
settings: {},
setValues: jest.fn(),
Expand Down Expand Up @@ -67,7 +80,9 @@ describe('MorePage', () => {
it('toggles dark mode correctly', () => {
const { getByTestId } = render(
<Provider store={store}>
<MorePage />
<NavigationContainer>
<MorePage />
</NavigationContainer>
</Provider>
);

Expand Down
Loading

0 comments on commit f3530dd

Please sign in to comment.