diff --git a/cypress/integration/authentication.spec.ts b/cypress/integration/authentication.spec.ts index a55c4aa2..5523ee6f 100644 --- a/cypress/integration/authentication.spec.ts +++ b/cypress/integration/authentication.spec.ts @@ -1,10 +1,6 @@ /// 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') + }) }) diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index 5aed0db5..be163e33 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -1 +1,13 @@ import '@testing-library/cypress/add-commands' +import AUTWindow = Cypress.AUTWindow +import Chainable = Cypress.Chainable + +Cypress.Commands.add('$login', (redirectTo = '/'): Chainable => { + window.localStorage.setItem('api-token', 'mock-token') + + cy.intercept('api/data', { + fixture: 'data.json' + }) + + return cy.visit(redirectTo) +}) diff --git a/cypress/types.d.ts b/cypress/types.d.ts new file mode 100644 index 00000000..32eb463d --- /dev/null +++ b/cypress/types.d.ts @@ -0,0 +1,7 @@ +/// + +declare namespace Cypress { + interface Chainable { + $login(redirectTo: string): Chainable + } +} diff --git a/resources/assets b/resources/assets index 10e8e490..9571bb50 160000 --- a/resources/assets +++ b/resources/assets @@ -1 +1 @@ -Subproject commit 10e8e490f4fbf8186f093c4a10091448636f9361 +Subproject commit 9571bb50bb9cb15e943a7586e505d53247b298b5