Skip to content

Commit

Permalink
🔁(#210): Adicionando teste de login
Browse files Browse the repository at this point in the history
Co-authored-by: LipeAKugel <[email protected]>
Co-authored-by: vitordiniz25 <[email protected]>
  • Loading branch information
3 people committed Dec 14, 2023
1 parent 66e1637 commit 8a61516
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/tests/pages/Login.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 8a61516

Please sign in to comment.