File size: 1,984 Bytes
f5071ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/// <reference types="Cypress" />

describe('<Login />', () => {
    beforeEach(() => {
        cy.visit('/login')

        cy.get('input[name="email"]')
            .as('inputEmail')

        cy.get('input[name="password"]')
            .as('passwordInput')
    })

    it('fails to submit form without any input and shows error spans for both inputs', () => {
        cy.get('.Button')
            .contains('Sign In')
            .click()

        cy.location().should(loc => {
            expect(loc.pathname).to.eq('/login')
        })

        cy.get('form')
            .children('span')
            .should('have.length', 2)
    })

    it('shows a span text on email input focus and focus lost', () => {
        const spanText = 'Please enter a valid email or phone number.'
        cy.get('@inputEmail')
            .focus()
            .blur()

        cy.get('form')
            .children('span')
            .should('have.length', 1)
            .contains(spanText)
    })

    it('changes span text on password validation passed', () => {
        const spanText = 'Your password must contain between 4 and 60 characters.'
        cy.get('@passwordInput')
            .focus()
            .blur()

        cy.get('form')
            .children('span')
            .as('text')

        cy.get('@text')
            .should('have.length', 1)
            .contains(spanText)

        cy.get('@passwordInput')
            .type('123')

        cy.get('@text')
            .contains(spanText)

        cy.get('@passwordInput')
            .type('4')

        cy.get('@text')
            .should('not.exist')
    })

    it('logs in on valid input', () => {
        cy.get('@inputEmail')
            .type('[email protected]')

        cy.get('@passwordInput')
            .type('1234')

        cy.get('.Button')
            .contains('Sign In')
            .click()

        cy.location().should(loc => {
            expect(loc.pathname).to.eq('/browse')
        })
    })
})