Last active
May 22, 2018 11:22
-
-
Save Jessica7/64acf6515516780e2dc73330c95236f1 to your computer and use it in GitHub Desktop.
Login
This file contains hidden or 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
| import { submit } from "./index" | |
| import { shallow } from "enzyme" | |
| import { Form, Field } from "react-final-form" | |
| import { | |
| validatePresence, | |
| validateEmailField, | |
| composeValidators | |
| } from "app/utils/validations" | |
| import FormField from "app/common/FormField" | |
| describe("submit", () => { | |
| it("Shows error when the credentials is invalid", async () => { | |
| const login = jest.fn(() => | |
| Promise.reject("Email ou senhas estão inválidos!") | |
| ) | |
| const saveToken = jest.fn() | |
| const onSubmit = () => | |
| submit(login, saveToken)({ | |
| email: "[email protected]", | |
| password: "secret" | |
| }) | |
| const EMAIL = "email" | |
| const preventDefault = event => event.preventDefault | |
| const formRender = () => { | |
| return ({ handleSubmit, submitting, submitSucceeded, submitFailed }) => { | |
| return ( | |
| <form | |
| onSubmit={ | |
| submitting || submitSucceeded ? preventDefault : handleSubmit | |
| } | |
| > | |
| <Field | |
| data-test="email" | |
| name={EMAIL} | |
| validate={composeValidators(validatePresence, validateEmailField)} | |
| render={props => <FormField {...props} placeholder="e-mail" />} | |
| /> | |
| {submitFailed && <p>{"Email ou senha incorretos"}</p>} | |
| </form> | |
| ) | |
| } | |
| } | |
| const form = shallow(<Form onSubmit={onSubmit} render={formRender()} />) | |
| form.simulate("submit") | |
| form.update() | |
| // Não consigo achar o p para acessar a mensagem de error | |
| console.log(form.find("p")) | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment