Advertisement
Guest User

Testes para adicionar

a guest
May 14th, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import messages from '../../src/utils/validationMessages'
  2.  
  3. describe('SignUp', () => {
  4.     const getStore = () => cy.window().its('app.$store')
  5.  
  6.     const firstName = 'Nina'
  7.     const lastName = 'Alecrim'
  8.     const cpf = '07031387400'
  9.     const phone = '83994181319'
  10.  
  11.     beforeEach(() => {
  12.       cy.visit('/');
  13.     });
  14.  
  15.     it('should display the main headline.', () => {
  16.       cy.get('[data-cy=signup-screen]').should('be.visible');
  17.     });
  18.  
  19.     describe('User stores', () => {
  20.       it('should have user stores properties', () => {
  21.         getStore().its('state.user').should('have.keys', ['user', 'error'])
  22.       })
  23.  
  24.       it('should start empty', () => {
  25.         getStore().its('state.user').should('deep.equal', {
  26.           user: {
  27.             street: '',
  28.             district: '',
  29.             city: '',
  30.             complement: '',
  31.             country: '',
  32.             cpf: '',
  33.             email: '',
  34.             firstName: '',
  35.             lastName: '',
  36.             number: '',
  37.             password: '',
  38.             phone: '',
  39.             state: '',
  40.             username: '',
  41.             zip: ''
  42.           },
  43.           error: {
  44.             message: null
  45.           }
  46.         })
  47.         getStore().its('state.user.user.zip').should('equal', '')
  48.       })
  49.     })
  50.  
  51.     describe('Insertion CEP', () => {
  52.       it('should not search when insert a wrong ZIP', () => {
  53.         cy.get('[data-cy=input-zip]').type('00000000')
  54.        
  55.         cy.contains(messages.INVALID_ZIP_CODE)
  56.         cy.get('[data-cy=address-screen]').should('not.be.visible')
  57.       })
  58.  
  59.       it('should search when insert a right ZIP', () => {
  60.         cy.get('[data-cy=input-zip]').type('58430360')
  61.  
  62.         cy.contains('search').click()
  63.         getStore().its('state.user.user.zip').should('equal', '58430-360')
  64.         cy.get('[data-cy=address-screen]').should('be.visible')
  65.       })
  66.     })
  67.  
  68.     describe('Location', () => {
  69.       beforeEach(() => {
  70.         cy.get('[data-cy=input-zip]').type('58430360')
  71.         cy.contains('search').click()
  72.       })
  73.  
  74.       it('inputs should be equal to zip inserted', () => {
  75.         cy.request({
  76.           method: 'GET',
  77.           url: 'https://viacep.com.br/ws/58430360/json/'
  78.         }).then(response => {
  79.           const { cep,
  80.                   logradouro,
  81.                   complemento,
  82.                   bairro,
  83.                   localidade,
  84.                   uf } = response.body
  85.          
  86.           cy.get('[data-cy=location-zip]').should('have.value', cep)
  87.           cy.get('[data-cy=location-state]').should('have.value', uf)
  88.           cy.get('[data-cy=location-city]').should('have.value', localidade)
  89.           cy.get('[data-cy=location-district]').should('have.value', bairro)
  90.           cy.get('[data-cy=location-street]').should('have.value', logradouro)
  91.           cy.get('[data-cy=location-complement]').should('have.value', complemento)
  92.         })
  93.       })
  94.  
  95.       it('should change user store', () => {
  96.         cy.get('[data-cy=location-number]').type(525).blur()
  97.  
  98.         cy.get('[data-cy=after-location]').click()
  99.         getStore().its('state.user.user.number').should('equal', '525')
  100.       })
  101.  
  102.       it('should warn when do not fill a required field', () => {
  103.         cy.get('[data-cy=location-number]').type(525).blur()
  104.         cy.get('[data-cy=location-number]').clear()
  105.         cy.contains(messages.REQUIRED_FIELD)
  106.       })
  107.  
  108.       it('should no continue with filder required with only espaces', () => {
  109.         cy.get('[data-cy=location-number]').type("     ").blur()
  110.         cy.get('[data-cy=after-location]').should('be.disabled')
  111.  
  112.       })
  113.     })
  114.  
  115.     describe('Identification', () => {
  116.       beforeEach(() => {
  117.         cy.get('[data-cy=input-zip]').type('58430360')
  118.         cy.contains('search').click()
  119.         cy.get('[data-cy=location-number]').type(525).blur()
  120.         cy.get('[data-cy=after-location]').click()
  121.       })
  122.  
  123.       function getValueField(input) {
  124.         var result = {};
  125.         cy.get(input).then(elem => {
  126.           const value = Cypress.$(elem).val();
  127.           console.log(value)
  128.           result = value;
  129.         });
  130.  
  131.         return result;
  132.       }
  133.  
  134.       it('should be saved on user store', () => {
  135.         cy.get('[data-cy=first-name]').type(firstName)
  136.         cy.get('[data-cy=last-name]').type(lastName)
  137.         cy.get('[data-cy=cpf]').type(cpf)
  138.         cy.get('[data-cy=phone]').type(phone).blur()
  139.  
  140.         getStore().its('state.user.user.firstName').should('equal', firstName)
  141.         getStore().its('state.user.user.lastName').should('equal', lastName)
  142.         getStore().its('state.user.user.cpf').should('equal', cpf)
  143.         getStore().its('state.user.user.phone').should('equal', phone)
  144.        
  145.         expect(getValueField('[data-cy=cpf]')).to.equal("070.313.874-00")
  146.         // cy.get('[data-cy=cpf]').then(elem => {
  147.         //   const xyz = Cypress.$(elem).val();
  148.         //   console.log(xyz === '070.313.874-00')
  149.         //   expect(xyz).to.equal("070.313.874-00")
  150.         // });
  151.         //.should('equal', '58430-360')
  152.       })
  153.  
  154.  
  155.  
  156.       it('should warn when do not fill a required field', () => {
  157.         cy.get('[data-cy=phone]').clear().blur()
  158.  
  159.         cy.contains(messages.REQUIRED_FIELD)
  160.         getStore().its('state.user.user.phone').should('equal', '')
  161.       })
  162.     })
  163.  
  164.     describe('Credentials', () => {
  165.       beforeEach(() => {
  166.         cy.get('[data-cy=input-zip]').type('58430360')
  167.         cy.contains('search').click()
  168.         cy.get('[data-cy=location-number]').type(525).blur()
  169.         cy.get('[data-cy=after-location]').click()
  170.  
  171.         cy.get('[data-cy=first-name]').type(firstName)
  172.         cy.get('[data-cy=last-name]').type(lastName)
  173.         cy.get('[data-cy=cpf]').type(cpf)
  174.         cy.get('[data-cy=phone]').type(phone).blur()
  175.         cy.get('[data-cy=after-identification]').click()
  176.       })
  177.  
  178.       it('should be saved on the user store', () => {
  179.         cy.get('[data-cy=username]').type('ninalecrim')
  180.         cy.get('[data-cy=email]').type('nina@gmail.com').blur()
  181.  
  182.         getStore().its('state.user.user.username').should('equal', 'ninalecrim')
  183.         getStore().its('state.user.user.email').should('equal', 'nina@gmail.com')
  184.       })
  185.  
  186.       it('email should be valid', () => {
  187.         cy.get('[data-cy=email]').type('nina@gmail').blur()
  188.         cy.contains(messages.INVALID_EMAIL)
  189.       })
  190.  
  191.       it('passwords should match', () => {
  192.         cy.get('[data-cy=password]').type(12345678)
  193.         cy.get('[data-cy=confirm-password]').type(12345687).blur()
  194.  
  195.         cy.contains(messages.PASSWORDS_DONT_MATCH)
  196.       })
  197.     })
  198.  
  199. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement