From cacd36a854b100c9fb55466ea4a976ebc55ae5b9 Mon Sep 17 00:00:00 2001 From: alexandre Date: Thu, 27 Apr 2023 10:40:00 +0200 Subject: [PATCH] refs #5255 tests fixed --- src/boot/axios.js | 5 ++- src/pages/Login/LoginMain.vue | 34 +++++++++++-------- test/cypress/integration/claimPhoto.spec.js | 4 +-- test/cypress/integration/ticketBoxing.spec.js | 8 ++--- test/cypress/integration/workerList.spec.js | 5 ++- .../cypress/integration/workerSummary.spec.js | 4 +-- test/vitest/__tests__/boot/axios.spec.js | 12 +++---- 7 files changed, 41 insertions(+), 31 deletions(-) diff --git a/src/boot/axios.js b/src/boot/axios.js index 2f454188e..cbd5e7213 100644 --- a/src/boot/axios.js +++ b/src/boot/axios.js @@ -58,9 +58,12 @@ const onResponseError = (error) => { break; } - if (session.isLoggedIn && response.status === 401) { + if (session.isLoggedIn() && response.status === 401) { session.destroy(); Router.push({ path: '/login' }); + } else if(!session.isLoggedIn()) + { + message = 'login.loginError'; } Notify.create({ diff --git a/src/pages/Login/LoginMain.vue b/src/pages/Login/LoginMain.vue index 7fb0ee408..747fe8b14 100644 --- a/src/pages/Login/LoginMain.vue +++ b/src/pages/Login/LoginMain.vue @@ -48,25 +48,29 @@ const password = ref(''); const keepLogin = ref(true); async function onSubmit() { - const { data } = await axios.post('Accounts/login', { - user: username.value, - password: password.value, - }); + try { + const { data } = await axios.post('Accounts/login', { + user: username.value, + password: password.value, + }); - if (!data) return; + if (!data) return; - await session.login(data.token, keepLogin.value); + await session.login(data.token, keepLogin.value); - quasar.notify({ - message: t('login.loginSuccess'), - type: 'positive', - }); + quasar.notify({ + message: t('login.loginSuccess'), + type: 'positive', + }); - const currentRoute = router.currentRoute.value; - if (currentRoute.query && currentRoute.query.redirect) { - router.push(currentRoute.query.redirect); - } else { - router.push({ name: 'Dashboard' }); + const currentRoute = router.currentRoute.value; + if (currentRoute.query && currentRoute.query.redirect) { + router.push(currentRoute.query.redirect); + } else { + router.push({ name: 'Dashboard' }); + } + } catch (e) { + // } } diff --git a/test/cypress/integration/claimPhoto.spec.js b/test/cypress/integration/claimPhoto.spec.js index e5ea2ce25..ec41e92a3 100755 --- a/test/cypress/integration/claimPhoto.spec.js +++ b/test/cypress/integration/claimPhoto.spec.js @@ -43,13 +43,13 @@ describe('ClaimPhoto', () => { cy.get( '.multimediaParent > :nth-child(3) > .q-btn > .q-btn__content > .q-icon' ).click(); - cy.get('.q-btn--standard > .q-btn__content > .block').click(); + cy.get('.q-btn--unelevated > .q-btn__content > .block').click(); cy.get('.q-notification__message').should('have.text', 'Data deleted'); cy.get( '.multimediaParent > :nth-child(3) > .q-btn > .q-btn__content > .q-icon' ).click(); - cy.get('.q-btn--standard > .q-btn__content > .block').click(); + cy.get('.q-btn--unelevated > .q-btn__content > .block').click(); cy.get('.q-notification__message').should('have.text', 'Data deleted'); }); }); diff --git a/test/cypress/integration/ticketBoxing.spec.js b/test/cypress/integration/ticketBoxing.spec.js index 7a1ed669d..7b3bd36cc 100755 --- a/test/cypress/integration/ticketBoxing.spec.js +++ b/test/cypress/integration/ticketBoxing.spec.js @@ -1,5 +1,5 @@ /// -xdescribe('TicketBoxing', () => { +describe('TicketBoxing', () => { beforeEach(() => { const ticketId = 1; cy.viewport(1280, 720); @@ -26,9 +26,9 @@ xdescribe('TicketBoxing', () => { }, ['2022-01-01T01-01-00.mp4', '2022-02-02T02-02-00.mp4', '2022-03-03T03-03-00.mp4'] ).as('getVideoList'); - cy.get('.q-list > :nth-child(3)').click(); + cy.get('.q-list').eq(3).find('.q-item').eq(2).click(); - cy.get('.q-list > :nth-child(1)').should('be.visible'); - cy.get('.q-list > :nth-child(2)').should('be.visible'); + cy.get('.q-list').eq(3).find('.q-item').eq(0).find('.q-range'); + cy.get('.q-list').eq(3).find('.q-item').eq(1).find('.q-select'); }); }); diff --git a/test/cypress/integration/workerList.spec.js b/test/cypress/integration/workerList.spec.js index 9f3d62448..79f2400bf 100644 --- a/test/cypress/integration/workerList.spec.js +++ b/test/cypress/integration/workerList.spec.js @@ -12,7 +12,10 @@ describe('WorkerList', () => { }); it('should open the worker summary', () => { - cy.get('div[class="q-item__section column q-item__section--side justify-center q-pa-md"]').eq(0).click(); + cy.get('div.text-h6') + .parentsUntil('div.q-card') + .find('div.q-card__actions') + .find('button').first().click(); cy.get('div[class="header bg-primary q-pa-sm q-mb-md"').should('have.text', '1110 - Jessica Jones'); cy.get('div[class="q-item__label q-item__label--header text-h6"]').eq(0).should('have.text', 'Basic data'); cy.get('div[class="q-item__label q-item__label--header text-h6"]').eq(1).should('have.text', 'User data'); diff --git a/test/cypress/integration/workerSummary.spec.js b/test/cypress/integration/workerSummary.spec.js index ae01378f6..cef26d061 100644 --- a/test/cypress/integration/workerSummary.spec.js +++ b/test/cypress/integration/workerSummary.spec.js @@ -6,10 +6,10 @@ describe('WorkerSummary', () => { }); it('should load worker summary', () => { - cy.get('div[class="header bg-primary q-pa-sm q-mb-md"').should('have.text', '19 - salesBoss'); + cy.get('div[class="header bg-primary q-pa-sm q-mb-md"').should('have.text', '19 - salesBoss salesBoss'); cy.get('div[class="q-item__label q-item__label--header text-h6"]').eq(0).should('have.text', 'Basic data'); cy.get('div[class="q-item__label q-item__label--header text-h6"]').eq(1).should('have.text', 'User data'); cy.get('div[class="q-item__section column q-item__section--main justify-center"]').eq(0).should('have.text', 'NamesalesBossNick'); }); -}); \ No newline at end of file +}); diff --git a/test/vitest/__tests__/boot/axios.spec.js b/test/vitest/__tests__/boot/axios.spec.js index a95c57fba..feb0d93ea 100644 --- a/test/vitest/__tests__/boot/axios.spec.js +++ b/test/vitest/__tests__/boot/axios.spec.js @@ -1,15 +1,15 @@ -import { vi, describe, expect, it } from 'vitest'; +import { Notify } from 'quasar'; import { onRequest, onResponseError } from 'src/boot/axios'; -import { Notify } from 'quasar' +import { describe, expect, it, vi } from 'vitest'; vi.mock('src/composables/useSession', () => ({ useSession: () => ({ - getToken: () => 'DEFAULT_TOKEN' - }), + getToken: () => 'DEFAULT_TOKEN', + isLoggedIn: () => vi.fn(), + destroy: () => vi.fn(), + }) })); -vi.mock('src/router', () => ({})); - describe('Axios boot', () => { describe('onRequest()', async () => {