From bf1697ebd80797168d20eace26281bbca20ebef7 Mon Sep 17 00:00:00 2001 From: Jonathan Niles Date: Wed, 30 Sep 2020 12:21:44 +0100 Subject: [PATCH] fix(test): fix bh-date-editor tests Cherry picked the bh-date-editor changes from #4837 and add the critical await call to prevent test failures. Closes #4919. --- client/src/js/components/bhDateEditor.js | 1 + .../modules/offdays/modals/offday.modal.html | 11 ++++++----- .../src/modules/offdays/modals/offday.modal.js | 18 ++++++++++++------ test/end-to-end/offdays/offdays.page.js | 4 ++-- test/end-to-end/offdays/offdays.spec.js | 4 ++-- .../shared/components/bhDateEditor.js | 2 +- 6 files changed, 24 insertions(+), 16 deletions(-) diff --git a/client/src/js/components/bhDateEditor.js b/client/src/js/components/bhDateEditor.js index a3820d6799..de507c0437 100644 --- a/client/src/js/components/bhDateEditor.js +++ b/client/src/js/components/bhDateEditor.js @@ -6,6 +6,7 @@ angular.module('bhima.components') dateValue : '<', // one-way binding onChange : '&', minDate : ' - - + +
(%) diff --git a/client/src/modules/offdays/modals/offday.modal.js b/client/src/modules/offdays/modals/offday.modal.js index 3a06d623eb..5e71afd5ca 100644 --- a/client/src/modules/offdays/modals/offday.modal.js +++ b/client/src/modules/offdays/modals/offday.modal.js @@ -5,6 +5,12 @@ OffdayModalController.$inject = [ '$state', 'OffdayService', 'NotifyService', 'appcache', 'moment', 'params', ]; +/** + * @function OffdayModalController + * + * @description + * This modal sets the offdays for the payroll module. + */ function OffdayModalController($state, Offdays, Notify, AppCache, moment, params) { const vm = this; vm.offday = {}; @@ -13,11 +19,9 @@ function OffdayModalController($state, Offdays, Notify, AppCache, moment, params if (params.isCreateState || params.id) { cache.stateParams = params; - vm.stateParams = cache.stateParams; - } else { - vm.stateParams = cache.stateParams; } + vm.stateParams = cache.stateParams; vm.isCreateState = vm.stateParams.isCreateState; // update the date @@ -41,11 +45,13 @@ function OffdayModalController($state, Offdays, Notify, AppCache, moment, params function submit(offdayForm) { if (offdayForm.$invalid) { return 0; } - vm.offday.date = moment(vm.offday.date).format('YYYY-MM-DD'); + const data = { ...vm.offday }; + + data.date = moment(data.date).format('YYYY-MM-DD'); const promise = (vm.isCreateState) - ? Offdays.create(vm.offday) - : Offdays.update(vm.offday.id, vm.offday); + ? Offdays.create(data) + : Offdays.update(vm.offday.id, data); return promise .then(() => { diff --git a/test/end-to-end/offdays/offdays.page.js b/test/end-to-end/offdays/offdays.page.js index 38968f75cf..530bd62c85 100644 --- a/test/end-to-end/offdays/offdays.page.js +++ b/test/end-to-end/offdays/offdays.page.js @@ -17,7 +17,7 @@ class OffdayPage { await FU.buttons.create(); await FU.input('OffdayModalCtrl.offday.label', offday.label); - components.dateEditor.set(new Date(offday.date), null, '[uib-modal] .title'); + await components.dateEditor.set(offday.date, 'offday-date-editor'); await FU.input('OffdayModalCtrl.offday.percent_pay', offday.percent_pay); @@ -50,7 +50,7 @@ class OffdayPage { await FU.input('OffdayModalCtrl.offday.label', updateOffday.label); - components.dateEditor.set(new Date(updateOffday.date), null, '[uib-modal] .title'); + await components.dateEditor.set(updateOffday.date, 'offday-date-editor'); await FU.input('OffdayModalCtrl.offday.percent_pay', updateOffday.percent_pay); diff --git a/test/end-to-end/offdays/offdays.spec.js b/test/end-to-end/offdays/offdays.spec.js index 47cdb93a7d..862cedb481 100644 --- a/test/end-to-end/offdays/offdays.spec.js +++ b/test/end-to-end/offdays/offdays.spec.js @@ -8,13 +8,13 @@ describe('Offdays Management', () => { const offday = { label : 'Fete de Parent', - date : '2017-08-01', + date : new Date('2017-08-01'), percent_pay : 100, }; const updateOffday = { label : 'Vingt', - date : '2017-11-24', + date : new Date('2017-11-24'), percent_pay : 100, }; diff --git a/test/end-to-end/shared/components/bhDateEditor.js b/test/end-to-end/shared/components/bhDateEditor.js index dcabf53277..bfb9ca0f98 100644 --- a/test/end-to-end/shared/components/bhDateEditor.js +++ b/test/end-to-end/shared/components/bhDateEditor.js @@ -17,7 +17,7 @@ module.exports = { * @param {String} elementClick - determine a css class that will clicked to * close the selection component Dates. */ - set : async function set(date, id, elementClick) { + set : async function set(date, id, elementClick) => { const elementCloseComponent = elementClick || '.header-image'; // fail hard if the user did not pass into