-
Notifications
You must be signed in to change notification settings - Fork 2
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
1 parent
6c8526d
commit 8d86eb0
Showing
2 changed files
with
51 additions
and
2 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
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import React from 'react'; | ||
import { render, fireEvent, waitFor, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom/extend-expect'; // For expect(...).toBeInTheDocument() | ||
import Login from './../components/Login'; | ||
import { AuthContext } from '../context/AuthContext'; // Mock the context if needed | ||
import { MemoryRouter } from 'react-router-dom'; // Mock the router if needed | ||
|
||
// Mock the AuthContext value | ||
const mockAuthContextValue = { | ||
dispatch: jest.fn() | ||
}; | ||
|
||
describe('Login Component', () => { | ||
test('renders login form correctly', () => { | ||
render( | ||
<MemoryRouter> | ||
<AuthContext.Provider value={mockAuthContextValue}> | ||
<Login /> | ||
</AuthContext.Provider> | ||
</MemoryRouter> | ||
); | ||
|
||
// Check if elements are rendered | ||
expect(screen.getByText('INTERNOVA.')).toBeInTheDocument(); | ||
expect(screen.getByLabelText('Email')).toBeInTheDocument(); | ||
expect(screen.getByLabelText('Password')).toBeInTheDocument(); | ||
expect(screen.getByRole('button', { name: 'Login' })).toBeInTheDocument(); | ||
}); | ||
|
||
test('handles user input correctly', () => { | ||
render( | ||
<MemoryRouter> | ||
<AuthContext.Provider value={mockAuthContextValue}> | ||
<Login /> | ||
</AuthContext.Provider> | ||
</MemoryRouter> | ||
); | ||
|
||
// Simulate user input | ||
fireEvent.change(screen.getByLabelText('Email'), { target: { value: '[email protected]' } }); | ||
fireEvent.change(screen.getByLabelText('Password'), { target: { value: 'password123' } }); | ||
|
||
// Check if input values are updated | ||
expect(screen.getByLabelText('Email')).toHaveValue('[email protected]'); | ||
expect(screen.getByLabelText('Password')).toHaveValue('password123'); | ||
}); | ||
|
||
// Add more test cases as needed, such as testing form submission and API calls | ||
}); |