Created
July 3, 2021 06:11
-
-
Save slawekradzyminski/ab2333a90c3fb0b755adbfa1e3074c69 to your computer and use it in GitHub Desktop.
This file contains 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
/// <reference types="cypress" /> | |
describe('login page', () => { | |
const firstName = 'Slawek' | |
beforeEach(() => { | |
cy.visit('/login') | |
}) | |
it('should login', () => { | |
const username = 'username' | |
const password = 'password' | |
cy.intercept('POST', 'http://localhost:4000/users/authenticate', { | |
statusCode: 200, | |
body: { | |
firstName: firstName, | |
lastName: 'Radzyminski', | |
id: 1, | |
token: '123456', | |
username: 'slawek' | |
}, | |
}).as('mytag') | |
cy.get('[name=username]').type(username) | |
cy.get('[name=password]').type(password) | |
cy.get('.btn-primary').click() | |
cy.get('p').should('contain.text', 'Congratulations') | |
cy.get('h1').should('contain.text', firstName) | |
cy.get('@mytag') | |
.its('request.body') | |
.should('deep.equal', { | |
username: username, | |
password: password | |
}) | |
}) | |
it('should show error message after unsuccessful login', () => { | |
const message = 'Login failed - bad username or password' | |
cy.intercept('POST', 'http://localhost:4000/users/authenticate', { | |
statusCode: 401, | |
body: { | |
message: message | |
}, | |
}) | |
cy.get('[name=username]').type('wrong') | |
cy.get('[name=password]').type('wrong') | |
cy.get('.btn-primary').click() | |
cy.get('.alert-danger').should('have.text', message) | |
}) | |
it('should correctly handle network error', () => { | |
cy.intercept('POST', 'http://localhost:4000/users/authenticate', { | |
forceNetworkError: true | |
}) | |
cy.get('[name=username]').type('wrong') | |
cy.get('[name=password]').type('wrong') | |
cy.get('.btn-primary').click() | |
cy.get('.alert-danger').should('contain.text', 'Failed') | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment