From 96c16727ff47da136a6b805409ea149399c3037a Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 28 Sep 2022 15:01:08 +0200 Subject: [PATCH] test(ticketBoxing): front test --- src/i18n/en/index.js | 4 +- src/i18n/es/index.js | 3 +- src/pages/Login/__tests__/Login.spec.js | 2 +- src/pages/Ticket/Card/TicketBoxing.vue | 13 +++- .../Card/__tests__/TicketBoxing.spec.js | 69 +++++++++++++++++++ 5 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 src/pages/Ticket/Card/__tests__/TicketBoxing.spec.js diff --git a/src/i18n/en/index.js b/src/i18n/en/index.js index 4211416ca..4b3105afa 100644 --- a/src/i18n/en/index.js +++ b/src/i18n/en/index.js @@ -63,7 +63,9 @@ export default { created: 'Created', worker: 'Worker', selectTime: 'Select time:', - selectVideo: 'Select video:' + selectVideo: 'Select video:', + notFound: 'No videos available' + } }, components: { diff --git a/src/i18n/es/index.js b/src/i18n/es/index.js index dd147ac42..91c43985f 100644 --- a/src/i18n/es/index.js +++ b/src/i18n/es/index.js @@ -63,7 +63,8 @@ export default { created: 'Creado', worker: 'Trabajador', selectTime: 'Seleccionar hora:', - selectVideo: 'Seleccionar video:' + selectVideo: 'Seleccionar vídeo:', + notFound: 'No hay vídeos disponibles' } }, components: { diff --git a/src/pages/Login/__tests__/Login.spec.js b/src/pages/Login/__tests__/Login.spec.js index 87f8de487..ee5ef237b 100644 --- a/src/pages/Login/__tests__/Login.spec.js +++ b/src/pages/Login/__tests__/Login.spec.js @@ -33,7 +33,7 @@ describe('Login', () => { } jest.spyOn(axios, 'post').mockResolvedValue({ data: { token: 'token' } }); jest.spyOn(axios, 'get').mockResolvedValue({ data: { roles: [], user: expectedUser } }); - jest.spyOn(vm.quasar, 'notify') + jest.spyOn(vm.quasar, 'notify'); expect(vm.session.getToken()).toEqual(''); diff --git a/src/pages/Ticket/Card/TicketBoxing.vue b/src/pages/Ticket/Card/TicketBoxing.vue index e173d5580..81d6fa77b 100644 --- a/src/pages/Ticket/Card/TicketBoxing.vue +++ b/src/pages/Ticket/Card/TicketBoxing.vue @@ -3,10 +3,11 @@ import { useI18n } from 'vue-i18n'; import { computed, ref, onMounted } from 'vue'; import { useRouter } from 'vue-router'; import axios from 'axios'; -import { date } from 'quasar'; +import { date, useQuasar } from 'quasar'; const router = useRouter(); const { t } = useI18n(); +const quasar = useQuasar(); onMounted(async () => { await fetch(); @@ -48,8 +49,8 @@ async function getVideoList(expeditionId, timed) { Object.assign(params, { from: timed.min, to: timed.max }); } const { data } = await axios.get(`/Boxings/getVideoList`, { params: params }); - const list = []; + const list = []; for (const video of data) { const videName = video.split('.')[0].split('T')[1].replaceAll('-', ':'); list.push({ @@ -62,12 +63,18 @@ async function getVideoList(expeditionId, timed) { videoList.value = list.reverse(); if (list[0]) { slide.value = list[0].value; - console.log({ min: list[0].label.split(':')[0], max: list[list.length - 1].label.split(':')[0] }); time.value = { min: parseInt(list[0].label.split(':')[0]), max: parseInt(list[list.length - 1].label.split(':')[0]), }; } + + if (!data.length) { + return quasar.notify({ + message: t('ticket.boxing.notFound'), + type: 'negative', + }); + } } diff --git a/src/pages/Ticket/Card/__tests__/TicketBoxing.spec.js b/src/pages/Ticket/Card/__tests__/TicketBoxing.spec.js new file mode 100644 index 000000000..078350471 --- /dev/null +++ b/src/pages/Ticket/Card/__tests__/TicketBoxing.spec.js @@ -0,0 +1,69 @@ +import { jest, describe, expect, it, beforeAll } from '@jest/globals'; +import { createWrapper, axios } from 'app/tests/jest/jestHelpers'; +import TicketBoxing from '../TicketBoxing.vue'; + +const mockPush = jest.fn(); + +jest.mock('vue-router', () => ({ + useRouter: () => ({ + push: mockPush, + currentRoute: { + value: { + params: { + id: 1 + } + } + } + }), +})); + +describe('TicketBoxing', () => { + let vm; + beforeAll(() => { + vm = createWrapper(TicketBoxing).vm; + }); + + afterEach(() => { + jest.clearAllMocks(); + }); + + describe('getVideoList()', () => { + it('should when response videoList use to list', async () => { + const expeditionId = 1; + const timed = { + min: 1, + max: 2 + } + const videoList = [ + "2022-01-01T01-01-00.mp4", + "2022-02-02T02-02-00.mp4", + "2022-03-03T03-03-00.mp4", + ] + + jest.spyOn(axios, 'get').mockResolvedValue({ data: videoList }); + jest.spyOn(vm.quasar, 'notify'); + + await vm.getVideoList(expeditionId, timed); + + expect(vm.videoList.length).toEqual(videoList.length); + expect(vm.slide).toEqual(videoList.reverse()[0]); + }); + + it('should if not have video show notify', async () => { + const expeditionId = 1; + const timed = { + min: 1, + max: 2 + } + + jest.spyOn(axios, 'get').mockResolvedValue({ data: [] }); + jest.spyOn(vm.quasar, 'notify') + + await vm.getVideoList(expeditionId, timed); + + expect(vm.quasar.notify).toHaveBeenCalledWith(expect.objectContaining( + { 'type': 'negative' } + )); + }); + }); +});