Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import messages from '../../src/utils/validationMessages'
- describe('SignUp', () => {
- const getStore = () => cy.window().its('app.$store')
- const firstName = 'Nina'
- const lastName = 'Alecrim'
- const cpf = '07031387400'
- const phone = '83994181319'
- beforeEach(() => {
- cy.visit('/');
- });
- it('should display the main headline.', () => {
- cy.get('[data-cy=signup-screen]').should('be.visible');
- });
- describe('User stores', () => {
- it('should have user stores properties', () => {
- getStore().its('state.user').should('have.keys', ['user', 'error'])
- })
- it('should start empty', () => {
- getStore().its('state.user').should('deep.equal', {
- user: {
- street: '',
- district: '',
- city: '',
- complement: '',
- country: '',
- cpf: '',
- email: '',
- firstName: '',
- lastName: '',
- number: '',
- password: '',
- phone: '',
- state: '',
- username: '',
- zip: ''
- },
- error: {
- message: null
- }
- })
- getStore().its('state.user.user.zip').should('equal', '')
- })
- })
- describe('Insertion CEP', () => {
- it('should not search when insert a wrong ZIP', () => {
- cy.get('[data-cy=input-zip]').type('00000000')
- cy.contains(messages.INVALID_ZIP_CODE)
- cy.get('[data-cy=address-screen]').should('not.be.visible')
- })
- it('should search when insert a right ZIP', () => {
- cy.get('[data-cy=input-zip]').type('58430360')
- cy.contains('search').click()
- getStore().its('state.user.user.zip').should('equal', '58430-360')
- cy.get('[data-cy=address-screen]').should('be.visible')
- })
- })
- describe('Location', () => {
- beforeEach(() => {
- cy.get('[data-cy=input-zip]').type('58430360')
- cy.contains('search').click()
- })
- it('inputs should be equal to zip inserted', () => {
- cy.request({
- method: 'GET',
- url: 'https://viacep.com.br/ws/58430360/json/'
- }).then(response => {
- const { cep,
- logradouro,
- complemento,
- bairro,
- localidade,
- uf } = response.body
- cy.get('[data-cy=location-zip]').should('have.value', cep)
- cy.get('[data-cy=location-state]').should('have.value', uf)
- cy.get('[data-cy=location-city]').should('have.value', localidade)
- cy.get('[data-cy=location-district]').should('have.value', bairro)
- cy.get('[data-cy=location-street]').should('have.value', logradouro)
- cy.get('[data-cy=location-complement]').should('have.value', complemento)
- })
- })
- it('should change user store', () => {
- cy.get('[data-cy=location-number]').type(525).blur()
- cy.get('[data-cy=after-location]').click()
- getStore().its('state.user.user.number').should('equal', '525')
- })
- it('should warn when do not fill a required field', () => {
- cy.get('[data-cy=location-number]').type(525).blur()
- cy.get('[data-cy=location-number]').clear()
- cy.contains(messages.REQUIRED_FIELD)
- })
- it('should no continue with filder required with only espaces', () => {
- cy.get('[data-cy=location-number]').type(" ").blur()
- cy.get('[data-cy=after-location]').should('be.disabled')
- })
- })
- describe('Identification', () => {
- beforeEach(() => {
- cy.get('[data-cy=input-zip]').type('58430360')
- cy.contains('search').click()
- cy.get('[data-cy=location-number]').type(525).blur()
- cy.get('[data-cy=after-location]').click()
- })
- function getValueField(input) {
- var result = {};
- cy.get(input).then(elem => {
- const value = Cypress.$(elem).val();
- console.log(value)
- result = value;
- });
- return result;
- }
- it('should be saved on user store', () => {
- cy.get('[data-cy=first-name]').type(firstName)
- cy.get('[data-cy=last-name]').type(lastName)
- cy.get('[data-cy=cpf]').type(cpf)
- cy.get('[data-cy=phone]').type(phone).blur()
- getStore().its('state.user.user.firstName').should('equal', firstName)
- getStore().its('state.user.user.lastName').should('equal', lastName)
- getStore().its('state.user.user.cpf').should('equal', cpf)
- getStore().its('state.user.user.phone').should('equal', phone)
- expect(getValueField('[data-cy=cpf]')).to.equal("070.313.874-00")
- // cy.get('[data-cy=cpf]').then(elem => {
- // const xyz = Cypress.$(elem).val();
- // console.log(xyz === '070.313.874-00')
- // expect(xyz).to.equal("070.313.874-00")
- // });
- //.should('equal', '58430-360')
- })
- it('should warn when do not fill a required field', () => {
- cy.get('[data-cy=phone]').clear().blur()
- cy.contains(messages.REQUIRED_FIELD)
- getStore().its('state.user.user.phone').should('equal', '')
- })
- })
- describe('Credentials', () => {
- beforeEach(() => {
- cy.get('[data-cy=input-zip]').type('58430360')
- cy.contains('search').click()
- cy.get('[data-cy=location-number]').type(525).blur()
- cy.get('[data-cy=after-location]').click()
- cy.get('[data-cy=first-name]').type(firstName)
- cy.get('[data-cy=last-name]').type(lastName)
- cy.get('[data-cy=cpf]').type(cpf)
- cy.get('[data-cy=phone]').type(phone).blur()
- cy.get('[data-cy=after-identification]').click()
- })
- it('should be saved on the user store', () => {
- cy.get('[data-cy=username]').type('ninalecrim')
- cy.get('[data-cy=email]').type('nina@gmail.com').blur()
- getStore().its('state.user.user.username').should('equal', 'ninalecrim')
- getStore().its('state.user.user.email').should('equal', 'nina@gmail.com')
- })
- it('email should be valid', () => {
- cy.get('[data-cy=email]').type('nina@gmail').blur()
- cy.contains(messages.INVALID_EMAIL)
- })
- it('passwords should match', () => {
- cy.get('[data-cy=password]').type(12345678)
- cy.get('[data-cy=confirm-password]').type(12345687).blur()
- cy.contains(messages.PASSWORDS_DONT_MATCH)
- })
- })
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement