Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
2.2 kB
1
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 login = 'email-input';
const password = 'password-input';

it('Verificar se email e senha estão na tela', () => {
  renderWithRouterAndRedux(<App />);
  const email = screen.getByTestId(login);
  const senha = screen.getByTestId(password);

  expect(email).toBeInTheDocument();
  expect(senha).toBeInTheDocument();
});

it('Verificar se o botão de login habilita e desabilita', async () => {
  renderWithRouterAndRedux(<App />);
  const user = userEvent.setup();
  const emailCorreto = 'seuemail@yahoo.com';
  const emailIncorreto = 'seuemailyahoo.com';
  const senhaCorreta = '1234567';
  const senhaIncorreta = '12345';
  const email = screen.getByTestId(login);
  const senha = screen.getByTestId(password);
  const button = screen.getByRole('button');

  await user.type(email, emailIncorreto);
  await user.type(senha, senhaIncorreta);
  expect(button).toBeDisabled();
  await user.clear(email);
  await user.clear(senha);

  await user.type(email, emailCorreto);
  await user.type(senha, senhaIncorreta);
  expect(button).toBeDisabled();
  await user.clear(email);
  await user.clear(senha);

  await user.type(email, emailCorreto);
  await user.type(senha, senhaIncorreta);
  expect(button).toBeDisabled();
  await user.clear(email);
  await user.clear(senha);

  await user.type(email, emailCorreto);
  await user.type(senha, senhaCorreta);
  expect(button).toBeEnabled();
});
it('Testar funcionamento da rota', async () => {
  renderWithRouterAndRedux(<App />);
  const user = userEvent.setup();
  const emailCerto = 'email@yahoo.com';
  const senhaCerta = '1234567';
  const acesso = screen.getByTestId(login);
  const senhaCorreta = screen.getByTestId(password);
  const button = screen.getByRole('button');
  await user.type(acesso, emailCerto);
  await user.type(senhaCorreta, senhaCerta);
  expect(button).toBeEnabled();
  await user.click(button);
  waitFor(() => expect(global.window.location.pathname).toEqual('/carteira'));
});