Untitled
unknown
plain_text
2 years ago
2.3 kB
6
Indexable
import userEvent from '@testing-library/user-event';
import { screen, waitFor } from '@testing-library/react';
import App from '../App';
import { renderWithRouterAndRedux } from './helpers/renderWith';
const meuEmail = 'email-input';
const minhaSenha = 'password-input';
it('Verificar se email e senha estão na tela', () => {
renderWithRouterAndRedux(<App />);
const email = screen.getByTestId(meuEmail);
const senha = screen.getByTestId(minhaSenha);
expect(email).toBeInTheDocument();
expect(senha).toBeInTheDocument();
});
it('Verificar se o botão de login habilita quando email e senha são válidos', async () => {
renderWithRouterAndRedux(<App />);
const meuUser = userEvent.setup();
const emailCorreto = 'majumarquezan@trybe.com';
const emailIncorreto = 'majumarquezantrybe.com';
const senhaCorreta = 'abcdefg';
const senhaIncorreta = '12345';
const email = screen.getByTestId(meuEmail);
const password = screen.getByTestId(minhaSenha);
const botao = screen.getByRole('button');
await meuUser.type(email, emailIncorreto);
await meuUser.type(password, senhaIncorreta);
expect(botao).toBeDisabled();
await meuUser.clear(email);
await meuUser.clear(password);
await meuUser.type(email, emailCorreto);
await meuUser.type(password, senhaIncorreta);
expect(botao).toBeDisabled();
await meuUser.clear(email);
await meuUser.clear(password);
await meuUser.type(email, emailIncorreto);
await meuUser.type(password, senhaCorreta);
expect(botao).toBeDisabled();
await meuUser.clear(email);
await meuUser.clear(password);
await meuUser.type(email, emailCorreto);
await meuUser.type(password, senhaCorreta);
expect(botao).toBeEnabled();
});
it('Rota funciona normalmente', async () => {
renderWithRouterAndRedux(<App />);
const meuUser = userEvent.setup();
const meuEmailmeu = 'majumarquezan@trybe.com';
const senha = '1234567';
const campoEmail = screen.getByTestId(meuEmailmeu);
const campoSenha = screen.getByTestId(senha);
const botao = screen.getByRole('button');
await meuUser.type(campoEmail, meuEmailmeu);
await meuUser.type(campoSenha, senha);
expect(botao).toBeEnabled();
await meuUser.click(botao);
waitFor(() => expect(global.window.location.pathname).toEqual('/carteira'));
});
Editor is loading...