Skip to content

Commit

Permalink
fix(test): fix bh-date-editor tests
Browse files Browse the repository at this point in the history
Cherry picked the bh-date-editor changes from #4837 and add the critical
await call to prevent test failures.

Closes #4919.
  • Loading branch information
jniles committed Oct 1, 2020
1 parent 2f8790f commit 4b18dad
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 19 deletions.
1 change: 1 addition & 0 deletions client/src/js/components/bhDateEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ angular.module('bhima.components')
dateValue : '<', // one-way binding
onChange : '&',
minDate : '<?',
required : '<?',
maxDate : '<?',
allowFutureDate : '<?',
disabled : '<?',
Expand Down
11 changes: 6 additions & 5 deletions client/src/modules/offdays/modals/offday.modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
</div>
</div>

<bh-date-editor
date-value="OffdayModalCtrl.offday.date"
on-change="OffdayModalCtrl.onDateChange(date)"
allow-future-date="true">
</bh-date-editor>
<bh-date-editor
id="offday-date-editor"
date-value="OffdayModalCtrl.offday.date"
on-change="OffdayModalCtrl.onDateChange(date)"
allow-future-date="true">
</bh-date-editor>

<div class="form-group" ng-class="{ 'has-error' : OffdayForm.$submitted && OffdayForm.percent_pay.$invalid }">
<label class="control-label" translate>FORM.LABELS.PERCENTAGE</label> (%)
Expand Down
18 changes: 12 additions & 6 deletions client/src/modules/offdays/modals/offday.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand All @@ -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
Expand All @@ -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(() => {
Expand Down
4 changes: 2 additions & 2 deletions client/src/modules/templates/bhDateEditor.tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
ng-class="{ 'has-error' : DateEditorForm.$submitted && DateEditorForm.$invalid } "
data-date-editor>

<label class="control-label" translate>
<label class="control-label" bh-date-editor-label translate>
{{ $ctrl.label }}
</label>

Expand All @@ -34,7 +34,7 @@
data-date-editor-input
ng-readonly="!$ctrl.editMode"
ng-disabled="$ctrl.disabled"
ng-required="required">
ng-required="$ctrl.required">
<span class="input-group-btn">
<button
type="button"
Expand Down
4 changes: 2 additions & 2 deletions test/end-to-end/offdays/offdays.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions test/end-to-end/offdays/offdays.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down
4 changes: 2 additions & 2 deletions test/end-to-end/shared/components/bhDateEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ 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) {
const elementCloseComponent = elementClick || '.header-image';
set : async (date, id, elementClick) => {
const elementCloseComponent = elementClick || '[bh-date-editor-label]';

// fail hard if the user did not pass into
/* if (!(date instanceof Date)) {
Expand Down

0 comments on commit 4b18dad

Please sign in to comment.