From 0baccc47453e2964a6b392cde9a0c78204846c5b Mon Sep 17 00:00:00 2001 From: alexandre Date: Fri, 24 Mar 2023 08:25:37 +0100 Subject: [PATCH] refs #5206 fix tests front --- modules/travel/front/index/index.html | 29 ----------- modules/travel/front/index/index.js | 31 ------------ modules/travel/front/main/index.js | 3 ++ modules/travel/front/main/index.spec.js | 49 ------------------- .../travel/front/search-panel/index.spec.js | 48 +++++++----------- 5 files changed, 22 insertions(+), 138 deletions(-) delete mode 100644 modules/travel/front/main/index.spec.js diff --git a/modules/travel/front/index/index.html b/modules/travel/front/index/index.html index a6952321f..a768e4a29 100644 --- a/modules/travel/front/index/index.html +++ b/modules/travel/front/index/index.html @@ -105,32 +105,3 @@ question="Do you want to clone this travel?" message="All it's properties will be copied"> - - - - Filter by selection - - - Exclude selection - - - Remove filter - - - Remove all filters - - - Copy value - - - diff --git a/modules/travel/front/index/index.js b/modules/travel/front/index/index.js index 2c8f8fc8a..a570146fe 100644 --- a/modules/travel/front/index/index.js +++ b/modules/travel/front/index/index.js @@ -31,37 +31,6 @@ export default class Controller extends Section { 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 'agencyModeFk': - 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/main/index.js b/modules/travel/front/main/index.js index 82ebe61af..6a153f21a 100644 --- a/modules/travel/front/main/index.js +++ b/modules/travel/front/main/index.js @@ -2,6 +2,9 @@ import ngModule from '../module'; import ModuleMain from 'salix/components/module-main'; export default class Travel extends ModuleMain { + constructor() { + super(); + } } ngModule.vnComponent('vnTravel', { diff --git a/modules/travel/front/main/index.spec.js b/modules/travel/front/main/index.spec.js deleted file mode 100644 index bf5a27b41..000000000 --- a/modules/travel/front/main/index.spec.js +++ /dev/null @@ -1,49 +0,0 @@ -import './index.js'; - -describe('Travel Component vnTravel', () => { - let controller; - - beforeEach(ngModule('travel')); - - beforeEach(inject($componentController => { - let $element = angular.element(`
`); - controller = $componentController('vnTravel', {$element}); - })); - - describe('fetchParams()', () => { - it('should return a range of dates with passed scope days', () => { - let params = controller.fetchParams({ - scopeDays: 2 - }); - const shippedFrom = Date.vnNew(); - shippedFrom.setHours(0, 0, 0, 0); - const shippedTo = new Date(shippedFrom.getTime()); - shippedTo.setDate(shippedTo.getDate() + params.scopeDays); - shippedTo.setHours(23, 59, 59, 999); - - const expectedParams = { - shippedFrom, - scopeDays: params.scopeDays, - shippedTo - }; - - 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.spec.js b/modules/travel/front/search-panel/index.spec.js index 884f4fb17..488143e80 100644 --- a/modules/travel/front/search-panel/index.spec.js +++ b/modules/travel/front/search-panel/index.spec.js @@ -8,41 +8,31 @@ describe('Travel Component vnTravelSearchPanel', () => { 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; + describe('applyFilters()', () => { + it('should apply filters', async() => { + controller.filter = {foo: 'bar'}; + controller.model = { + applyFilter: jest.fn().mockResolvedValue(), + _orgData: [{id: 1}] + }; + controller.$state = { + current: { + name: 'foo' + }, + go: jest.fn() + }; - controller.shippedFrom = Date.vnNew(); + await controller.applyFilters(true); - expect(controller.filter.scopeDays).toBeNull(); - expect(controller.shippedFrom).toBeDefined(); - }); - }); + expect(controller.model.applyFilter).toHaveBeenCalledWith({}, controller.filter); + expect(controller.$state.go).toHaveBeenCalledWith('travel.card.summary', {id: 1}); - describe('shippedTo() setter', () => { - it('should clear the scope days when setting the to property', () => { - controller.filter.scopeDays = 1; + await controller.applyFilters(false); - controller.shippedTo = Date.vnNew(); - - 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 = Date.vnNew(); - controller.filter.shippedTo = Date.vnNew(); - - controller.scopeDays = 1; - - expect(controller.filter.shippedFrom).toBeNull(); - expect(controller.filter.shippedTo).toBeNull(); - expect(controller.scopeDays).toBeDefined(); + expect(controller.$state.go).toHaveBeenCalledWith(controller.$state.current.name, + {q: JSON.stringify(controller.filter)}, {location: 'replace'}); }); }); });