diff --git a/.vscode/settings.json b/.vscode/settings.json index c8da3d854..59aa4abd3 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,7 +5,6 @@ "editor.defaultFormatter": "johnsoncodehk.volar", "editor.codeActionsOnSave": ["source.fixAll.eslint"], "eslint.validate": ["javascript", "javascriptreact", "typescript", "vue"], - "jest.jestCommandLine": "jest", "json.schemas": [ { "fileMatch": ["cypress.json"], diff --git a/src/components/Navbar.vue b/src/components/Navbar.vue index e26f120d9..a8ee12705 100644 --- a/src/components/Navbar.vue +++ b/src/components/Navbar.vue @@ -62,7 +62,7 @@ function onToggleDrawer() { - + @{{ user.name }} - describe('Login', () => { beforeEach(() => { cy.visit('/#/login'); }); - it('should log in', () => { - cy.get('input[aria-label="Username"]').type('developer') - cy.get('input[aria-label="Password"]').type('nightmare') - cy.get('button[type="submit"]').click() + it('should fail to log in using wrong user', () => { + cy.get('input[aria-label="Username"]').type('incorrectUser'); + cy.get('input[aria-label="Password"]').type('nightmare'); + cy.get('button[type="submit"]').click(); + cy.get('.q-notification__message').should('have.text', 'Invalid username or password'); }); + + it('should fail to log in using wrong password', () => { + cy.get('input[aria-label="Username"]').type('employee'); + cy.get('input[aria-label="Password"]').type('wrongPassword'); + cy.get('button[type="submit"]').click(); + cy.get('.q-notification__message').should('have.text', 'Invalid username or password'); + }); + + it('should log in', () => { + cy.get('input[aria-label="Username"]').type('employee'); + cy.get('input[aria-label="Password"]').type('nightmare'); + cy.get('button[type="submit"]').click(); + cy.get('.q-notification__message').should('have.text', 'You have successfully logged in'); + cy.url().should('contain', '/dashboard'); + }); + + it('should log out', () => { + cy.get('input[aria-label="Username"]').type('employee'); + cy.get('input[aria-label="Password"]').type('nightmare'); + cy.get('button[type="submit"]').click(); + cy.get('.q-notification__message').should('have.text', 'You have successfully logged in'); + cy.url().should('contain', '/dashboard'); + cy.get('#user').click(); + cy.get('#logout').click(); + cy.window().its('localStorage').invoke('getItem', 'token').should('not.exist'); + cy.url().should('contain', '/login'); + }) + + it(`should get redirected to dashboard since employee can't create tickets`, () => { + cy.visit('/#/ticket/create', { failOnStatusCode: false }); + cy.url().should('contain', '/#/login?redirect=/ticket/create'); + cy.get('input[aria-label="Username"]').type('employee'); + cy.get('input[aria-label="Password"]').type('nightmare'); + cy.get('button[type="submit"]').click(); + cy.url().should('contain', '/dashboard'); + }) + + it(`should get redirected to ticket creation after login since salesPerson can do it`, () => { + cy.visit('/#/ticket/create', { failOnStatusCode: false }); + cy.url().should('contain', '/#/login?redirect=/ticket/create'); + cy.get('input[aria-label="Username"]').type('salesPerson'); + cy.get('input[aria-label="Password"]').type('nightmare'); + cy.get('button[type="submit"]').click(); + cy.url().should('contain', '/#/ticket/create'); + }) }); \ No newline at end of file diff --git a/tests/cypress/support/commands.js b/tests/cypress/support/commands.js index f8cbd2dfb..031c738da 100755 --- a/tests/cypress/support/commands.js +++ b/tests/cypress/support/commands.js @@ -27,4 +27,17 @@ // DO NOT REMOVE // Imports Quasar Cypress AE predefined commands import { registerCommands } from '@quasar/quasar-app-extension-testing-e2e-cypress'; +Cypress.Commands.add('login', (user) => { + cy.visit('/#/login'); + cy.request({ + method: 'POST', + url: '/api/accounts/login', + body: { + user: user, + password: 'nightmare' + } + }).then(response => { + window.localStorage.setItem('token', response.body.token); + }) +}) registerCommands();