-
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.
Co-authored-by: LipeAKugel <[email protected]> Co-authored-by: vitordiniz25 <[email protected]>
- Loading branch information
1 parent
66e1637
commit 8a61516
Showing
1 changed file
with
25 additions
and
0 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 |
---|---|---|
|
@@ -71,6 +71,7 @@ describe('Login Component', () => { | |
}); | ||
}); | ||
|
||
|
||
it('should display login error for invalid credentials', async () => { | ||
const mockLoginApi = jest.spyOn(api, 'login'); | ||
mockLoginApi.mockRejectedValue(new Error('Invalid credentials')); | ||
|
@@ -111,6 +112,30 @@ describe('Login Component', () => { | |
}); | ||
}); | ||
|
||
|
||
it('should make API call with invalid credentials', async () => { | ||
const mockLoginApi = jest.spyOn(api, 'login'); | ||
mockLoginApi.mockResolvedValue({ type: 'error', token: token}); | ||
|
||
const mockNavigate = jest.fn(); | ||
useNavigate.mockImplementation(() => mockNavigate); | ||
|
||
// Simular o envio do formulário com credenciais válidas | ||
render(<Login />); | ||
fireEvent.input(screen.getByPlaceholderText('[email protected]'), { target: { value: 'testecom' } }); | ||
fireEvent.input(screen.getByPlaceholderText('************'), { target: { value: '@' } }); | ||
fireEvent.submit(screen.getByText('LOGIN')); | ||
|
||
await waitFor(() => { | ||
// Verificar se a função da API foi chamada com as credenciais corretas | ||
expect(mockLoginApi).toHaveBeenCalledWith('testecom', '@'); | ||
|
||
// Verificar se a navegação ocorreu após o login bem-sucedido | ||
expect(screen.queryByText('E-mail inválido')).toBeInTheDocument() | ||
expect(screen.queryByText('E-mail ou senha incorreto.')).toBeInTheDocument() | ||
}); | ||
}); | ||
|
||
it("navega para a página 'esqueciMinhaSenha' quando é clicado", () => { | ||
render(<Login/>); | ||
const buttonElement = screen.getByText("Recuperar senha"); | ||
|