feat(test): complete authentication E2E tests

This commit is contained in:
Phan An 2020-12-30 11:11:59 +01:00
parent d29a2dcf39
commit 9740bf8d12
4 changed files with 29 additions and 5 deletions

View file

@ -1,10 +1,6 @@
/// <reference types="cypress" /> /// <reference types="cypress" />
context('Authentication', () => { context('Authentication', () => {
beforeEach(() => {
cy.visit('/')
})
const submitLoginForm = () => { const submitLoginForm = () => {
cy.get('[type=email]').type('admin@koel.test') cy.get('[type=email]').type('admin@koel.test')
cy.get('[type=password]').type('super-secret') cy.get('[type=password]').type('super-secret')
@ -20,6 +16,7 @@ context('Authentication', () => {
fixture: 'data.json' fixture: 'data.json'
}) })
cy.visit('/')
submitLoginForm() submitLoginForm()
cy.get('[id=main]').should('be.visible') cy.get('[id=main]').should('be.visible')
}) })
@ -29,9 +26,17 @@ context('Authentication', () => {
statusCode: 401 statusCode: 401
}) })
cy.visit('/')
submitLoginForm() submitLoginForm()
cy.findByTestId('login-form') cy.findByTestId('login-form')
.should('be.visible') .should('be.visible')
.and('have.class', 'error') .and('have.class', 'error')
}) })
it('logs out', () => {
cy.intercept('DELETE', '/api/me', {})
cy.$login('/')
cy.findByTestId('btn-logout').click()
cy.findByTestId('login-form').should('be.visible')
})
}) })

View file

@ -1 +1,13 @@
import '@testing-library/cypress/add-commands' import '@testing-library/cypress/add-commands'
import AUTWindow = Cypress.AUTWindow
import Chainable = Cypress.Chainable
Cypress.Commands.add('$login', (redirectTo = '/'): Chainable<AUTWindow> => {
window.localStorage.setItem('api-token', 'mock-token')
cy.intercept('api/data', {
fixture: 'data.json'
})
return cy.visit(redirectTo)
})

7
cypress/types.d.ts vendored Normal file
View file

@ -0,0 +1,7 @@
/// <reference types="cypress" />
declare namespace Cypress {
interface Chainable {
$login(redirectTo: string): Chainable
}
}

@ -1 +1 @@
Subproject commit 10e8e490f4fbf8186f093c4a10091448636f9361 Subproject commit 9571bb50bb9cb15e943a7586e505d53247b298b5