mirror of
https://github.com/koel/koel
synced 2024-09-20 06:11:53 +00:00
feat(test): complete authentication E2E tests
This commit is contained in:
parent
d29a2dcf39
commit
9740bf8d12
4 changed files with 29 additions and 5 deletions
|
@ -1,10 +1,6 @@
|
|||
/// <reference types="cypress" />
|
||||
|
||||
context('Authentication', () => {
|
||||
beforeEach(() => {
|
||||
cy.visit('/')
|
||||
})
|
||||
|
||||
const submitLoginForm = () => {
|
||||
cy.get('[type=email]').type('admin@koel.test')
|
||||
cy.get('[type=password]').type('super-secret')
|
||||
|
@ -20,6 +16,7 @@ context('Authentication', () => {
|
|||
fixture: 'data.json'
|
||||
})
|
||||
|
||||
cy.visit('/')
|
||||
submitLoginForm()
|
||||
cy.get('[id=main]').should('be.visible')
|
||||
})
|
||||
|
@ -29,9 +26,17 @@ context('Authentication', () => {
|
|||
statusCode: 401
|
||||
})
|
||||
|
||||
cy.visit('/')
|
||||
submitLoginForm()
|
||||
cy.findByTestId('login-form')
|
||||
.should('be.visible')
|
||||
.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')
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1 +1,13 @@
|
|||
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
7
cypress/types.d.ts
vendored
Normal 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
|
Loading…
Reference in a new issue