From 8373c6f5d18b7fec784be9c10d47cc1dedcad7f6 Mon Sep 17 00:00:00 2001 From: carlosjr Date: Fri, 13 Nov 2020 13:04:22 +0100 Subject: [PATCH] filter by selection + unit tests for travel index --- modules/ticket/front/index/index.spec.js | 4 +- modules/travel/front/index/index.html | 48 ++++++++++++++++++++---- modules/travel/front/index/index.js | 43 +++++++++++++++++++++ modules/travel/front/index/index.spec.js | 28 ++++++++++++++ 4 files changed, 113 insertions(+), 10 deletions(-) diff --git a/modules/ticket/front/index/index.spec.js b/modules/ticket/front/index/index.spec.js index 43b5189bf..27940c63d 100644 --- a/modules/ticket/front/index/index.spec.js +++ b/modules/ticket/front/index/index.spec.js @@ -31,8 +31,8 @@ describe('Component vnTicketIndex', () => { describe('compareDate()', () => { it('should return warning when the date is the present', () => { - let curDate = new Date(); - let result = controller.compareDate(curDate); + let today = new Date(); + let result = controller.compareDate(today); expect(result).toEqual('warning'); }); diff --git a/modules/travel/front/index/index.html b/modules/travel/front/index/index.html index d4d28233e..96a6e3229 100644 --- a/modules/travel/front/index/index.html +++ b/modules/travel/front/index/index.html @@ -9,7 +9,7 @@ - Id + Id Reference Agency Warehouse Out @@ -26,13 +26,21 @@ class="clickable vn-tr search-result" ui-sref="travel.card.summary({id: {{::travel.id}}})"> {{::travel.id}} - {{::travel.ref}} - {{::travel.agencyModeName}} - {{::travel.warehouseOutName}} - {{::travel.shipped | date:'dd/MM/yyyy'}} - + {{::travel.ref}} + {{::travel.agencyModeName}} + {{::travel.warehouseOutName}} + + + {{::travel.shipped | date:'dd/MM/yyyy'}} + + + {{::travel.warehouseInName}} - {{::travel.landed | date:'dd/MM/yyyy'}} + + + {{::travel.landed | date:'dd/MM/yyyy'}} + + @@ -70,4 +78,28 @@ on-accept="$ctrl.onCloneAccept($data)" question="Do you want to clone this travel?" message="All it's properties will be copied"> - \ No newline at end of file + + + + + Filter by selection + + + Exclude selection + + + Remove filter + + + Remove all filters + + + \ No newline at end of file diff --git a/modules/travel/front/index/index.js b/modules/travel/front/index/index.js index d1fd4f381..5cae6fa06 100644 --- a/modules/travel/front/index/index.js +++ b/modules/travel/front/index/index.js @@ -18,6 +18,49 @@ export default class Controller extends Section { }); this.$state.go('travel.create', {q: params}); } + + compareDate(date) { + let today = new Date(); + today.setHours(0, 0, 0, 0); + + date = new Date(date); + date.setHours(0, 0, 0, 0); + + const timeDifference = today - date; + if (timeDifference == 0) return 'warning'; + if (timeDifference < 0) return 'success'; + } + + exprBuilder(param, value) { + switch (param) { + case 'search': + return /^\d+$/.test(value) + ? {'t.id': value} + : {'t.ref': {like: `%${value}%`}}; + case 'ref': + return {'t.ref': {like: `%${value}%`}}; + case 'shipped': + return {'t.shipped': {between: this.dateRange(value)}}; + case 'landed': + return {'t.landed': {between: this.dateRange(value)}}; + case 'id': + case 'agencyFk': + case 'warehouseOutFk': + case 'warehouseInFk': + case 'totalEntries': + param = `t.${param}`; + return {[param]: value}; + } + } + + dateRange(value) { + const minHour = new Date(value); + minHour.setHours(0, 0, 0, 0); + const maxHour = new Date(value); + maxHour.setHours(23, 59, 59, 59); + + return [minHour, maxHour]; + } } ngModule.vnComponent('vnTravelIndex', { diff --git a/modules/travel/front/index/index.spec.js b/modules/travel/front/index/index.spec.js index f88705cc7..1b2ab0a87 100644 --- a/modules/travel/front/index/index.spec.js +++ b/modules/travel/front/index/index.spec.js @@ -47,4 +47,32 @@ describe('Travel Component vnTravelIndex', () => { expect(controller.$state.go).toHaveBeenCalledWith('travel.create', {q: queryParams}); }); }); + + describe('compareDate()', () => { + it('should return warning if the date passed to compareDate() is todays', () => { + const today = new Date(); + + const result = controller.compareDate(today); + + expect(result).toEqual('warning'); + }); + + it('should return success if the date passed to compareDate() is in the future', () => { + const tomorrow = new Date(); + tomorrow.setDate(tomorrow.getDate() + 1); + + const result = controller.compareDate(tomorrow); + + expect(result).toEqual('success'); + }); + + it('should return undefined if the date passed to compareDate() is in the past', () => { + const yesterday = new Date(); + yesterday.setDate(yesterday.getDate() - 1); + + const result = controller.compareDate(yesterday); + + expect(result).toBeUndefined(); + }); + }); });