Last active
April 29, 2017 19:59
-
-
Save DanCassiano/e05f2fc7119ddec2540b6814fa5f2b12 to your computer and use it in GitHub Desktop.
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 React from 'react'; | |
import ReactDOM from 'react-dom'; | |
import { mount, shallow } from 'enzyme'; | |
import sinon from 'sinon'; | |
import From from './../components/Form'; | |
describe("#Contact form",()=> { | |
const onSubmit = sinon.spy(); | |
sinon.spy(From.prototype, 'onSubmit'); | |
const mokContact = { | |
nome: 'Jose', | |
email: '[email protected]', | |
telefone: '024 99999999', | |
msg: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua' | |
}; | |
it('#1. Nosso componente pode ser renderizado', () => { | |
shallow(<From onSubmit={onSubmit} />); | |
}); | |
it('#2. O Submit acontence com dados validos', () => { | |
const form = mount(<From onSubmit={onSubmit} />); | |
const inputName = form.find('input[name="nome"]').first(); | |
inputName.node.value = mokContact.nome; | |
const inputTelefone = form.find('input[name="telefone"]').first(); | |
inputTelefone.node.value = mokContact.telefone | |
const inputEmail = form.find('input[name="email"]').first(); | |
inputEmail.node.value = mokContact.email | |
const textAreaMsg = form.find('textarea[name="msg"]').first(); | |
textAreaMsg.node.value = mokContact.msg; | |
form.find('button').get(0).click(); | |
expect(From.prototype.onSubmit.calledOnce).toEqual(true); | |
}); | |
describe("#3. É possível enviar o form sem dados ou com dados inválidos",()=> { | |
it('Não permitir submit sem dados', () => { | |
const form = mount(<From onSubmit={onSubmit} />); | |
form.find('button').get(0).click(); | |
expect(From.prototype.onSubmit.calledOnce).toEqual(false); | |
}); | |
it('Não permitir submit com email inválido', () => { | |
const form = mount(<From onSubmit={onSubmit} />); | |
const inputName = form.find('input[name="nome"]').first(); | |
inputName.node.value = mokContact.nome; | |
const inputTelefone = form.find('input[name="telefone"]').first(); | |
inputTelefone.node.value = mokContact.telefone | |
const inputEmail = form.find('input[name="email"]').first(); | |
inputEmail.node.value = '123456' | |
const textAreaMsg = form.find('textarea[name="msg"]').first(); | |
textAreaMsg.node.value = mokContact.msg; | |
form.find('button').get(0).click(); | |
expect(From.prototype.onSubmit.calledOnce).toEqual(false); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment