diff --git a/client/core/src/autocomplete/autocomplete.spec.js b/client/core/src/autocomplete/autocomplete.spec.js index b554973dd..619cba24d 100644 --- a/client/core/src/autocomplete/autocomplete.spec.js +++ b/client/core/src/autocomplete/autocomplete.spec.js @@ -204,6 +204,7 @@ describe('Component vnAutocomplete', () => { expect(controller.getItems).toHaveBeenCalledWith(); }); }); + describe('getItem()', () => { it(`should perfom a query to fill the items without filter`, () => { let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout}, {url: 'test.com'}); diff --git a/client/core/src/datePicker/datePicker.js b/client/core/src/datePicker/datePicker.js index 70a6344b8..79d7d6cd9 100644 --- a/client/core/src/datePicker/datePicker.js +++ b/client/core/src/datePicker/datePicker.js @@ -48,9 +48,8 @@ class DatePicker extends Component { this._modelView = value; this.input.value = value; this._setModel(value); - this.$timeout( - () => { - this.mdlUpdate(); + this.$timeout(() => { + this.mdlUpdate(); }, 500); } onClear() { @@ -76,9 +75,8 @@ class DatePicker extends Component { return `${dates} ${hours}`.trim(); } else if (string.indexOf(':') !== -1) { // only time format return parts.join(':'); - } else { // only date format - return parts.join('-'); - } + } // only date format + return parts.join('-'); } _setModel(value) { diff --git a/client/core/src/datePicker/datePicker.spec.js b/client/core/src/datePicker/datePicker.spec.js new file mode 100644 index 000000000..ebea87ccf --- /dev/null +++ b/client/core/src/datePicker/datePicker.spec.js @@ -0,0 +1,45 @@ +import './datePicker.js'; + +describe('Component vnDatePicker', () => { + let $componentController; + let $scope; + let $timeout; + let $element; + let $translate; + + beforeEach(() => { + angular.mock.module('client'); + }); + + beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$timeout_) => { + $componentController = _$componentController_; + $scope = $rootScope.$new(); + $timeout = _$timeout_; + $element = angular.element(`
`); + $translate = {}; + })); + + describe('_formatFlat2Angular()', () => { + it(`should format date from Y-m-d to yyyy-MM-dd`, () => { + let controller = $componentController('vnDatePicker', {$scope, $element, $translate, $timeout}); + let formatedDate = controller._formatFlat2Angular(`Y-m-d`); + + expect(formatedDate).toBe('yyyy-MM-dd'); + }); + + it(`should format date from d-m-Y to dd-MM-yyyy`, () => { + let controller = $componentController('vnDatePicker', {$scope, $element, $translate, $timeout}); + let formatedDate = controller._formatFlat2Angular(`d-m-Y`); + + expect(formatedDate).toBe('dd-MM-yyyy'); + }); + + it(`should split the given string into parts`, () => { + let controller = $componentController('vnDatePicker', {$scope, $element, $translate, $timeout}); + controller.iniOptions = {dateFormat: 'd/m/Y'}; + controller.model = '2017-12-23'; + + expect(controller.modelView).toBe('23-12-2017'); + }); + }); +});