From 540d5e9e718df0af9eaa2ead1ad198baf354c51a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20S=C3=A1nchez?= Date: Tue, 18 Aug 2020 13:50:08 +0200 Subject: [PATCH] Fixed errors --- modules/worker/front/calendar/index.js | 5 +++++ modules/worker/front/calendar/index.spec.js | 25 +++++++++++++++++++++ modules/worker/front/calendar/locale/es.yml | 3 ++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/modules/worker/front/calendar/index.js b/modules/worker/front/calendar/index.js index 7bbdb894e..006725172 100644 --- a/modules/worker/front/calendar/index.js +++ b/modules/worker/front/calendar/index.js @@ -19,6 +19,8 @@ class Controller extends Section { newYear.setFullYear(value); this.date = newYear; + + this.refresh().then(() => this.repaint()); } get date() { @@ -140,6 +142,9 @@ class Controller extends Section { if (!this.absenceType) return this.vnApp.showMessage(this.$t('Choose an absence type from the right menu')); + if (this.year != new Date().getFullYear()) + return this.vnApp.showMessage(this.$t('You can just add absences within the current year')); + const day = $days[0]; const stamp = day.getTime(); const event = this.events[stamp]; diff --git a/modules/worker/front/calendar/index.spec.js b/modules/worker/front/calendar/index.spec.js index 6b5025dae..7637f3a16 100644 --- a/modules/worker/front/calendar/index.spec.js +++ b/modules/worker/front/calendar/index.spec.js @@ -30,11 +30,14 @@ describe('Worker', () => { describe('year() setter', () => { it(`should set the year of the calendar date`, () => { + jest.spyOn(controller, 'refresh').mockReturnValue(new Promise()); + const previousYear = year - 1; controller.year = previousYear; expect(controller.year).toEqual(previousYear); expect(controller.date.getFullYear()).toEqual(previousYear); + expect(controller.refresh).toHaveBeenCalledWith(); }); }); @@ -157,6 +160,28 @@ describe('Worker', () => { expect(controller.vnApp.showMessage).toHaveBeenCalledWith('Choose an absence type from the right menu'); }); + it(`should show an snackbar message if the selected day is not within the current year`, () => { + jest.spyOn(controller.vnApp, 'showMessage').mockReturnThis(); + + const selectedDay = new Date(); + const $event = { + target: { + closest: () => { + return {$ctrl: {}}; + } + } + }; + const $days = [selectedDay]; + const pastYear = new Date(); + pastYear.setFullYear(pastYear.getFullYear() - 1); + + controller.date = pastYear; + controller.absenceType = {id: 1}; + controller.onSelection($event, $days); + + expect(controller.vnApp.showMessage).toHaveBeenCalledWith('You can just add absences within the current year'); + }); + it(`should call to the create() method`, () => { jest.spyOn(controller, 'create').mockReturnThis(); diff --git a/modules/worker/front/calendar/locale/es.yml b/modules/worker/front/calendar/locale/es.yml index f48a67c7b..68a9cf54d 100644 --- a/modules/worker/front/calendar/locale/es.yml +++ b/modules/worker/front/calendar/locale/es.yml @@ -5,4 +5,5 @@ Year: Año of: de days: días Choose an absence type from the right menu: Elige un tipo de ausencia desde el menú de la derecha -To start adding absences, click an absence type from the right menu and then on the day you want to add an absence: Para empezar a añadir ausencias, haz clic en un tipo de ausencia desde el menu de la derecha y después en el día que quieres añadir la ausencia \ No newline at end of file +To start adding absences, click an absence type from the right menu and then on the day you want to add an absence: Para empezar a añadir ausencias, haz clic en un tipo de ausencia desde el menu de la derecha y después en el día que quieres añadir la ausencia +You can just add absences within the current year: Solo puedes añadir ausencias dentro del año actual \ No newline at end of file