diff --git a/modules/route/front/main/index.spec.js b/modules/route/front/main/index.spec.js index b6df9fd73..e5724b493 100644 --- a/modules/route/front/main/index.spec.js +++ b/modules/route/front/main/index.spec.js @@ -38,20 +38,12 @@ describe('Route Component vnRoute', () => { expect(params.scopeDays).toEqual(1); }); - it('should return a number value in scope days', () => { + it('should return the given scope days', () => { let params = controller.fetchParams({ scopeDays: 2 }); expect(params.scopeDays).toEqual(2); }); - - it('should throw an error when scope days is not equal a number', () => { - let params = controller.fetchParams({ - scopeDays: 'ScopeDayNoNumber' - }); - - expect(params.scopeDays).toBe('ScopeDayNoNumber'); - }); }); }); diff --git a/modules/travel/front/main/index.spec.js b/modules/travel/front/main/index.spec.js index 96d819a6f..6d9db4dc8 100644 --- a/modules/travel/front/main/index.spec.js +++ b/modules/travel/front/main/index.spec.js @@ -12,29 +12,38 @@ describe('Travel Component vnTravel', () => { describe('fetchParams()', () => { it('should return a range of dates with passed scope days', () => { - /** - * Calculates the difference in days between two dates, it also - * accounts for cases where the two dates in question span a - * daylight saving time (DST) change. - * - * @param {Date} a The start date - * @param {Date} b The end date - * @return {Number} The difference in days - */ - function diffInDays(a, b) { - const utc1 = Date.UTC(a.getFullYear(), a.getMonth(), a.getDate()); - const utc2 = Date.UTC(b.getFullYear(), b.getMonth(), b.getDate()); - const msInDay = 86400 * 1000; - return Math.floor((utc2 - utc1) / msInDay); - } + let params = controller.fetchParams({ + scopeDays: 2 + }); + const shippedFrom = new Date(); + shippedFrom.setHours(0, 0, 0, 0); + const shippedTo = new Date(shippedFrom.getTime()); + shippedTo.setDate(shippedTo.getDate() + params.scopeDays); + shippedTo.setHours(23, 59, 59, 999); - let params = controller.fetchParams({scopeDays: 2}); - const diff = diffInDays( - params.shippedFrom, - new Date(params.shippedTo.getTime() + 1) - ); + const expectedParams = { + shippedFrom, + scopeDays: params.scopeDays, + shippedTo + }; - expect(diff).toEqual(3); + expect(params).toEqual(expectedParams); + }); + + it('should return default value for scope days', () => { + let params = controller.fetchParams({ + scopeDays: 1 + }); + + expect(params.scopeDays).toEqual(1); + }); + + it('should return the given scope days', () => { + let params = controller.fetchParams({ + scopeDays: 2 + }); + + expect(params.scopeDays).toEqual(2); }); }); }); diff --git a/modules/travel/front/search-panel/index.html b/modules/travel/front/search-panel/index.html index afc041f66..8e7f4140d 100644 --- a/modules/travel/front/search-panel/index.html +++ b/modules/travel/front/search-panel/index.html @@ -1,6 +1,6 @@
-
- + + - + - + - - - - - - - +
+ + + + + + Or + + + + + +
+ - + - + diff --git a/modules/travel/front/search-panel/index.js b/modules/travel/front/search-panel/index.js index 8aa25e594..877d4f9d3 100644 --- a/modules/travel/front/search-panel/index.js +++ b/modules/travel/front/search-panel/index.js @@ -1,7 +1,43 @@ import ngModule from '../module'; import SearchPanel from 'core/components/searchbar/search-panel'; +class Controller extends SearchPanel { + constructor($, $element) { + super($, $element); + this.filter = this.$.filter; + } + + get shippedFrom() { + return this._shippedFrom; + } + + set shippedFrom(value) { + this._shippedFrom = value; + this.filter.scopeDays = null; + } + + get shippedTo() { + return this._shippedTo; + } + + set shippedTo(value) { + this._shippedTo = value; + this.filter.scopeDays = null; + } + + get scopeDays() { + return this._scopeDays; + } + + set scopeDays(value) { + this._scopeDays = value; + + this.filter.shippedFrom = null; + this.filter.shippedTo = null; + } +} + ngModule.vnComponent('vnTravelSearchPanel', { template: require('./index.html'), - controller: SearchPanel + controller: Controller }); diff --git a/modules/travel/front/search-panel/index.spec.js b/modules/travel/front/search-panel/index.spec.js new file mode 100644 index 000000000..a1f3c36b3 --- /dev/null +++ b/modules/travel/front/search-panel/index.spec.js @@ -0,0 +1,48 @@ +import './index'; + +describe('Travel Component vnTravelSearchPanel', () => { + let controller; + + beforeEach(ngModule('travel')); + + beforeEach(inject($componentController => { + controller = $componentController('vnTravelSearchPanel', {$element: null}); + controller.$t = () => {}; + controller.filter = {}; + })); + + describe('shippedFrom() setter', () => { + it('should clear the scope days when setting the from property', () => { + controller.filter.scopeDays = 1; + + controller.shippedFrom = new Date(); + + expect(controller.filter.scopeDays).toBeNull(); + expect(controller.shippedFrom).toBeDefined(); + }); + }); + + describe('shippedTo() setter', () => { + it('should clear the scope days when setting the to property', () => { + controller.filter.scopeDays = 1; + + controller.shippedTo = new Date(); + + expect(controller.filter.scopeDays).toBeNull(); + expect(controller.shippedTo).toBeDefined(); + }); + }); + + describe('scopeDays() setter', () => { + it('should clear the date range when setting the scopeDays property', () => { + controller.filter.shippedFrom = new Date(); + controller.filter.shippedTo = new Date(); + + controller.scopeDays = 1; + + expect(controller.filter.shippedFrom).toBeNull(); + expect(controller.filter.shippedTo).toBeNull(); + expect(controller.scopeDays).toBeDefined(); + }); + }); +});