e2e path for login, logout and nav ACLs
gitea/salix-front/pipeline/head This commit looks good Details

This commit is contained in:
Carlos Jimenez Ruiz 2022-05-23 15:46:09 +02:00
parent 229ddb8f2d
commit 157f218c97
5 changed files with 65 additions and 7 deletions

View File

@ -5,7 +5,6 @@
"editor.defaultFormatter": "johnsoncodehk.volar", "editor.defaultFormatter": "johnsoncodehk.volar",
"editor.codeActionsOnSave": ["source.fixAll.eslint"], "editor.codeActionsOnSave": ["source.fixAll.eslint"],
"eslint.validate": ["javascript", "javascriptreact", "typescript", "vue"], "eslint.validate": ["javascript", "javascriptreact", "typescript", "vue"],
"jest.jestCommandLine": "jest",
"json.schemas": [ "json.schemas": [
{ {
"fileMatch": ["cypress.json"], "fileMatch": ["cypress.json"],

View File

@ -62,7 +62,7 @@ function onToggleDrawer() {
</div> </div>
</q-menu> </q-menu>
</q-btn> </q-btn>
<q-btn dense flat no-wrap> <q-btn dense flat no-wrap id="user">
<q-avatar size="lg"> <q-avatar size="lg">
<q-img <q-img
:src="`/api/Images/user/160x160/${user.id}/download?access_token=${token}`" :src="`/api/Images/user/160x160/${user.id}/download?access_token=${token}`"

View File

@ -100,6 +100,7 @@ function logout() {
<div class="text-subtitle3 text-grey-7 q-mb-xs">@{{ user.name }}</div> <div class="text-subtitle3 text-grey-7 q-mb-xs">@{{ user.name }}</div>
<q-btn <q-btn
id="logout"
color="orange" color="orange"
flat flat
:label="t('globals.logOut')" :label="t('globals.logOut')"

View File

@ -1,13 +1,58 @@
/// <reference types="cypress" /> /// <reference types="cypress" />
describe('Login', () => { describe('Login', () => {
beforeEach(() => { beforeEach(() => {
cy.visit('/#/login'); cy.visit('/#/login');
}); });
it('should log in', () => { it('should fail to log in using wrong user', () => {
cy.get('input[aria-label="Username"]').type('developer') cy.get('input[aria-label="Username"]').type('incorrectUser');
cy.get('input[aria-label="Password"]').type('nightmare') cy.get('input[aria-label="Password"]').type('nightmare');
cy.get('button[type="submit"]').click() 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');
})
}); });

View File

@ -27,4 +27,17 @@
// DO NOT REMOVE // DO NOT REMOVE
// Imports Quasar Cypress AE predefined commands // Imports Quasar Cypress AE predefined commands
import { registerCommands } from '@quasar/quasar-app-extension-testing-e2e-cypress'; 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(); registerCommands();