-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
243 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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({ | ||
|
@@ -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 | ||
|
@@ -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', () => { | ||
|
@@ -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'); | ||
}); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.