Untitled
unknown
plain_text
2 years ago
2.5 kB
10
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 emailID = 'email-input'; const passwordID = 'password-input'; it('Verifica se o campo email e password são renderizados na tela', () => { renderWithRouterAndRedux(<App />); const email = screen.getByTestId(emailID); const password = screen.getByTestId(passwordID); expect(email).toBeInTheDocument(); expect(password).toBeInTheDocument(); }); it('Verifica se o botão de login é habilitado/desabilitado conforme email e password são válidos ou não', async () => { renderWithRouterAndRedux(<App />); const user = userEvent.setup(); const okEmail = 'email@domain.com'; const notOkEmail = 'emaildomain.com'; const okPassword = '1029384'; const notOkPassword = '1029'; const email = screen.getByTestId(emailID); const password = screen.getByTestId(passwordID); const btn = screen.getByRole('button'); it('1o Teste', async () => { await user.type(email, notOkEmail); await user.type(password, notOkPassword); expect(btn).toBeDisabled(); await user.clear(email); await user.clear(password); }); it('2o Teste', async () => { await user.type(email, notOkEmail); await user.type(password, okPassword); expect(btn).toBeDisabled(); await user.clear(email); await user.clear(password); }); it('3o Teste', async () => { await user.type(email, okEmail); await user.type(password, notOkPassword); expect(btn).toBeDisabled(); await user.clear(email); await user.clear(password); }); it('4o Teste', async () => { await user.type(email, okEmail); await user.type(password, okPassword); expect(btn).toBeEnabled(); }); }); it('Verifica se a aplicação é redirecionada para a rota da carteira se email e password forem válidos', async () => { renderWithRouterAndRedux(<App />); const user = userEvent.setup(); const okEmail = 'email@domain.com'; const okPassword = '1029384'; const email = screen.getByTestId(emailID); const password = screen.getByTestId(passwordID); const btn = screen.getByRole('button'); await user.type(email, okEmail); await user.type(password, okPassword); expect(btn).toBeEnabled(); await user.click(btn); waitFor(() => expect(global.window.location.pathname).toEqual('/carteira')); });
Editor is loading...