From 9849c60651596d78cf62f77389ff68d92256bce3 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 26 Feb 2020 07:02:03 +0100 Subject: [PATCH 01/31] Added popover --- front/core/components/calendar/index.html | 4 +- front/core/components/calendar/index.js | 6 ++- front/core/components/popover/index.js | 17 +++++++- front/core/mocks/popover.js | 25 +++++++++++ modules/zone/front/calendar/index.html | 2 +- modules/zone/front/calendar/index.js | 3 +- modules/zone/front/card/index.spec.js | 2 +- modules/zone/front/create/index.spec.js | 2 +- modules/zone/front/delivery-days/index.html | 11 ++++- modules/zone/front/delivery-days/index.js | 21 ++++++++++ .../zone/front/delivery-days/index.spec.js | 41 +++++++++++++++++++ modules/zone/front/delivery-days/style.scss | 24 +++++++++++ modules/zone/front/index/index.html | 2 +- modules/zone/front/index/index.spec.js | 2 +- 14 files changed, 150 insertions(+), 12 deletions(-) create mode 100644 front/core/mocks/popover.js create mode 100644 modules/zone/front/delivery-days/index.spec.js diff --git a/front/core/components/calendar/index.html b/front/core/components/calendar/index.html index 0efff2492..eb6d196ba 100644 --- a/front/core/components/calendar/index.html +++ b/front/core/components/calendar/index.html @@ -23,7 +23,7 @@
+ ng-click="$ctrl.selectWeekDay($event, day.index)"> {{::day.localeChar}}
@@ -38,7 +38,7 @@ on-last="$ctrl.repeatLast()">
+ ng-click="$ctrl.select($event, day)"> {{::day | date: 'd'}}
diff --git a/front/core/components/calendar/index.js b/front/core/components/calendar/index.js index 4afec0a9a..96bc435db 100644 --- a/front/core/components/calendar/index.js +++ b/front/core/components/calendar/index.js @@ -127,10 +127,11 @@ export default class Calendar extends FormInput { /* * Day selection event */ - select(day) { + select($event, day) { if (!this.editable) return; this.change(day); this.emit('selection', { + $event: $event, $days: [day], $type: 'day' }); @@ -140,7 +141,7 @@ export default class Calendar extends FormInput { /* * WeekDay selection event */ - selectWeekDay(weekday) { + selectWeekDay($event, weekday) { if (!this.editable) return; let days = []; for (let day of this.days) { @@ -149,6 +150,7 @@ export default class Calendar extends FormInput { } this.field = days[0]; this.emit('selection', { + $event: $event, $days: days, $type: 'weekday', $weekday: weekday diff --git a/front/core/components/popover/index.js b/front/core/components/popover/index.js index 413f4d85f..e209034a3 100644 --- a/front/core/components/popover/index.js +++ b/front/core/components/popover/index.js @@ -37,6 +37,21 @@ export default class Popover extends Popup { super.hide(); } + get parent() { + return this.__parent; + } + + set parent(value) { + this.__parent = value; + + if (!value) return; + + const parentRect = value.getBoundingClientRect(); + this.parentRect = {}; + for (let prop in parentRect) + this.parentRect[prop] = parentRect[prop]; + } + /** * Repositions the popover to a correct location relative to the parent. */ @@ -55,7 +70,7 @@ export default class Popover extends Popup { arrowStyle.top = ''; arrowStyle.bottom = ''; - let parentRect = this.parent.getBoundingClientRect(); + let parentRect = this.parentRect; let popoverRect = this.windowEl.getBoundingClientRect(); let arrowRect = arrow.getBoundingClientRect(); let clamp = (value, min, max) => Math.min(Math.max(value, min), max); diff --git a/front/core/mocks/popover.js b/front/core/mocks/popover.js new file mode 100644 index 000000000..037e0963a --- /dev/null +++ b/front/core/mocks/popover.js @@ -0,0 +1,25 @@ +const popover = { + show: () => { + return { + then: callback => { + callback(); + } + }; + }, + hide: () => { + return { + then: callback => { + callback(); + } + }; + }, + relocate: () => { + return { + then: callback => { + callback(); + } + }; + } +}; + +module.exports = popover; diff --git a/modules/zone/front/calendar/index.html b/modules/zone/front/calendar/index.html index b1277cbe5..cfcebf359 100644 --- a/modules/zone/front/calendar/index.html +++ b/modules/zone/front/calendar/index.html @@ -25,7 +25,7 @@ hide-contiguous="true" has-events="$ctrl.hasEvents($day)" get-class="$ctrl.getClass($day)" - on-selection="$ctrl.onSelection($days, $type, $weekday)" + on-selection="$ctrl.onSelection($event, $days, $type, $weekday)" class="vn-pa-md" style="min-width: 250px; flex: 1;"> diff --git a/modules/zone/front/calendar/index.js b/modules/zone/front/calendar/index.js index 88f16d334..702a0a0d9 100644 --- a/modules/zone/front/calendar/index.js +++ b/modules/zone/front/calendar/index.js @@ -130,7 +130,7 @@ class Controller extends Component { } } - onSelection($days, $type, $weekday) { + onSelection($event, $days, $type, $weekday) { let $events = []; let $exclusions = []; @@ -141,6 +141,7 @@ class Controller extends Component { } this.emit('selection', { + $event, $days, $type, $weekday, diff --git a/modules/zone/front/card/index.spec.js b/modules/zone/front/card/index.spec.js index 48970ce6b..9d0911de2 100644 --- a/modules/zone/front/card/index.spec.js +++ b/modules/zone/front/card/index.spec.js @@ -1,6 +1,6 @@ import './index.js'; -describe('Agency Component vnZoneCard', () => { +describe('Zone Component vnZoneCard', () => { let controller; let $httpBackend; let data = {id: 1, name: 'fooName'}; diff --git a/modules/zone/front/create/index.spec.js b/modules/zone/front/create/index.spec.js index 5041e5095..b97c9c3cf 100644 --- a/modules/zone/front/create/index.spec.js +++ b/modules/zone/front/create/index.spec.js @@ -1,7 +1,7 @@ import './index'; import watcher from 'core/mocks/watcher'; -describe('Agency Component vnZoneCreate', () => { +describe('Zone Component vnZoneCreate', () => { let $scope; let $state; let controller; diff --git a/modules/zone/front/delivery-days/index.html b/modules/zone/front/delivery-days/index.html index 2b8a0e423..589208caf 100644 --- a/modules/zone/front/delivery-days/index.html +++ b/modules/zone/front/delivery-days/index.html @@ -1,6 +1,7 @@
+ data="data" + on-selection="$ctrl.onSelection($event, $events)">
@@ -31,3 +32,11 @@ + + + +
+
Zones
+ +
+
\ No newline at end of file diff --git a/modules/zone/front/delivery-days/index.js b/modules/zone/front/delivery-days/index.js index 0d7baeb60..006252a69 100644 --- a/modules/zone/front/delivery-days/index.js +++ b/modules/zone/front/delivery-days/index.js @@ -17,6 +17,27 @@ class Controller extends Section { this.vnApp.showMessage(this.$t('No service for the specified zone')); }); } + + onSelection($event, $events) { + if (!$events.length) return; + + const zones = []; + for (let event of $events) + zones.push(event.zoneFk); + + this.$.zoneEvents.show($event.target); + const zoneIndex = this.$.zoneIndex; + const zoneModel = zoneIndex.$scope.model; + zoneModel.applyFilter({ + include: { + relation: 'agencyMode', + scope: {fields: ['name']} + }, + where: { + id: {inq: zones} + } + }); + } } ngModule.component('vnZoneDeliveryDays', { diff --git a/modules/zone/front/delivery-days/index.spec.js b/modules/zone/front/delivery-days/index.spec.js new file mode 100644 index 000000000..e6019b025 --- /dev/null +++ b/modules/zone/front/delivery-days/index.spec.js @@ -0,0 +1,41 @@ +import './index.js'; +import popover from 'core/mocks/popover'; +import crudModel from 'core/mocks/crud-model'; + +fdescribe('Zone Component vnZoneDeliveryDays', () => { + let $componentController; + let controller; + let $element; + + beforeEach(ngModule('zone')); + + beforeEach(angular.mock.inject(_$componentController_ => { + $componentController = _$componentController_; + $element = angular.element(' { + it('should return', () => { + jest.spyOn(controller.$.zoneEvents, 'show'); + + const $event = new Event('click'); + const target = angular.element('
My target
'); // crear con DOM? + target.dispatchEvent($event); + const $events = [ + {zoneFk: 1}, + {zoneFk: 2}, + {zoneFk: 8} + ]; + controller.onSelection($event, $events); + + expect(controller.$.zoneEvents.show).toHaveBeenCalledWith(); + }); + }); +}); diff --git a/modules/zone/front/delivery-days/style.scss b/modules/zone/front/delivery-days/style.scss index 79f95a3dc..531b51795 100644 --- a/modules/zone/front/delivery-days/style.scss +++ b/modules/zone/front/delivery-days/style.scss @@ -1,3 +1,4 @@ +@import "variables"; vn-zone-delivery-days { vn-zone-calendar { @@ -13,4 +14,27 @@ vn-zone-delivery-days { display: flex; flex-direction: column; } +} + +.zoneEvents { + width: 700px; + max-height: 450px; + + vn-float-button { + display: none + } + + vn-data-viewer { + margin-bottom: 0; + vn-pagination { + padding: 0 + } + } + + & > .header { + background-color: $color-main; + color: white; + font-weight: bold; + text-align: center + } } \ No newline at end of file diff --git a/modules/zone/front/index/index.html b/modules/zone/front/index/index.html index cb820b66a..b05789615 100644 --- a/modules/zone/front/index/index.html +++ b/modules/zone/front/index/index.html @@ -4,7 +4,7 @@ filter="::$ctrl.filter" limit="20" data="zones" - auto-load="true"> + auto-load="false"> { +describe('Zone Component vnZoneIndex', () => { let $componentController; let controller; From 442c3ba87c22f369bd9028193dc46a4e5fe8168e Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 26 Feb 2020 11:05:29 +0100 Subject: [PATCH 02/31] unit tests --- front/core/components/calendar/index.spec.js | 8 ++- .../zone/front/delivery-days/index.spec.js | 61 +++++++++++++++++-- 2 files changed, 63 insertions(+), 6 deletions(-) diff --git a/front/core/components/calendar/index.spec.js b/front/core/components/calendar/index.spec.js index 6945c35ea..74abb921c 100644 --- a/front/core/components/calendar/index.spec.js +++ b/front/core/components/calendar/index.spec.js @@ -50,9 +50,15 @@ describe('Component vnCalendar', () => { const day = new Date(); day.setHours(0, 0, 0, 0); - controller.select(day); + + const clickEvent = new Event('click'); + const target = document.createElement('div'); + target.dispatchEvent(clickEvent); + + controller.select(clickEvent, day); let res = { + $event: clickEvent, $days: [day], $type: 'day' }; diff --git a/modules/zone/front/delivery-days/index.spec.js b/modules/zone/front/delivery-days/index.spec.js index e6019b025..17bf9caff 100644 --- a/modules/zone/front/delivery-days/index.spec.js +++ b/modules/zone/front/delivery-days/index.spec.js @@ -2,15 +2,17 @@ import './index.js'; import popover from 'core/mocks/popover'; import crudModel from 'core/mocks/crud-model'; -fdescribe('Zone Component vnZoneDeliveryDays', () => { +describe('Zone Component vnZoneDeliveryDays', () => { let $componentController; + let $httpBackend; let controller; let $element; beforeEach(ngModule('zone')); - beforeEach(angular.mock.inject(_$componentController_ => { + beforeEach(angular.mock.inject((_$componentController_, _$httpBackend_) => { $componentController = _$componentController_; + $httpBackend = _$httpBackend_; $element = angular.element(' { }; })); + describe('onSubmit()', () => { + it('should make an HTTP GET query and then call the showMessage() method', () => { + jest.spyOn(controller.vnApp, 'showMessage'); + + const expectedData = {events: []}; + $httpBackend.when('GET', 'Zones/getEvents').respond({events: []}); + controller.onSubmit(); + $httpBackend.flush(); + + expect(controller.$.data).toBeDefined(); + expect(controller.$.data).toEqual(expectedData); + expect(controller.vnApp.showMessage).toHaveBeenCalledWith('No service for the specified zone'); + }); + + it('should make an HTTP GET query and then set the data property', () => { + const expectedData = {events: [{zoneFk: 1}]}; + $httpBackend.when('GET', 'Zones/getEvents').respond({events: [{zoneFk: 1}]}); + controller.onSubmit(); + $httpBackend.flush(); + + expect(controller.$.data).toBeDefined(); + expect(controller.$.data).toEqual(expectedData); + }); + }); + describe('onSelection()', () => { - it('should return', () => { + it('should not call the show popover method', () => { jest.spyOn(controller.$.zoneEvents, 'show'); const $event = new Event('click'); - const target = angular.element('
My target
'); // crear con DOM? + const target = document.createElement('div'); + target.dispatchEvent($event); + const $events = []; + controller.onSelection($event, $events); + + expect(controller.$.zoneEvents.show).not.toHaveBeenCalled(); + }); + + it('should return', () => { + const zoneModel = controller.$.zoneIndex.$scope.model; + jest.spyOn(controller.$.zoneEvents, 'show'); + jest.spyOn(zoneModel, 'applyFilter'); + + const $event = new Event('click'); + const target = document.createElement('div'); target.dispatchEvent($event); const $events = [ {zoneFk: 1}, @@ -34,8 +75,18 @@ fdescribe('Zone Component vnZoneDeliveryDays', () => { {zoneFk: 8} ]; controller.onSelection($event, $events); + const expectedFilter = { + include: { + relation: 'agencyMode', + scope: {fields: ['name']} + }, + where: { + id: {inq: [1, 2, 8]} + } + }; - expect(controller.$.zoneEvents.show).toHaveBeenCalledWith(); + expect(controller.$.zoneEvents.show).toHaveBeenCalledWith(target); + expect(zoneModel.applyFilter).toHaveBeenCalledWith(expectedFilter); }); }); }); From 54bb2c4a0ac1be4b0e47d64c28a8b55a64b0f22e Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 26 Feb 2020 11:37:58 +0100 Subject: [PATCH 03/31] Updated with bug-task description --- front/core/components/popover/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/front/core/components/popover/index.js b/front/core/components/popover/index.js index e209034a3..7c54ce494 100644 --- a/front/core/components/popover/index.js +++ b/front/core/components/popover/index.js @@ -41,6 +41,7 @@ export default class Popover extends Popup { return this.__parent; } + // Bug #2147 Popover loses parent location set parent(value) { this.__parent = value; From e09325b3fa2a71da245a5f3fa9290d819d589c3b Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 26 Feb 2020 11:43:41 +0100 Subject: [PATCH 04/31] Changed test description --- modules/zone/front/delivery-days/index.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/zone/front/delivery-days/index.spec.js b/modules/zone/front/delivery-days/index.spec.js index 17bf9caff..273d5822e 100644 --- a/modules/zone/front/delivery-days/index.spec.js +++ b/modules/zone/front/delivery-days/index.spec.js @@ -61,7 +61,7 @@ describe('Zone Component vnZoneDeliveryDays', () => { expect(controller.$.zoneEvents.show).not.toHaveBeenCalled(); }); - it('should return', () => { + it('should call the show() method and then call the applyFilter() method with the spected ids', () => { const zoneModel = controller.$.zoneIndex.$scope.model; jest.spyOn(controller.$.zoneEvents, 'show'); jest.spyOn(zoneModel, 'applyFilter'); From ce84d26fae242c8fa50def18ef7efaf6d834dcd7 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 26 Feb 2020 12:24:48 +0100 Subject: [PATCH 05/31] Some changes --- modules/zone/front/delivery-days/index.spec.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/modules/zone/front/delivery-days/index.spec.js b/modules/zone/front/delivery-days/index.spec.js index 273d5822e..0524f3590 100644 --- a/modules/zone/front/delivery-days/index.spec.js +++ b/modules/zone/front/delivery-days/index.spec.js @@ -49,32 +49,32 @@ describe('Zone Component vnZoneDeliveryDays', () => { }); describe('onSelection()', () => { - it('should not call the show popover method', () => { + it('should not call the show popover method if events array is empty', () => { jest.spyOn(controller.$.zoneEvents, 'show'); - const $event = new Event('click'); + const event = new Event('click'); const target = document.createElement('div'); - target.dispatchEvent($event); - const $events = []; - controller.onSelection($event, $events); + target.dispatchEvent(event); + const events = []; + controller.onSelection(event, events); expect(controller.$.zoneEvents.show).not.toHaveBeenCalled(); }); - it('should call the show() method and then call the applyFilter() method with the spected ids', () => { + it('should call the show() method and then call the applyFilter() method with the expected ids', () => { const zoneModel = controller.$.zoneIndex.$scope.model; jest.spyOn(controller.$.zoneEvents, 'show'); jest.spyOn(zoneModel, 'applyFilter'); - const $event = new Event('click'); + const event = new Event('click'); const target = document.createElement('div'); target.dispatchEvent($event); - const $events = [ + const events = [ {zoneFk: 1}, {zoneFk: 2}, {zoneFk: 8} ]; - controller.onSelection($event, $events); + controller.onSelection(event, events); const expectedFilter = { include: { relation: 'agencyMode', From d401fa8d13a6dc183adc0c06431f03def9608f6f Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 26 Feb 2020 13:06:35 +0100 Subject: [PATCH 06/31] Changed variable name --- modules/zone/front/delivery-days/index.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/zone/front/delivery-days/index.spec.js b/modules/zone/front/delivery-days/index.spec.js index 0524f3590..35171ab94 100644 --- a/modules/zone/front/delivery-days/index.spec.js +++ b/modules/zone/front/delivery-days/index.spec.js @@ -68,7 +68,7 @@ describe('Zone Component vnZoneDeliveryDays', () => { const event = new Event('click'); const target = document.createElement('div'); - target.dispatchEvent($event); + target.dispatchEvent(event); const events = [ {zoneFk: 1}, {zoneFk: 2}, From e15ef3386e97e9ebfb06cc95e631bd2b140556b3 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 26 Feb 2020 13:18:29 +0100 Subject: [PATCH 07/31] Translation changes --- modules/ticket/front/basic-data/step-two/index.html | 4 ++-- modules/ticket/front/basic-data/step-two/locale/es.yml | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/ticket/front/basic-data/step-two/index.html b/modules/ticket/front/basic-data/step-two/index.html index 0154b3caa..474e39342 100644 --- a/modules/ticket/front/basic-data/step-two/index.html +++ b/modules/ticket/front/basic-data/step-two/index.html @@ -26,8 +26,8 @@ Description Quantity Price (PPU) - New price (PPU) - Price difference + New (PPU) + Difference diff --git a/modules/ticket/front/basic-data/step-two/locale/es.yml b/modules/ticket/front/basic-data/step-two/locale/es.yml index 2cb66b38b..47fc87b0c 100644 --- a/modules/ticket/front/basic-data/step-two/locale/es.yml +++ b/modules/ticket/front/basic-data/step-two/locale/es.yml @@ -1,3 +1,4 @@ Price (PPU): Precio (Ud.) -New price (PPU): Nuevo precio (Ud.) -Price difference: Diferencia de precio \ No newline at end of file +New (PPU): Nuevo (Ud.) +Difference: Diferencia +Charge difference to: Cargar diferencia a \ No newline at end of file From 794b20fc83350119615e79b6176f67a0f39fa6c8 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Wed, 26 Feb 2020 13:22:52 +0100 Subject: [PATCH 08/31] #2131 jest.spyOn --- .../core/components/button-menu/index.spec.js | 4 +- front/core/components/calendar/index.spec.js | 6 +-- front/core/components/chip/index.spec.js | 2 +- .../core/components/crud-model/index.spec.js | 2 +- front/core/components/dialog/index.spec.js | 10 ++-- .../multi-check/multi-check.spec.js | 2 +- front/core/components/popover/index.spec.js | 10 ++-- .../components/searchbar/searchbar.spec.js | 2 +- front/core/components/spinner/spinner.spec.js | 4 +- .../step-control/step-control.spec.js | 2 +- front/core/components/th/index.spec.js | 14 +++--- front/core/components/treeview/index.spec.js | 40 +++++++-------- front/core/components/watcher/watcher.spec.js | 26 +++++----- front/core/directives/specs/dialog.spec.js | 2 +- .../components/left-menu/left-menu.spec.js | 2 +- modules/claim/front/action/index.spec.js | 50 +++++++++---------- modules/claim/front/basic-data/index.spec.js | 2 +- modules/claim/front/descriptor/index.spec.js | 8 +-- modules/claim/front/detail/index.spec.js | 24 ++++----- modules/claim/front/development/index.spec.js | 2 +- modules/claim/front/photos/index.spec.js | 8 +-- modules/claim/front/summary/index.spec.js | 2 +- .../client/front/address/create/index.spec.js | 4 +- .../client/front/address/edit/index.spec.js | 8 +-- .../client/front/address/index/index.spec.js | 2 +- .../client/front/balance/index/index.spec.js | 14 +++--- .../client/front/billing-data/index.spec.js | 2 +- modules/client/front/create/index.spec.js | 2 +- .../credit-insurance/index/index.spec.js | 4 +- .../client/front/credit/create/index.spec.js | 10 ++-- .../front/descriptor-popover/index.spec.js | 8 +-- modules/client/front/dms/create/index.spec.js | 4 +- modules/client/front/dms/edit/index.spec.js | 4 +- modules/client/front/dms/index/index.spec.js | 4 +- .../client/front/fiscal-data/index.spec.js | 12 ++--- .../client/front/greuge/create/index.spec.js | 2 +- modules/client/front/index/index.spec.js | 2 +- modules/client/front/postcode/index.spec.js | 2 +- .../front/recovery/create/index.spec.js | 2 +- .../client/front/sample/create/index.spec.js | 12 ++--- modules/client/front/sms/index.spec.js | 6 +-- modules/client/front/summary/index.spec.js | 4 +- modules/client/front/web-access/index.spec.js | 4 +- .../client/front/web-payment/index.spec.js | 2 +- modules/entry/front/descriptor/index.spec.js | 2 +- modules/entry/front/summary/index.spec.js | 4 +- modules/item/front/create/index.spec.js | 2 +- .../front/descriptor-popover/index.spec.js | 8 +-- modules/item/front/diary/index.spec.js | 6 +-- modules/item/front/index/index.spec.js | 6 +-- modules/item/front/request/index.spec.js | 12 ++--- modules/item/front/summary/index.spec.js | 2 +- modules/item/front/tags/index.spec.js | 4 +- modules/item/front/tax/index.spec.js | 4 +- modules/order/front/create/card.spec.js | 6 +-- modules/order/front/create/index.spec.js | 4 +- modules/order/front/descriptor/index.spec.js | 8 +-- modules/order/front/summary/index.spec.js | 2 +- modules/order/front/volume/index.spec.js | 4 +- .../front/descriptor-popover/index.spec.js | 8 +-- modules/route/front/tickets/index.spec.js | 34 ++++++------- .../front/basic-data/step-one/index.spec.js | 22 ++++---- .../front/descriptor-popover/index.spec.js | 8 +-- modules/ticket/front/descriptor/index.spec.js | 32 ++++++------ modules/ticket/front/dms/create/index.spec.js | 4 +- modules/ticket/front/dms/edit/index.spec.js | 4 +- modules/ticket/front/dms/index/index.spec.js | 4 +- modules/ticket/front/expedition/index.spec.js | 2 +- modules/ticket/front/index/index.spec.js | 2 +- modules/ticket/front/sale/index.js | 2 +- .../front/sale/specs/editDiscount.spec.js | 6 +-- modules/ticket/front/sale/specs/index.spec.js | 18 +++---- modules/ticket/front/sms/index.spec.js | 6 +-- modules/ticket/front/summary/index.spec.js | 2 +- .../ticket/front/tracking/edit/index.spec.js | 8 +-- modules/ticket/front/volume/index.spec.js | 4 +- modules/travel/front/basic-data/index.spec.js | 4 +- modules/travel/front/create/index.spec.js | 2 +- .../front/descriptor-popover/index.spec.js | 6 +-- modules/travel/front/summary/index.spec.js | 6 +-- .../front/thermograph/create/index.spec.js | 4 +- .../front/descriptor-popover/index.spec.js | 6 +-- modules/worker/front/dms/create/index.spec.js | 4 +- modules/worker/front/dms/edit/index.spec.js | 4 +- modules/worker/front/dms/index/index.spec.js | 4 +- .../worker/front/time-control/index.spec.js | 8 +-- modules/zone/front/create/index.spec.js | 2 +- modules/zone/front/summary/index.spec.js | 4 +- 88 files changed, 313 insertions(+), 319 deletions(-) diff --git a/front/core/components/button-menu/index.spec.js b/front/core/components/button-menu/index.spec.js index 87f677001..4e5046419 100644 --- a/front/core/components/button-menu/index.spec.js +++ b/front/core/components/button-menu/index.spec.js @@ -16,7 +16,7 @@ describe('Component vnButtonMenu', () => { describe('onButtonClick(event)', () => { it(`should emit the open event`, () => { - spyOn(controller, 'emit'); + jest.spyOn(controller, 'emit'); let event = new MouseEvent('click', { view: controller.element.window, @@ -31,7 +31,7 @@ describe('Component vnButtonMenu', () => { describe('onDropDownSelect(value)', () => { it(`should set field to the given value and emit the change event`, () => { - spyOn(controller, 'emit'); + jest.spyOn(controller, 'emit'); controller.onDropDownSelect({name: 'Item name'}); expect(controller.field).toBe('Item name'); diff --git a/front/core/components/calendar/index.spec.js b/front/core/components/calendar/index.spec.js index 6945c35ea..42ee41958 100644 --- a/front/core/components/calendar/index.spec.js +++ b/front/core/components/calendar/index.spec.js @@ -20,7 +20,7 @@ describe('Component vnCalendar', () => { describe('moveNext()', () => { it(`should shift to the next month, then emit a 'move' event`, () => { - spyOn(controller, 'emit'); + jest.spyOn(controller, 'emit'); let nextMonth = new Date(date.getTime()); nextMonth.setMonth(nextMonth.getMonth() + 1); @@ -33,7 +33,7 @@ describe('Component vnCalendar', () => { describe('movePrevious()', () => { it(`should shift to the previous month, then emit a 'move' event`, () => { - spyOn(controller, 'emit'); + jest.spyOn(controller, 'emit'); let previousMonth = new Date(date.getTime()); previousMonth.setMonth(previousMonth.getMonth() - 1); @@ -46,7 +46,7 @@ describe('Component vnCalendar', () => { describe('select()', () => { it(`should return the selected element, then emit a 'selection' event`, () => { - spyOn(controller, 'emit'); + jest.spyOn(controller, 'emit'); const day = new Date(); day.setHours(0, 0, 0, 0); diff --git a/front/core/components/chip/index.spec.js b/front/core/components/chip/index.spec.js index 8555f2c11..60129fd69 100644 --- a/front/core/components/chip/index.spec.js +++ b/front/core/components/chip/index.spec.js @@ -17,7 +17,7 @@ describe('Component vnChip', () => { describe('onRemove()', () => { it(`should emit remove event`, () => { controller.emit = () => {}; - spyOn(controller, 'emit'); + jest.spyOn(controller, 'emit'); controller.onRemove(); expect(controller.emit).toHaveBeenCalledWith('remove'); diff --git a/front/core/components/crud-model/index.spec.js b/front/core/components/crud-model/index.spec.js index e0daa2558..73841e98b 100644 --- a/front/core/components/crud-model/index.spec.js +++ b/front/core/components/crud-model/index.spec.js @@ -26,7 +26,7 @@ describe('Component vnCrudModel', () => { describe('save()', () => { it(`should make an HTTP post query and then update the original rows with the returned values`, () => { - spyOn(controller, 'applyChanges'); + jest.spyOn(controller, 'applyChanges'); controller.insert({value: 'My new item 1'}); controller.insert({value: 'My new item 2'}); diff --git a/front/core/components/dialog/index.spec.js b/front/core/components/dialog/index.spec.js index 8c41bc060..e8c8f6320 100644 --- a/front/core/components/dialog/index.spec.js +++ b/front/core/components/dialog/index.spec.js @@ -30,7 +30,7 @@ describe('Component vnDialog', () => { it(`should not hide the dialog when false is returned from response handler`, () => { controller.show(() => false); - spyOn(controller, 'hide'); + jest.spyOn(controller, 'hide'); controller.respond('answer'); expect(controller.hide).not.toHaveBeenCalled(); @@ -51,7 +51,7 @@ describe('Component vnDialog', () => { describe('respond()', () => { it(`should do nothing if dialog is already hidden`, () => { controller.onResponse = () => {}; - spyOn(controller, 'onResponse'); + jest.spyOn(controller, 'onResponse'); controller.respond(); expect(controller.onResponse).not.toHaveBeenCalledWith(); @@ -59,7 +59,7 @@ describe('Component vnDialog', () => { it(`should call onResponse() if it's defined`, () => { controller.onResponse = () => {}; - spyOn(controller, 'onResponse'); + jest.spyOn(controller, 'onResponse'); controller.show(); controller.respond(); @@ -69,7 +69,7 @@ describe('Component vnDialog', () => { it(`should call onResponse() with the response`, () => { controller.onResponse = () => {}; - spyOn(controller, 'onResponse'); + jest.spyOn(controller, 'onResponse'); controller.show(); controller.respond('response'); @@ -79,7 +79,7 @@ describe('Component vnDialog', () => { it(`should call onAccept() when accept response is given`, () => { controller.onAccept = () => {}; - spyOn(controller, 'onAccept'); + jest.spyOn(controller, 'onAccept'); controller.show(); controller.respond('accept'); diff --git a/front/core/components/multi-check/multi-check.spec.js b/front/core/components/multi-check/multi-check.spec.js index c85b160c1..d10cc27cf 100644 --- a/front/core/components/multi-check/multi-check.spec.js +++ b/front/core/components/multi-check/multi-check.spec.js @@ -20,7 +20,7 @@ describe('Component vnMultiCheck', () => { describe('checked() setter', () => { it(`should set controller _checked property with the argument received then call toggle()`, () => { - spyOn(controller, 'toggle'); + jest.spyOn(controller, 'toggle'); controller.checked = crudModel; expect(controller._checked).toEqual(crudModel); diff --git a/front/core/components/popover/index.spec.js b/front/core/components/popover/index.spec.js index 54901b222..dc6e3b23f 100644 --- a/front/core/components/popover/index.spec.js +++ b/front/core/components/popover/index.spec.js @@ -22,7 +22,7 @@ describe('Component vnPopover', () => { describe('show()', () => { it(`should enable the shown property and emit the open event`, () => { - spyOn(controller, 'emit'); + jest.spyOn(controller, 'emit'); controller.show(); expect(controller.shown).toBeTruthy(); @@ -31,13 +31,13 @@ describe('Component vnPopover', () => { it(`should do nothing if it's already shown`, () => { controller.shown = true; - spyOn(controller, 'emit'); + jest.spyOn(controller, 'emit'); controller.show(); expect(controller.emit).not.toHaveBeenCalledWith('open'); }); - //#1615 migrar karma a jest (this doesn't work anymore, needs fixing) + // #1615 migrar karma a jest (this doesn't work anymore, needs fixing) xit(`should check that popover is visible into the screen`, () => { $parent.css({ backgroundColor: 'red', @@ -65,7 +65,7 @@ describe('Component vnPopover', () => { describe('hide()', () => { it(`should disable the shown property and emit the close event`, inject($timeout => { controller.show(); - spyOn(controller, 'emit'); + jest.spyOn(controller, 'emit'); controller.hide(); $timeout.flush(); @@ -75,7 +75,7 @@ describe('Component vnPopover', () => { it(`should do nothing if it's already hidden`, () => { controller.shown = false; - spyOn(controller, 'emit'); + jest.spyOn(controller, 'emit'); controller.hide(); expect(controller.emit).not.toHaveBeenCalledWith('close'); diff --git a/front/core/components/searchbar/searchbar.spec.js b/front/core/components/searchbar/searchbar.spec.js index f923f12b5..7318e93b6 100644 --- a/front/core/components/searchbar/searchbar.spec.js +++ b/front/core/components/searchbar/searchbar.spec.js @@ -139,7 +139,7 @@ describe('Component vnSearchbar', () => { describe('doSearch()', () => { it(`should go to the search state and pass the filter as query param`, () => { - spyOn($state, 'go'); + jest.spyOn($state, 'go'); controller.searchState = 'search.state'; controller.doSearch(filter); diff --git a/front/core/components/spinner/spinner.spec.js b/front/core/components/spinner/spinner.spec.js index dbcdb0acd..ef3c99623 100644 --- a/front/core/components/spinner/spinner.spec.js +++ b/front/core/components/spinner/spinner.spec.js @@ -17,14 +17,14 @@ describe('Component vnSpinner', () => { describe('enable()', () => { it(`should call start() when enable is set to true`, () => { - spyOn(controller, 'start'); + jest.spyOn(controller, 'start'); controller.enable = true; expect(controller.start).toHaveBeenCalledWith(); }); it(`should call stop() when enable is set to false`, () => { - spyOn(controller, 'stop'); + jest.spyOn(controller, 'stop'); controller.enable = false; expect(controller.stop).toHaveBeenCalledWith(); diff --git a/front/core/components/step-control/step-control.spec.js b/front/core/components/step-control/step-control.spec.js index 944457cfe..11a157470 100644 --- a/front/core/components/step-control/step-control.spec.js +++ b/front/core/components/step-control/step-control.spec.js @@ -8,7 +8,7 @@ describe('Component vnStepControl', () => { beforeEach(angular.mock.inject(($componentController, _$state_) => { $state = _$state_; - spyOn($state, 'go'); + jest.spyOn($state, 'go'); controller = $componentController('vnStepControl', {$state: $state}); })); diff --git a/front/core/components/th/index.spec.js b/front/core/components/th/index.spec.js index dc9e43672..ce6dbeec5 100644 --- a/front/core/components/th/index.spec.js +++ b/front/core/components/th/index.spec.js @@ -20,7 +20,7 @@ describe('Component vnTh', () => { describe('onInit()', () => { it(`should define controllers order as per defaultOrder then call setOrder()`, () => { controller.defaultOrder = 'DESC'; - spyOn(controller.table, 'setOrder'); + jest.spyOn(controller.table, 'setOrder'); controller.$onInit(); expect(controller.order).toEqual('DESC'); @@ -44,7 +44,7 @@ describe('Component vnTh', () => { }); it(`should call the setOrder() function after changing a value`, () => { - spyOn(controller.table, 'setOrder'); + jest.spyOn(controller.table, 'setOrder'); controller.order = 'Change me!'; expect(controller.table.setOrder).toHaveBeenCalledWith('MyField', 'Change me!'); @@ -54,7 +54,7 @@ describe('Component vnTh', () => { describe('onToggleOrder()', () => { it(`should not call updateArrow() method if field property isn't defined`, () => { controller.column.setAttribute('field', ''); - spyOn(controller, 'updateArrow'); + jest.spyOn(controller, 'updateArrow'); controller.onToggleOrder(); @@ -64,8 +64,8 @@ describe('Component vnTh', () => { it(`should call toggleOrder() method if field property and table field property equals and then call updateArrow()`, () => { controller.table.field = 'MyField'; - spyOn(controller, 'toggleOrder'); - spyOn(controller, 'updateArrow'); + jest.spyOn(controller, 'toggleOrder'); + jest.spyOn(controller, 'updateArrow'); controller.onToggleOrder(); @@ -76,8 +76,8 @@ describe('Component vnTh', () => { it(`should call setOrder() method if field property and table field property doesn't equals and then call updateArrow()`, () => { controller.table.field = 'MyField2'; - spyOn(controller.table, 'setOrder'); - spyOn(controller, 'updateArrow'); + jest.spyOn(controller.table, 'setOrder'); + jest.spyOn(controller, 'updateArrow'); controller.onToggleOrder(); diff --git a/front/core/components/treeview/index.spec.js b/front/core/components/treeview/index.spec.js index e03345c33..9277f3ee4 100644 --- a/front/core/components/treeview/index.spec.js +++ b/front/core/components/treeview/index.spec.js @@ -37,7 +37,7 @@ describe('Component vnTreeview', () => { xdescribe('undrop()', () => { it(`should reset all drop events and properties`, () => { controller.dropping = angular.element(``); - spyOn(controller.dropping.classList, 'remove'); + jest.spyOn(controller.dropping.classList, 'remove'); controller.undrop(); @@ -69,9 +69,7 @@ describe('Component vnTreeview', () => { describe('fetch()', () => { it(`should call the fetchFunc() method`, () => { - spyOn(controller, 'fetchFunc').and.returnValue( - new Promise(resolve => resolve([{name: 'My item'}])) - ); + jest.spyOn(controller, 'fetchFunc'); controller.fetch().then(() => { expect(controller.data).toBeDefined(); }); @@ -82,7 +80,7 @@ describe('Component vnTreeview', () => { describe('setParent()', () => { it(`should set the parent property recursively to each element of an item list`, () => { - spyOn(controller, 'setParent').and.callThrough(); + jest.spyOn(controller, 'setParent'); const items = [{name: 'Item1'}, {name: 'Item2', childs: [ {name: 'Item3'} ]}]; @@ -97,8 +95,8 @@ describe('Component vnTreeview', () => { describe('onToggle()', () => { it(`should call the fold() or unfold() methods`, () => { - spyOn(controller, 'fold'); - spyOn(controller, 'unfold'); + jest.spyOn(controller, 'fold'); + jest.spyOn(controller, 'unfold'); let event = new MouseEvent('click', { bubbles: true, @@ -130,11 +128,9 @@ describe('Component vnTreeview', () => { describe('unfold()', () => { it(`should unfold a parent item`, () => { const expectedResponse = [{name: 'Item 1'}, {name: 'Item 2'}]; - spyOn(controller, 'fetchFunc').and.returnValue( - new Promise(resolve => resolve(expectedResponse)) - ); - spyOn(controller, 'setParent'); - spyOn(controller, 'sortFunc'); + jest.spyOn(controller, 'fetchFunc'); + jest.spyOn(controller, 'setParent'); + jest.spyOn(controller, 'sortFunc'); const parent = {name: 'My item', sons: 1}; const child = {name: 'Item 1'}; child.parent = parent; @@ -157,7 +153,7 @@ describe('Component vnTreeview', () => { view: window }); - spyOn(controller, 'removeFunc'); + jest.spyOn(controller, 'removeFunc'); const item = {name: 'My item'}; controller.onRemove(event, item); @@ -187,7 +183,7 @@ describe('Component vnTreeview', () => { view: window }); - spyOn(controller, 'createFunc'); + jest.spyOn(controller, 'createFunc'); const parent = {name: 'My item'}; controller.onCreate(event, parent); @@ -197,8 +193,8 @@ describe('Component vnTreeview', () => { describe('create()', () => { it(`should unfold an inactive parent and then create a child`, () => { - spyOn(controller, 'unfold'); - spyOn(controller, 'sortFunc'); + jest.spyOn(controller, 'unfold'); + jest.spyOn(controller, 'sortFunc'); const parent = {name: 'My item', sons: 2, childs: [ {name: 'Item 1'}, {name: 'Item 2'} @@ -216,8 +212,8 @@ describe('Component vnTreeview', () => { }); it(`should create a child on an active parent`, () => { - spyOn(controller, 'unfold'); - spyOn(controller, 'sortFunc'); + jest.spyOn(controller, 'unfold'); + jest.spyOn(controller, 'sortFunc'); const parent = {name: 'My item', sons: 2, childs: [ {name: 'Item 1'}, {name: 'Item 2'} @@ -236,9 +232,7 @@ describe('Component vnTreeview', () => { describe('move()', () => { it(`should move an item to anocher parent and then unfold the parent`, () => { - spyOn(controller, 'unfold').and.returnValue( - new Promise(resolve => resolve()) - ); + jest.spyOn(controller, 'unfold'); const newParent = {name: 'My item 2', sons: 0}; const parent = {name: 'My item', sons: 3, childs: [ {name: 'Item 1'}, @@ -255,8 +249,8 @@ describe('Component vnTreeview', () => { }); it(`should move an item to anocher parent`, () => { - spyOn(controller, 'unfold'); - spyOn(controller, 'create'); + jest.spyOn(controller, 'unfold'); + jest.spyOn(controller, 'create'); const newParent = {name: 'My item 2', sons: 0, active: true}; const parent = {name: 'My item', sons: 3, childs: [ {name: 'Item 1'}, diff --git a/front/core/components/watcher/watcher.spec.js b/front/core/components/watcher/watcher.spec.js index 2f7be4704..bad55b870 100644 --- a/front/core/components/watcher/watcher.spec.js +++ b/front/core/components/watcher/watcher.spec.js @@ -25,10 +25,10 @@ describe('Component vnWatcher', () => { })); describe('$onInit()', () => { - it(`should call fetchData() if controllers get and url properties are defined`, () => { + it('should call fetchData() if controllers get and url properties are defined', () => { controller.get = () => {}; controller.url = 'test.com'; - spyOn(controller, 'fetchData'); + jest.spyOn(controller, 'fetchData').mockReturnValue('ok!'); controller.$onInit(); expect(controller.fetchData).toHaveBeenCalledWith(); @@ -45,7 +45,7 @@ describe('Component vnWatcher', () => { describe('fetchData()', () => { it(`should perform a query then store the received data into controller.data and call updateOriginalData()`, () => { - spyOn(controller, 'updateOriginalData'); + jest.spyOn(controller, 'updateOriginalData'); let json = {data: 'some data'}; controller.data = [1]; controller.idField = 0; @@ -61,9 +61,9 @@ describe('Component vnWatcher', () => { }); describe('submitBack()', () => { - it(`should call controller.window.history.back() function after calling controllers submit() function`, done => { - spyOn(controller, 'submit').and.returnValue(Promise.resolve()); - spyOn(controller.window.history, 'back'); + it('should call controller.window.history.back() function after calling controllers submit() function', done => { + jest.spyOn(controller, 'submit').mockReturnValue(Promise.resolve()); + jest.spyOn(controller.window.history, 'back'); controller.submitBack() .then(() => { expect(controller.submit).toHaveBeenCalledWith(); @@ -74,9 +74,9 @@ describe('Component vnWatcher', () => { }); describe('submitGo()', () => { - it(`should call controller.$state.go() function after calling controllers submit() function`, done => { - spyOn(controller, 'submit').and.returnValue(Promise.resolve()); - spyOn(controller.$state, 'go'); + it('should call controller.$state.go() function after calling controllers submit() function', done => { + jest.spyOn(controller, 'submit').mockReturnValue(Promise.resolve()); + jest.spyOn(controller.$state, 'go'); let state = 'the.State'; controller.submitGo(state) .then(() => { @@ -112,7 +112,7 @@ describe('Component vnWatcher', () => { $setSubmitted: () => {}, $setPristine: () => {} }; - spyOn(controller.form, '$setSubmitted'); + jest.spyOn(controller.form, '$setSubmitted'); controller.realSubmit(); expect(controller.form.$setSubmitted).toHaveBeenCalledWith(); @@ -141,7 +141,7 @@ describe('Component vnWatcher', () => { controller.idField = 'id'; controller.url = 'test.com'; let json = {data: 'some data'}; - spyOn(controller, 'writeData').and.callThrough(); + jest.spyOn(controller, 'writeData'); $httpBackend.whenPATCH(`${controller.url}/1`, changedData).respond(json); $httpBackend.expectPATCH(`${controller.url}/1`); controller.realSubmit() @@ -161,7 +161,7 @@ describe('Component vnWatcher', () => { controller.orgData = {id: 1}; controller.url = 'test.com'; let json = {data: 'some data'}; - spyOn(controller, 'writeData').and.callThrough(); + jest.spyOn(controller, 'writeData'); $httpBackend.whenPOST(`${controller.url}`, controller.data).respond(json); $httpBackend.expectPOST(`${controller.url}`, controller.data); controller.realSubmit() @@ -175,7 +175,7 @@ describe('Component vnWatcher', () => { describe('writeData()', () => { it(`should call Object.asssign() function over controllers.data with json.data, then call updateOriginalData function and finally call resolve() function`, () => { - spyOn(controller, 'updateOriginalData'); + jest.spyOn(controller, 'updateOriginalData'); controller.data = {}; let json = {data: 'some data'}; let resolve = jasmine.createSpy('resolve'); diff --git a/front/core/directives/specs/dialog.spec.js b/front/core/directives/specs/dialog.spec.js index 4d5a02e31..fe84cdcc7 100644 --- a/front/core/directives/specs/dialog.spec.js +++ b/front/core/directives/specs/dialog.spec.js @@ -24,7 +24,7 @@ describe('Directive dialog', () => { it('should call show() function if dialog is a instance of vnDialog', () => { let html = `
`; - spyOn(controller, 'show'); + jest.spyOn(controller, 'show'); compile(html); element[0].click(); diff --git a/front/salix/components/left-menu/left-menu.spec.js b/front/salix/components/left-menu/left-menu.spec.js index 12846d2e3..84c1b60d4 100644 --- a/front/salix/components/left-menu/left-menu.spec.js +++ b/front/salix/components/left-menu/left-menu.spec.js @@ -26,7 +26,7 @@ describe('Component vnLeftMenu', () => { describe('depth() setter', () => { it(`should set depth property and call activateItem()`, () => { - spyOn(controller, 'activateItem'); + jest.spyOn(controller, 'activateItem'); controller.depth = 3; expect(controller.depth).toEqual(3); diff --git a/modules/claim/front/action/index.spec.js b/modules/claim/front/action/index.spec.js index 539d2e8ef..c0bcea452 100644 --- a/modules/claim/front/action/index.spec.js +++ b/modules/claim/front/action/index.spec.js @@ -36,8 +36,8 @@ describe('claim', () => { describe('openAddSalesDialog()', () => { it('should call getClaimableFromTicket and $.addSales.show', () => { controller.$ = {addSales: {show: () => {}}}; - spyOn(controller, 'getClaimedSales'); - spyOn(controller.$.addSales, 'show'); + jest.spyOn(controller, 'getClaimedSales'); + jest.spyOn(controller.$.addSales, 'show'); controller.openAddSalesDialog(); expect(controller.getClaimedSales).toHaveBeenCalledWith(); @@ -58,9 +58,9 @@ describe('claim', () => { describe('addClaimedSale(saleFk)', () => { it('should make a post and call refresh, hide and showSuccess', () => { - spyOn(controller.$.model, 'refresh'); - spyOn(controller.$.addSales, 'hide'); - spyOn(controller.vnApp, 'showSuccess'); + jest.spyOn(controller.$.model, 'refresh'); + jest.spyOn(controller.$.addSales, 'hide'); + jest.spyOn(controller.vnApp, 'showSuccess'); $httpBackend.expectPOST(`ClaimEnds/`).respond({}); controller.addClaimedSale(1); $httpBackend.flush(); @@ -73,8 +73,8 @@ describe('claim', () => { describe('deleteClaimedSale(id)', () => { it('should make a delete and call refresh and showSuccess', () => { - spyOn(controller.$.model, 'refresh'); - spyOn(controller.vnApp, 'showSuccess'); + jest.spyOn(controller.$.model, 'refresh'); + jest.spyOn(controller.vnApp, 'showSuccess'); $httpBackend.expectDELETE(`ClaimEnds/1`).respond({}); controller.deleteClaimedSale(1); $httpBackend.flush(); @@ -99,8 +99,8 @@ describe('claim', () => { describe('importToNewRefundTicket()', () => { it('should perform a post query and add lines from a new ticket', () => { - spyOn(controller.$.model, 'refresh'); - spyOn(controller.vnApp, 'showSuccess'); + jest.spyOn(controller.$.model, 'refresh'); + jest.spyOn(controller.vnApp, 'showSuccess'); $httpBackend.expect('POST', `ClaimBeginnings/1/importToNewRefundTicket`).respond({}); controller.importToNewRefundTicket(); $httpBackend.flush(); @@ -112,8 +112,8 @@ describe('claim', () => { describe('showLastTickets()', () => { it('should get a list of tickets and call lastTicketsPopover show() method', () => { - spyOn(controller.$.lastTicketsModel, 'refresh'); - spyOn(controller.$.lastTicketsPopover, 'show'); + jest.spyOn(controller.$.lastTicketsModel, 'refresh'); + jest.spyOn(controller.$.lastTicketsPopover, 'show'); controller.showLastTickets({}); expect(controller.$.lastTicketsModel.refresh).toHaveBeenCalledWith(); @@ -123,9 +123,9 @@ describe('claim', () => { describe('importTicketLines()', () => { it('should perform a post query and add lines from an existent ticket', () => { - spyOn(controller.$.model, 'refresh'); - spyOn(controller.vnApp, 'showSuccess'); - spyOn(controller.$.lastTicketsPopover, 'hide'); + jest.spyOn(controller.$.model, 'refresh'); + jest.spyOn(controller.vnApp, 'showSuccess'); + jest.spyOn(controller.$.lastTicketsPopover, 'hide'); let data = {claimFk: 1, ticketFk: 1}; $httpBackend.expect('POST', `ClaimEnds/importTicketSales`, data).respond({}); controller.importTicketLines(1); @@ -139,8 +139,8 @@ describe('claim', () => { describe('regularize()', () => { it('should perform a post query and reload the claim card', () => { - spyOn(controller.card, 'reload'); - spyOn(controller.vnApp, 'showSuccess'); + jest.spyOn(controller.card, 'reload'); + jest.spyOn(controller.vnApp, 'showSuccess'); let data = {claimFk: $state.params.id}; $httpBackend.expect('POST', `Claims/regularizeClaim`, data).respond({}); @@ -156,9 +156,9 @@ describe('claim', () => { const greugeTypeId = 7; const freightPickUpPrice = 11; it('should do nothing', () => { - spyOn(controller.$http, 'post'); - spyOn(controller.card, 'reload'); - spyOn(controller.vnApp, 'showSuccess'); + jest.spyOn(controller.$http, 'post'); + jest.spyOn(controller.card, 'reload'); + jest.spyOn(controller.vnApp, 'showSuccess'); controller.onUpdateGreugeResponse('cancel'); @@ -168,8 +168,8 @@ describe('claim', () => { }); it('should make a query and get the greugeTypeId and greuge config', () => { - spyOn(controller.card, 'reload'); - spyOn(controller.vnApp, 'showSuccess'); + jest.spyOn(controller.card, 'reload'); + jest.spyOn(controller.vnApp, 'showSuccess'); const greugeTypeParams = $httpParamSerializer({filter: {where: {code: 'freightPickUp'}}}); $httpBackend.expect('GET', `GreugeTypes/findOne?${greugeTypeParams}`).respond({id: greugeTypeId}); @@ -183,13 +183,13 @@ describe('claim', () => { // #1957 - Investigate how to test nested httpBackend requests xit('should perform a insert into greuges', () => { - spyOn(controller.card, 'reload'); - spyOn(controller.vnApp, 'showSuccess'); + jest.spyOn(controller.card, 'reload'); + jest.spyOn(controller.vnApp, 'showSuccess'); - spyOn(controller, 'getGreugeTypeId').and.returnValue(new Promise(resolve => { + jest.spyOn(controller, 'getGreugeTypeId').and.returnValue(new Promise(resolve => { return resolve({id: greugeTypeId}); })); - spyOn(controller, 'getGreugeConfig').and.returnValue(new Promise(resolve => { + jest.spyOn(controller, 'getGreugeConfig').and.returnValue(new Promise(resolve => { return resolve({freightPickUpPrice}); })); diff --git a/modules/claim/front/basic-data/index.spec.js b/modules/claim/front/basic-data/index.spec.js index 187fca275..54b6e025d 100644 --- a/modules/claim/front/basic-data/index.spec.js +++ b/modules/claim/front/basic-data/index.spec.js @@ -17,7 +17,7 @@ describe('Claim', () => { describe('onSubmit()', () => { it(`should redirect to 'claim.card.detail' state`, () => { - spyOn(controller.$state, 'go'); + jest.spyOn(controller.$state, 'go'); controller.onSubmit(); expect(controller.$state.go).toHaveBeenCalledWith('claim.card.detail'); diff --git a/modules/claim/front/descriptor/index.spec.js b/modules/claim/front/descriptor/index.spec.js index 87da181fa..53fa289e0 100644 --- a/modules/claim/front/descriptor/index.spec.js +++ b/modules/claim/front/descriptor/index.spec.js @@ -22,7 +22,7 @@ describe('Item Component vnClaimDescriptor', () => { }; const serializedParams = $httpParamSerializer(params); let expectedPath = `api/report/claim-pickup-order?${serializedParams}`; - spyOn(window, 'open'); + jest.spyOn(window, 'open'); controller.showPickupOrder(); expect(window.open).toHaveBeenCalledWith(expectedPath); @@ -43,7 +43,7 @@ describe('Item Component vnClaimDescriptor', () => { describe('sendPickupOrder(response)', () => { it('should make a query and call vnApp.showMessage() if the response is accept', () => { - spyOn(controller.vnApp, 'showMessage'); + jest.spyOn(controller.vnApp, 'showMessage'); const params = { recipient: 'client@email', @@ -78,8 +78,8 @@ describe('Item Component vnClaimDescriptor', () => { let response = 'accept'; controller.claim = {id: 2}; - spyOn(controller.vnApp, 'showSuccess'); - spyOn(controller.$state, 'go'); + jest.spyOn(controller.vnApp, 'showSuccess'); + jest.spyOn(controller.$state, 'go'); $httpBackend.when('DELETE', `Claims/2`).respond(200); $httpBackend.expect('DELETE', `Claims/2`); controller.deleteClaim(response); diff --git a/modules/claim/front/detail/index.spec.js b/modules/claim/front/detail/index.spec.js index 8d102ae96..a4d7878c5 100644 --- a/modules/claim/front/detail/index.spec.js +++ b/modules/claim/front/detail/index.spec.js @@ -37,8 +37,8 @@ describe('claim', () => { describe('openAddSalesDialog()', () => { it('should call getClaimableFromTicket and $.addSales.show', () => { - spyOn(controller, 'getClaimableFromTicket'); - spyOn(controller.$.addSales, 'show'); + jest.spyOn(controller, 'getClaimableFromTicket'); + jest.spyOn(controller.$.addSales, 'show'); controller.openAddSalesDialog(); expect(controller.getClaimableFromTicket).toHaveBeenCalledWith(); @@ -58,8 +58,8 @@ describe('claim', () => { describe('addClaimedSale(index)', () => { it('should make a post and call refresh, hide and showSuccess', () => { - spyOn(controller.$.addSales, 'hide'); - spyOn(controller.$state, 'go'); + jest.spyOn(controller.$.addSales, 'hide'); + jest.spyOn(controller.$state, 'go'); $httpBackend.expectPOST(`ClaimBeginnings/`).respond({}); controller.addClaimedSale(1); $httpBackend.flush(); @@ -71,7 +71,7 @@ describe('claim', () => { describe('deleteClaimedSale(index)', () => { it('should make a delete and call refresh and showSuccess', () => { - spyOn(controller.$.model, 'remove'); + jest.spyOn(controller.$.model, 'remove'); $httpBackend.expectDELETE(`ClaimBeginnings/1`).respond({}); controller.deleteClaimedSale(0); $httpBackend.flush(); @@ -82,7 +82,7 @@ describe('claim', () => { describe('setClaimedQuantity(id, claimedQuantity)', () => { it('should make a patch and call refresh and showSuccess', () => { - spyOn(controller.vnApp, 'showSuccess'); + jest.spyOn(controller.vnApp, 'showSuccess'); $httpBackend.expectPATCH(`ClaimBeginnings/`).respond({}); controller.setClaimedQuantity(1, 1); $httpBackend.flush(); @@ -112,10 +112,10 @@ describe('claim', () => { controller.newDiscount = 10; - spyOn(controller.vnApp, 'showSuccess'); - spyOn(controller, 'calculateTotals'); - spyOn(controller, 'clearDiscount'); - spyOn(controller.$.editPopover, 'hide'); + jest.spyOn(controller.vnApp, 'showSuccess'); + jest.spyOn(controller, 'calculateTotals'); + jest.spyOn(controller, 'clearDiscount'); + jest.spyOn(controller.$.editPopover, 'hide'); $httpBackend.when('POST', 'Tickets/1/updateDiscount').respond({}); controller.updateDiscount(); @@ -135,8 +135,8 @@ describe('claim', () => { stopImmediatePropagation: () => {}, target: 'the target element' }; - spyOn(event, 'stopImmediatePropagation'); - spyOn(controller.$.descriptor, 'show'); + jest.spyOn(event, 'stopImmediatePropagation'); + jest.spyOn(controller.$.descriptor, 'show'); controller.showItemDescriptor(event, itemId); diff --git a/modules/claim/front/development/index.spec.js b/modules/claim/front/development/index.spec.js index 007a977c3..4d9ebdc7e 100644 --- a/modules/claim/front/development/index.spec.js +++ b/modules/claim/front/development/index.spec.js @@ -20,7 +20,7 @@ describe('Claim', () => { describe('onSubmit()', () => { it(`should redirect to 'claim.card.action' state`, () => { - spyOn(controller.$state, 'go'); + jest.spyOn(controller.$state, 'go'); controller.onSubmit(); expect(controller.$state.go).toHaveBeenCalledWith('claim.card.action'); diff --git a/modules/claim/front/photos/index.spec.js b/modules/claim/front/photos/index.spec.js index 731988a84..81eab69ee 100644 --- a/modules/claim/front/photos/index.spec.js +++ b/modules/claim/front/photos/index.spec.js @@ -28,8 +28,8 @@ describe('Claim', () => { it('should make an HTTP Post query', () => { const dmsId = 1; const dmsIndex = 0; - spyOn(controller.vnApp, 'showSuccess'); - spyOn(controller.$.model, 'remove'); + jest.spyOn(controller.vnApp, 'showSuccess'); + jest.spyOn(controller.$.model, 'remove'); controller.photos = [{dmsFk: 1}]; controller.dmsIndex = dmsIndex; @@ -62,8 +62,8 @@ describe('Claim', () => { it('should make an HTTP Post query, then refresh the model data', () => { const claimId = 1; const dmsIndex = 0; - spyOn(controller.vnApp, 'showSuccess'); - spyOn(controller.$.model, 'refresh'); + jest.spyOn(controller.vnApp, 'showSuccess'); + jest.spyOn(controller.$.model, 'refresh'); controller.photos = [{dmsFk: 1}]; controller.dmsIndex = dmsIndex; controller.dms = {files: []}; diff --git a/modules/claim/front/summary/index.spec.js b/modules/claim/front/summary/index.spec.js index 858829a68..f1897a3e0 100644 --- a/modules/claim/front/summary/index.spec.js +++ b/modules/claim/front/summary/index.spec.js @@ -28,7 +28,7 @@ describe('Claim', () => { describe('$onChanges()', () => { it('should call getSummary when item.id is defined', () => { - spyOn(controller, 'getSummary'); + jest.spyOn(controller, 'getSummary'); controller.$onChanges(); expect(controller.getSummary).toHaveBeenCalledWith(); diff --git a/modules/client/front/address/create/index.spec.js b/modules/client/front/address/create/index.spec.js index 6bd53cb72..289e0572d 100644 --- a/modules/client/front/address/create/index.spec.js +++ b/modules/client/front/address/create/index.spec.js @@ -35,7 +35,7 @@ describe('Client', () => { describe('onSubmit()', () => { it('should perform a PATCH and not set value to defaultAddressFk property', () => { - spyOn(controller.$state, 'go'); + jest.spyOn(controller.$state, 'go'); controller.address.isDefaultAddress = false; controller.onSubmit(); @@ -44,7 +44,7 @@ describe('Client', () => { }); it('should perform a PATCH and set a value to defaultAddressFk property', () => { - spyOn(controller.$state, 'go'); + jest.spyOn(controller.$state, 'go'); controller.address.isDefaultAddress = true; controller.onSubmit(); diff --git a/modules/client/front/address/edit/index.spec.js b/modules/client/front/address/edit/index.spec.js index 3d91ad440..b67138b6d 100644 --- a/modules/client/front/address/edit/index.spec.js +++ b/modules/client/front/address/edit/index.spec.js @@ -36,8 +36,8 @@ describe('Client', () => { describe('removeObservation()', () => { it('should call $.watcher.setDirty() and $.model.remove(index)', () => { - spyOn(controller.$.watcher, 'setDirty'); - spyOn(controller.$.model, 'remove'); + jest.spyOn(controller.$.watcher, 'setDirty'); + jest.spyOn(controller.$.model, 'remove'); controller.removeObservation(1); expect(controller.$.model.remove).toHaveBeenCalledWith(1); @@ -47,7 +47,7 @@ describe('Client', () => { describe('cancel()', () => { it('should call goToIndex()', () => { - spyOn(controller, 'goToIndex'); + jest.spyOn(controller, 'goToIndex'); controller.cancel(); expect(controller.goToIndex).toHaveBeenCalledWith(); @@ -56,7 +56,7 @@ describe('Client', () => { describe('goToIndex()', () => { it('should call $state.go("client.card.address.index")', () => { - spyOn(controller.$state, 'go'); + jest.spyOn(controller.$state, 'go'); controller.goToIndex(); expect(controller.$state.go).toHaveBeenCalledWith('client.card.address.index'); diff --git a/modules/client/front/address/index/index.spec.js b/modules/client/front/address/index/index.spec.js index 61495e7a3..1398f617f 100644 --- a/modules/client/front/address/index/index.spec.js +++ b/modules/client/front/address/index/index.spec.js @@ -22,7 +22,7 @@ describe('Client', () => { describe('setDefault()', () => { it('should perform a PATCH and set a value to defaultAddressFk property', () => { - spyOn(controller, 'sortAddresses'); + jest.spyOn(controller, 'sortAddresses'); let address = {id: 1}; let data = {defaultAddressFk: address.id}; let expectedResult = {defaultAddressFk: address.id}; diff --git a/modules/client/front/balance/index/index.spec.js b/modules/client/front/balance/index/index.spec.js index e044b7979..769164def 100644 --- a/modules/client/front/balance/index/index.spec.js +++ b/modules/client/front/balance/index/index.spec.js @@ -31,9 +31,9 @@ describe('Client', () => { it('should apply the filters on he models and get the client balance', () => { controller._companyId = 442; controller.$stateParams.id = 101; - spyOn(controller, 'getBalances'); - spyOn(controller.$.model, 'applyFilter').and.returnValue(Promise.resolve()); - spyOn(controller.$.riskModel, 'applyFilter').and.returnValue(Promise.resolve()); + jest.spyOn(controller, 'getBalances'); + jest.spyOn(controller.$.model, 'applyFilter').mockReturnValue(Promise.resolve()); + jest.spyOn(controller.$.riskModel, 'applyFilter').mockReturnValue(Promise.resolve()); controller.getData().then(() => { expect(controller.$.model.applyFilter).toHaveBeenCalledWith(null, {'clientId': 101, 'companyId': 442}); @@ -45,7 +45,7 @@ describe('Client', () => { describe('company setter/getter', () => { it('should return the company and then call getData()', () => { - spyOn(controller, 'getData'); + jest.spyOn(controller, 'getData').mockReturnValue('ok!'); controller.companyId = 442; expect(controller._companyId).toEqual(442); @@ -64,7 +64,7 @@ describe('Client', () => { describe('getBalances()', () => { it('should return the total client balance amount', () => { - spyOn(controller, 'getCurrentBalance').and.callThrough(); + jest.spyOn(controller, 'getCurrentBalance'); controller._companyId = 442; controller.$.model = {data: [{ @@ -94,7 +94,7 @@ describe('Client', () => { describe('balances() setter', () => { it('should set the balances data and not call the getBalances() method', () => { - spyOn(controller, 'getBalances'); + jest.spyOn(controller, 'getBalances'); controller.$.riskModel.data = null; controller.balances = [{ id: 1, @@ -115,7 +115,7 @@ describe('Client', () => { }); it('should set the balances data and then call the getBalances() method', () => { - spyOn(controller, 'getBalances'); + jest.spyOn(controller, 'getBalances').mockReturnValue('ok!'); controller.balances = [{ id: 1, debit: 1000, diff --git a/modules/client/front/billing-data/index.spec.js b/modules/client/front/billing-data/index.spec.js index ade8b2fff..1b295abeb 100644 --- a/modules/client/front/billing-data/index.spec.js +++ b/modules/client/front/billing-data/index.spec.js @@ -15,7 +15,7 @@ describe('Client', () => { vnApp = _vnApp_; $scope = $rootScope.$new(); $scope.watcher = {}; - spyOn(vnApp, 'showError'); + jest.spyOn(vnApp, 'showError'); controller = $componentController('vnClientBillingData', {$element, $scope}); controller.client = {id: 101, name: 'Client name', payMethodFk: 4}; $scope.watcher.orgData = {id: 101, name: 'Client name', payMethodFk: 4}; diff --git a/modules/client/front/create/index.spec.js b/modules/client/front/create/index.spec.js index b59dffe44..656392e3d 100644 --- a/modules/client/front/create/index.spec.js +++ b/modules/client/front/create/index.spec.js @@ -33,7 +33,7 @@ describe('Client', () => { describe('onSubmit()', () => { it(`should call submit() on the watcher then expect a callback`, () => { - spyOn($state, 'go'); + jest.spyOn($state, 'go'); controller.onSubmit(); expect(controller.$state.go).toHaveBeenCalledWith('client.card.basicData', {id: '1234'}); diff --git a/modules/client/front/credit-insurance/index/index.spec.js b/modules/client/front/credit-insurance/index/index.spec.js index 733936bf2..b6a86e5dd 100644 --- a/modules/client/front/credit-insurance/index/index.spec.js +++ b/modules/client/front/credit-insurance/index/index.spec.js @@ -60,7 +60,7 @@ describe('Client', () => { describe('closeContract()', () => { it('should define the classificationId property of the controller and then call the show method()', () => { controller.$scope.closeContract = {show: () => {}}; - spyOn(controller.$scope.closeContract, 'show'); + jest.spyOn(controller.$scope.closeContract, 'show'); expect(controller.classificationId).toBeFalsy(); controller.closeContract({id: 1}); @@ -72,7 +72,7 @@ describe('Client', () => { describe('returnDialog()', () => { it('should call the returnDialog method and perform a PATCH query, then call _getClassifications method', () => { - spyOn(controller, '_getClassifications'); + jest.spyOn(controller, '_getClassifications').mockReturnValue('ok!'); controller.classificationId = 1; $httpBackend.when('PATCH', `CreditClassifications/1`).respond(200); $httpBackend.expect('PATCH', `CreditClassifications/1`); diff --git a/modules/client/front/credit/create/index.spec.js b/modules/client/front/credit/create/index.spec.js index 3dd96aaa1..13f034969 100644 --- a/modules/client/front/credit/create/index.spec.js +++ b/modules/client/front/credit/create/index.spec.js @@ -42,7 +42,7 @@ describe('Client', () => { }); it('should call show() method when the client have a recovery', () => { - spyOn(controller.$scope.confirmation, 'show'); + jest.spyOn(controller.$scope.confirmation, 'show'); $httpBackend.whenGET(`Recoveries/101/hasActiveRecovery`).respond(true); $httpBackend.expectGET(`Recoveries/101/hasActiveRecovery`); controller.onSubmit(); @@ -52,7 +52,7 @@ describe('Client', () => { }); it('should call addCredit() method when the client doesnt have a recovery', () => { - spyOn(controller, 'addCredit'); + jest.spyOn(controller, 'addCredit'); $httpBackend.whenGET(`Recoveries/101/hasActiveRecovery`).respond(false); $httpBackend.expectGET(`Recoveries/101/hasActiveRecovery`); controller.onSubmit(); @@ -64,7 +64,7 @@ describe('Client', () => { describe('cancel()', () => { it('should call goToIndex()', () => { - spyOn(controller, 'goToIndex'); + jest.spyOn(controller, 'goToIndex'); controller.cancel(); expect(controller.goToIndex).toHaveBeenCalledWith(); @@ -73,7 +73,7 @@ describe('Client', () => { describe('returnDialog()', () => { it('should call addCredit() when is called with accept', () => { - spyOn(controller, 'addCredit'); + jest.spyOn(controller, 'addCredit'); controller.returnDialog('accept'); expect(controller.addCredit).toHaveBeenCalledWith(); @@ -82,7 +82,7 @@ describe('Client', () => { describe('addCredit()', () => { it('should call the function go() on $state to go to the credit list', () => { - spyOn($state, 'go'); + jest.spyOn($state, 'go'); client.credit = 1; controller.addCredit(); diff --git a/modules/client/front/descriptor-popover/index.spec.js b/modules/client/front/descriptor-popover/index.spec.js index 6e76d3062..ff8ffceff 100644 --- a/modules/client/front/descriptor-popover/index.spec.js +++ b/modules/client/front/descriptor-popover/index.spec.js @@ -23,7 +23,7 @@ describe('Client', () => { it(`should not apply any changes if the received id is the same stored in _clientFk`, () => { controller.client = 'I exist!'; controller._clientFk = 1; - spyOn(controller, 'getCard'); + jest.spyOn(controller, 'getCard'); controller.clientFk = 1; expect(controller.client).toEqual('I exist!'); @@ -34,7 +34,7 @@ describe('Client', () => { it(`should set the received id into _clientFk, set the client to null and then call getCard()`, () => { controller.client = `Please don't`; controller._clientFk = 1; - spyOn(controller, 'getCard'); + jest.spyOn(controller, 'getCard'); controller.clientFk = 999; expect(controller.client).toBeNull(); @@ -45,7 +45,7 @@ describe('Client', () => { describe('client()', () => { it(`should save the client into _client and then call relocate()`, () => { - spyOn(controller.$.popover, 'relocate'); + jest.spyOn(controller.$.popover, 'relocate'); controller.client = `i'm the client!`; $timeout.flush(); @@ -56,7 +56,7 @@ describe('Client', () => { describe('show()', () => { it(`should call the show()`, () => { - spyOn(controller.$.popover, 'show'); + jest.spyOn(controller.$.popover, 'show'); controller.show(); expect(controller.$.popover.show).toHaveBeenCalledWith(); diff --git a/modules/client/front/dms/create/index.spec.js b/modules/client/front/dms/create/index.spec.js index 4ff8ce122..2c1215d6b 100644 --- a/modules/client/front/dms/create/index.spec.js +++ b/modules/client/front/dms/create/index.spec.js @@ -19,8 +19,8 @@ describe('Client', () => { describe('client() setter', () => { it('should set the client data and then call setDefaultParams() and getAllowedContentTypes()', () => { - spyOn(controller, 'setDefaultParams'); - spyOn(controller, 'getAllowedContentTypes'); + jest.spyOn(controller, 'setDefaultParams'); + jest.spyOn(controller, 'getAllowedContentTypes'); controller.client = { id: 15, name: 'Bruce wayne' diff --git a/modules/client/front/dms/edit/index.spec.js b/modules/client/front/dms/edit/index.spec.js index 732a90868..4d432cfd0 100644 --- a/modules/client/front/dms/edit/index.spec.js +++ b/modules/client/front/dms/edit/index.spec.js @@ -19,8 +19,8 @@ describe('Client', () => { describe('client() setter', () => { it('should set the client data and then call setDefaultParams() and getAllowedContentTypes()', () => { - spyOn(controller, 'setDefaultParams'); - spyOn(controller, 'getAllowedContentTypes'); + jest.spyOn(controller, 'setDefaultParams'); + jest.spyOn(controller, 'getAllowedContentTypes'); controller._client = undefined; controller.client = { id: 15 diff --git a/modules/client/front/dms/index/index.spec.js b/modules/client/front/dms/index/index.spec.js index 16190177b..49b6014c0 100644 --- a/modules/client/front/dms/index/index.spec.js +++ b/modules/client/front/dms/index/index.spec.js @@ -22,8 +22,8 @@ describe('Client', () => { it('should make an HTTP Post query', () => { const dmsId = 1; const dmsIndex = 0; - spyOn(controller.vnApp, 'showSuccess'); - spyOn(controller.$.model, 'remove'); + jest.spyOn(controller.vnApp, 'showSuccess'); + jest.spyOn(controller.$.model, 'remove'); controller.clientDms = [{dmsFk: 1}]; controller.dmsIndex = dmsIndex; diff --git a/modules/client/front/fiscal-data/index.spec.js b/modules/client/front/fiscal-data/index.spec.js index 1e92426ec..52c2ee29e 100644 --- a/modules/client/front/fiscal-data/index.spec.js +++ b/modules/client/front/fiscal-data/index.spec.js @@ -29,7 +29,7 @@ describe('Client', () => { describe('onSubmit()', () => { it('should call the save() method directly', () => { - spyOn(controller, 'save'); + jest.spyOn(controller, 'save'); controller.onSubmit(); @@ -37,8 +37,8 @@ describe('Client', () => { }); it('should call the checkExistingClient() if the isTaxDataChecked property is checked', () => { - spyOn(controller, 'save'); - spyOn(controller, 'checkExistingClient'); + jest.spyOn(controller, 'save'); + jest.spyOn(controller, 'checkExistingClient'); controller.client.isTaxDataChecked = true; controller.onSubmit(); @@ -51,7 +51,7 @@ describe('Client', () => { describe('checkExistingClient()', () => { it('should show a save confirmation when a duplicated client is found and then set the despiteOfClient property', () => { controller.$.confirmDuplicatedClient = {show: () => {}}; - spyOn(controller.$.confirmDuplicatedClient, 'show'); + jest.spyOn(controller.$.confirmDuplicatedClient, 'show'); const filterObj = { where: { and: [ @@ -74,7 +74,7 @@ describe('Client', () => { describe('checkEtChanges()', () => { it(`should show a propagation confirmation if isEqualizated property is changed and invoice by address is checked`, () => { controller.$.propagateIsEqualizated = {show: () => {}}; - spyOn(controller.$.propagateIsEqualizated, 'show'); + jest.spyOn(controller.$.propagateIsEqualizated, 'show'); const orgData = $scope.watcher.orgData; orgData.hasToInvoiceByAddress = true; @@ -86,7 +86,7 @@ describe('Client', () => { }); it(`should call to the onAcceptEt() method if isEqualizated property is changed and invoice by address isn't checked`, () => { - spyOn(controller, 'onAcceptEt'); + jest.spyOn(controller, 'onAcceptEt'); const orgData = $scope.watcher.orgData; orgData.hasToInvoiceByAddress = false; diff --git a/modules/client/front/greuge/create/index.spec.js b/modules/client/front/greuge/create/index.spec.js index 76b361cc5..73563ca3d 100644 --- a/modules/client/front/greuge/create/index.spec.js +++ b/modules/client/front/greuge/create/index.spec.js @@ -27,7 +27,7 @@ describe('Client', () => { describe('onSubmit()', () => { it('should call the function go() on $state to go to the greuges list', () => { - spyOn($state, 'go'); + jest.spyOn($state, 'go'); controller.onSubmit(); expect(controller.$state.go).toHaveBeenCalledWith('client.card.greuge.index'); diff --git a/modules/client/front/index/index.spec.js b/modules/client/front/index/index.spec.js index da149838d..8b00381c7 100644 --- a/modules/client/front/index/index.spec.js +++ b/modules/client/front/index/index.spec.js @@ -15,7 +15,7 @@ describe('Client index', () => { it('should navigate to the ticket index using params as filter', () => { const client = {id: 101}; const event = new MouseEvent('click', {cancelable: true}); - spyOn($state, 'go'); + jest.spyOn($state, 'go'); controller.filterTickets(client, event); diff --git a/modules/client/front/postcode/index.spec.js b/modules/client/front/postcode/index.spec.js index 2ca3f8c7b..04f1a8924 100644 --- a/modules/client/front/postcode/index.spec.js +++ b/modules/client/front/postcode/index.spec.js @@ -20,7 +20,7 @@ describe('Client', () => { let params = {townFk: 1, provinceFk: 1, countryFk: 1, code: '46460'}; controller.data = {townFk: 1, provinceFk: 1, countryFk: 1, code: '46460'}; - spyOn(controller.vnApp, 'showMessage'); + jest.spyOn(controller.vnApp, 'showMessage'); $httpBackend.when('PATCH', `postcodes`, params).respond(200, params); $httpBackend.expect('PATCH', `postcodes`, params).respond(params); diff --git a/modules/client/front/recovery/create/index.spec.js b/modules/client/front/recovery/create/index.spec.js index d1d3f39f2..cf28cee8d 100644 --- a/modules/client/front/recovery/create/index.spec.js +++ b/modules/client/front/recovery/create/index.spec.js @@ -27,7 +27,7 @@ describe('Client', () => { describe('onSubmit()', () => { it('should call the function go() on $state to go to the recovery list', () => { - spyOn($state, 'go'); + jest.spyOn($state, 'go'); controller.onSubmit(); expect(controller.$state.go).toHaveBeenCalledWith('client.card.recovery.index'); diff --git a/modules/client/front/sample/create/index.spec.js b/modules/client/front/sample/create/index.spec.js index da9a557f1..a08ee013c 100644 --- a/modules/client/front/sample/create/index.spec.js +++ b/modules/client/front/sample/create/index.spec.js @@ -52,7 +52,7 @@ describe('Client', () => { describe('onSubmit()', () => { it(`should call sendSample() method`, () => { - spyOn(controller, 'sendSample'); + jest.spyOn(controller, 'sendSample'); controller.onSubmit(); expect(controller.sendSample).toHaveBeenCalledWith(); @@ -61,7 +61,7 @@ describe('Client', () => { describe('send()', () => { it(`should not perform an HTTP query if no recipient is specified`, () => { - spyOn(controller.$http, 'get'); + jest.spyOn(controller.$http, 'get'); controller.$.sampleType.selection = { hasCompany: false, @@ -77,7 +77,7 @@ describe('Client', () => { }); it(`should not perform an HTTP query if no sample is specified`, () => { - spyOn(controller.$http, 'get'); + jest.spyOn(controller.$http, 'get'); controller.$.sampleType.selection = null; controller.clientSample = { @@ -91,7 +91,7 @@ describe('Client', () => { }); it(`should not perform an HTTP query if company is required and not specified`, () => { - spyOn(controller.$http, 'get'); + jest.spyOn(controller.$http, 'get'); controller.$.sampleType.selection = { hasCompany: true, @@ -143,7 +143,7 @@ describe('Client', () => { describe('showPreview()', () => { it(`should open a sample preview`, () => { - spyOn(controller.$.showPreview, 'show'); + jest.spyOn(controller.$.showPreview, 'show'); controller.send = (isPreview, cb) => { cb({ @@ -158,7 +158,7 @@ describe('Client', () => { describe('sendSample()', () => { it(`should perform a query (GET) and call go() method`, () => { - spyOn(controller.$state, 'go'); + jest.spyOn(controller.$state, 'go'); controller.send = (isPreview, cb) => { cb({ diff --git a/modules/client/front/sms/index.spec.js b/modules/client/front/sms/index.spec.js index 03d9cbf1d..3958aec3b 100644 --- a/modules/client/front/sms/index.spec.js +++ b/modules/client/front/sms/index.spec.js @@ -27,7 +27,7 @@ describe('Client', () => { let params = {destinationFk: 101, destination: 111111111, message: 'My SMS'}; controller.sms = {destinationFk: 101, destination: 111111111, message: 'My SMS'}; - spyOn(controller.vnApp, 'showMessage'); + jest.spyOn(controller.vnApp, 'showMessage'); $httpBackend.expect('POST', `Clients/101/sendSms`, params).respond(200, params); controller.onResponse('accept'); @@ -39,7 +39,7 @@ describe('Client', () => { it('should call onResponse without the destination and show an error snackbar', () => { controller.sms = {destinationFk: 101, message: 'My SMS'}; - spyOn(controller.vnApp, 'showError'); + jest.spyOn(controller.vnApp, 'showError'); controller.onResponse('accept'); @@ -49,7 +49,7 @@ describe('Client', () => { it('should call onResponse without the message and show an error snackbar', () => { controller.sms = {destinationFk: 101, destination: 222222222}; - spyOn(controller.vnApp, 'showError'); + jest.spyOn(controller.vnApp, 'showError'); controller.onResponse('accept'); diff --git a/modules/client/front/summary/index.spec.js b/modules/client/front/summary/index.spec.js index 24f9b55dc..4835a01af 100644 --- a/modules/client/front/summary/index.spec.js +++ b/modules/client/front/summary/index.spec.js @@ -14,10 +14,10 @@ describe('Client', () => { })); describe('$onChanges()', () => { - it('should perform a GET query and define summary property', () => { + it('should perform a GET query and then define the summary property', () => { let res = {name: 'Superman', classifications: []}; - spyOn(controller, 'sumRisk'); + jest.spyOn(controller, 'sumRisk').mockReturnValue('ok!'); $httpBackend.when('GET', `Clients/101/summary`).respond(200, res); $httpBackend.expect('GET', `Clients/101/summary`); diff --git a/modules/client/front/web-access/index.spec.js b/modules/client/front/web-access/index.spec.js index d7329bf8c..319d1d1dc 100644 --- a/modules/client/front/web-access/index.spec.js +++ b/modules/client/front/web-access/index.spec.js @@ -12,13 +12,13 @@ describe('Component VnClientWebAccess', () => { $scope = $rootScope.$new(); $httpBackend = _$httpBackend_; vnApp = _vnApp_; - spyOn(vnApp, 'showError'); + jest.spyOn(vnApp, 'showError'); controller = $componentController('vnClientWebAccess', {$scope}); })); describe('$onChanges()', () => { it(`should pass client's account data to account then call isCustomer function`, () => { - spyOn(controller, 'isCustomer'); + jest.spyOn(controller, 'isCustomer'); controller.client = {client: 'Bruce Wayne', account: 'Wayne Industries'}; controller.account = {}; controller.$onChanges(); diff --git a/modules/client/front/web-payment/index.spec.js b/modules/client/front/web-payment/index.spec.js index f5a801ccb..dc2d40b1a 100644 --- a/modules/client/front/web-payment/index.spec.js +++ b/modules/client/front/web-payment/index.spec.js @@ -14,7 +14,7 @@ describe('Component vnClientWebPayment', () => { $scope.model = crudModel; $httpBackend = _$httpBackend_; vnApp = _vnApp_; - spyOn(vnApp, 'showError'); + jest.spyOn(vnApp, 'showError'); controller = $componentController('vnClientWebPayment', {$scope: $scope}); })); diff --git a/modules/entry/front/descriptor/index.spec.js b/modules/entry/front/descriptor/index.spec.js index a63abc0f1..69472eae1 100644 --- a/modules/entry/front/descriptor/index.spec.js +++ b/modules/entry/front/descriptor/index.spec.js @@ -26,7 +26,7 @@ describe('Entry Component vnEntryDescriptor', () => { }; const serializedParams = $httpParamSerializer(params); let expectedPath = `api/report/entry-order?${serializedParams}`; - spyOn(window, 'open'); + jest.spyOn(window, 'open'); controller.showEntryReport(); expect(window.open).toHaveBeenCalledWith(expectedPath); diff --git a/modules/entry/front/summary/index.spec.js b/modules/entry/front/summary/index.spec.js index ea4a5a7c1..64952cec1 100644 --- a/modules/entry/front/summary/index.spec.js +++ b/modules/entry/front/summary/index.spec.js @@ -19,7 +19,7 @@ describe('component vnEntrySummary', () => { describe('entry setter/getter', () => { it('should check if value.id is defined', () => { - spyOn(controller, 'getEntryData'); + jest.spyOn(controller, 'getEntryData'); controller.entry = {id: 1}; @@ -27,7 +27,7 @@ describe('component vnEntrySummary', () => { }); it('should return the entry and then call getEntryData()', () => { - spyOn(controller, 'getEntryData'); + jest.spyOn(controller, 'getEntryData'); controller.entry = {id: 99}; expect(controller._entry.id).toEqual(99); diff --git a/modules/item/front/create/index.spec.js b/modules/item/front/create/index.spec.js index cb58cdaa3..cd5197305 100644 --- a/modules/item/front/create/index.spec.js +++ b/modules/item/front/create/index.spec.js @@ -27,7 +27,7 @@ describe('Item', () => { describe('onSubmit()', () => { it(`should call submit() on the watcher then expect a callback`, () => { - spyOn($state, 'go'); + jest.spyOn($state, 'go'); controller.onSubmit(); expect(controller.$state.go).toHaveBeenCalledWith('item.card.basicData', {id: 1}); diff --git a/modules/item/front/descriptor-popover/index.spec.js b/modules/item/front/descriptor-popover/index.spec.js index 67708faf2..eb09bf7d9 100644 --- a/modules/item/front/descriptor-popover/index.spec.js +++ b/modules/item/front/descriptor-popover/index.spec.js @@ -23,7 +23,7 @@ describe('Item', () => { it(`should not apply any changes if the received id is the same stored in _itemFk`, () => { controller.item = 'I exist!'; controller._itemFk = 1; - spyOn(controller, 'getCard'); + jest.spyOn(controller, 'getCard'); controller.itemFk = 1; expect(controller.item).toEqual('I exist!'); @@ -34,7 +34,7 @@ describe('Item', () => { it(`should set the received id into _itemFk, set the item to null and then call getCard()`, () => { controller.item = `Please don't`; controller._itemFk = 1; - spyOn(controller, 'getCard'); + jest.spyOn(controller, 'getCard'); controller.itemFk = 999; expect(controller.item).toBeNull(); @@ -45,7 +45,7 @@ describe('Item', () => { describe('item()', () => { it(`should save the item into _item and then call relocate()`, () => { - spyOn(controller.$.popover, 'relocate'); + jest.spyOn(controller.$.popover, 'relocate'); controller.item = `i'm the item!`; $timeout.flush(); @@ -56,7 +56,7 @@ describe('Item', () => { describe('show()', () => { it(`should call the show()`, () => { - spyOn(controller.$.popover, 'show'); + jest.spyOn(controller.$.popover, 'show'); controller.show(); expect(controller.$.popover.show).toHaveBeenCalledWith(); diff --git a/modules/item/front/diary/index.spec.js b/modules/item/front/diary/index.spec.js index 9286f2863..9e7f0cf0c 100644 --- a/modules/item/front/diary/index.spec.js +++ b/modules/item/front/diary/index.spec.js @@ -68,8 +68,8 @@ describe('Item', () => { }); describe('set item()', () => { - it(`should set warehouseFk property based on itemType warehouseFk`, () => { - spyOn(controller.$scope, '$applyAsync').and.callThrough(); + it('should set warehouseFk property based on itemType warehouseFk', () => { + jest.spyOn(controller.$scope, '$applyAsync'); controller.item = {id: 1, itemType: {warehouseFk: 1}}; expect(controller.$scope.$applyAsync).toHaveBeenCalledWith(jasmine.any(Function)); @@ -80,7 +80,7 @@ describe('Item', () => { }); it(`should set warehouseFk property based on url query warehouseFk`, () => { - spyOn(controller.$scope, '$applyAsync').and.callThrough(); + jest.spyOn(controller.$scope, '$applyAsync'); controller.$stateParams.warehouseFk = 4; controller.item = {id: 1, itemType: {warehouseFk: 1}}; diff --git a/modules/item/front/index/index.spec.js b/modules/item/front/index/index.spec.js index 0de80323e..aa8523b79 100644 --- a/modules/item/front/index/index.spec.js +++ b/modules/item/front/index/index.spec.js @@ -16,7 +16,7 @@ describe('Item', () => { describe('onCloneAccept()', () => { it('should do nothing if response is not accept', () => { - spyOn(controller.$state, 'go'); + jest.spyOn(controller.$state, 'go'); let response = 'ERROR!'; controller.itemSelected = 'check me'; @@ -28,7 +28,7 @@ describe('Item', () => { }); it('should do nothing if response is accept but itemSelected is not defined in the controller', () => { - spyOn(controller.$state, 'go'); + jest.spyOn(controller.$state, 'go'); let response = 'accept'; controller.itemSelected = undefined; @@ -40,7 +40,7 @@ describe('Item', () => { }); it('should perform a post query and then call go() then update itemSelected in the controller', () => { - spyOn(controller.$state, 'go'); + jest.spyOn(controller.$state, 'go'); let response = 'accept'; controller.itemSelected = {id: 1}; diff --git a/modules/item/front/request/index.spec.js b/modules/item/front/request/index.spec.js index 4c1e31634..aaaade566 100644 --- a/modules/item/front/request/index.spec.js +++ b/modules/item/front/request/index.spec.js @@ -46,7 +46,7 @@ describe('Item', () => { describe('confirmRequest()', () => { it(`should do nothing if the request does't have itemFk or saleQuantity`, () => { let request = {}; - spyOn(controller.vnApp, 'showSuccess'); + jest.spyOn(controller.vnApp, 'showSuccess'); controller.confirmRequest(request); @@ -54,9 +54,9 @@ describe('Item', () => { }); it('should perform a query and call vnApp.showSuccess() and refresh if the conditions are met', () => { - spyOn(controller.vnApp, 'showSuccess'); + jest.spyOn(controller.vnApp, 'showSuccess'); let model = controller.$.model; - spyOn(model, 'refresh'); + jest.spyOn(model, 'refresh'); const expectedResult = {concept: 'Melee Weapon'}; let request = {itemFk: 1, saleQuantity: 1, id: 1}; @@ -73,7 +73,7 @@ describe('Item', () => { describe('changeQuantity()', () => { it(`should call confirmRequest() if there's no sale id in the request`, () => { let request = {}; - spyOn(controller, 'confirmRequest'); + jest.spyOn(controller, 'confirmRequest'); controller.changeQuantity(request); @@ -82,7 +82,7 @@ describe('Item', () => { it(`should perform a query and call vnApp.showSuccess() if the conditions are met`, () => { let request = {saleFk: 1, saleQuantity: 1}; - spyOn(controller.vnApp, 'showSuccess'); + jest.spyOn(controller.vnApp, 'showSuccess'); $httpBackend.when('PATCH', `Sales/${request.saleFk}/`).respond(); @@ -114,7 +114,7 @@ describe('Item', () => { describe('denyRequest()', () => { it(`should perform a query and call vnApp.showSuccess(), refresh(), hide() and set denyObservation to null in the controller`, () => { - spyOn(controller.vnApp, 'showSuccess'); + jest.spyOn(controller.vnApp, 'showSuccess'); const request = {id: 1}; const expectedResult = {isOk: false, attenderFk: 106, response: 'Denied!'}; diff --git a/modules/item/front/summary/index.spec.js b/modules/item/front/summary/index.spec.js index 1b6c2a812..8058ece10 100644 --- a/modules/item/front/summary/index.spec.js +++ b/modules/item/front/summary/index.spec.js @@ -27,7 +27,7 @@ describe('Item', () => { describe('$onChanges()', () => { it('should call getSummary when item.id is defined', () => { - spyOn(controller, 'getSummary'); + jest.spyOn(controller, 'getSummary'); controller.$onChanges(); expect(controller.getSummary).toHaveBeenCalledWith(); diff --git a/modules/item/front/tags/index.spec.js b/modules/item/front/tags/index.spec.js index d1b5acccc..a59f0b6e0 100644 --- a/modules/item/front/tags/index.spec.js +++ b/modules/item/front/tags/index.spec.js @@ -17,7 +17,7 @@ describe('Item', () => { describe('itemTags setter', () => { it('should call getSourceTable one time for each element in the value array', () => { - spyOn(controller, 'getSourceTable'); + jest.spyOn(controller, 'getSourceTable'); let itemTags = [ {id: 1}, {id: 2}, @@ -27,7 +27,7 @@ describe('Item', () => { controller.itemTags = itemTags; - expect(controller.getSourceTable.calls.count()).toEqual(4); + expect(controller.getSourceTable.mock.calls.length).toEqual(4); expect(controller.itemTags).toEqual(itemTags); }); }); diff --git a/modules/item/front/tax/index.spec.js b/modules/item/front/tax/index.spec.js index ddc582ad3..95e46cfbf 100644 --- a/modules/item/front/tax/index.spec.js +++ b/modules/item/front/tax/index.spec.js @@ -44,8 +44,8 @@ describe('Item', () => { describe('submit()', () => { it('should perform a post to update taxes', () => { - spyOn(controller.$.watcher, 'notifySaved'); - spyOn(controller.$.watcher, 'updateOriginalData'); + jest.spyOn(controller.$.watcher, 'notifySaved'); + jest.spyOn(controller.$.watcher, 'updateOriginalData'); controller.taxes = [ {id: 37, countryFk: 1, taxClassFk: 1, country: {id: 1, country: 'España'}} ]; diff --git a/modules/order/front/create/card.spec.js b/modules/order/front/create/card.spec.js index 32949fd54..ef2bba529 100644 --- a/modules/order/front/create/card.spec.js +++ b/modules/order/front/create/card.spec.js @@ -73,7 +73,7 @@ describe('Order', () => { describe('onSubmit()', () => { it(`should call createOrder()`, () => { - spyOn(controller, 'createOrder'); + jest.spyOn(controller, 'createOrder'); controller.onSubmit(); expect(controller.createOrder).toHaveBeenCalledWith(); @@ -86,8 +86,8 @@ describe('Order', () => { controller.order.addressFk = 101; controller.order.agencyModeFk = 101; - spyOn(controller.vnApp, 'showSuccess'); - spyOn(controller.$state, 'go'); + jest.spyOn(controller.vnApp, 'showSuccess'); + jest.spyOn(controller.$state, 'go'); $httpBackend.when('POST', 'Orders/new', {landed: 101, addressId: 101, agencyModeId: 101}).respond(200, 1); $httpBackend.expect('POST', 'Orders/new', {landed: 101, addressId: 101, agencyModeId: 101}); controller.createOrder(); diff --git a/modules/order/front/create/index.spec.js b/modules/order/front/create/index.spec.js index 6c1714004..80a8341ec 100644 --- a/modules/order/front/create/index.spec.js +++ b/modules/order/front/create/index.spec.js @@ -15,14 +15,14 @@ describe('Order', () => { describe('onSubmit()', () => { it(`should call createOrder()`, () => { - spyOn(controller.$.card, 'createOrder'); + jest.spyOn(controller.$.card, 'createOrder'); controller.onSubmit(); expect(controller.$.card.createOrder).toHaveBeenCalledWith(); }); it(`should call go()`, async() => { - spyOn(controller.$state, 'go'); + jest.spyOn(controller.$state, 'go'); await controller.onSubmit(); expect(controller.$state.go).toHaveBeenCalledWith('order.card.summary', {id: undefined}); diff --git a/modules/order/front/descriptor/index.spec.js b/modules/order/front/descriptor/index.spec.js index a0818ebe7..924ea4a97 100644 --- a/modules/order/front/descriptor/index.spec.js +++ b/modules/order/front/descriptor/index.spec.js @@ -16,8 +16,8 @@ describe('Order Component vnOrderDescriptor', () => { it(`should do nothing if the response isn't accept`, () => { let response = 'WAGH!'; - spyOn(controller.vnApp, 'showSuccess'); - spyOn(controller.$state, 'go'); + jest.spyOn(controller.vnApp, 'showSuccess'); + jest.spyOn(controller.$state, 'go'); controller.deleteOrder(response); expect(controller.vnApp.showSuccess).not.toHaveBeenCalledWith('Order deleted!'); @@ -27,8 +27,8 @@ describe('Order Component vnOrderDescriptor', () => { it(`should perform a DELETE query if the response was accept`, () => { let response = 'accept'; - spyOn(controller.vnApp, 'showSuccess'); - spyOn(controller.$state, 'go'); + jest.spyOn(controller.vnApp, 'showSuccess'); + jest.spyOn(controller.$state, 'go'); $httpBackend.when('DELETE', `Orders/${controller.order.id}`).respond(200); $httpBackend.expect('DELETE', `Orders/${controller.order.id}`); controller.deleteOrder(response); diff --git a/modules/order/front/summary/index.spec.js b/modules/order/front/summary/index.spec.js index ba412cc90..f693db35d 100644 --- a/modules/order/front/summary/index.spec.js +++ b/modules/order/front/summary/index.spec.js @@ -14,7 +14,7 @@ describe('Order', () => { })); describe('getSummary()', () => { - it('should perform a GET query and define summary property', () => { + it('should now perform a GET query and define the summary property', () => { let res = {id: 1, nickname: 'Batman'}; $httpBackend.when('GET', `Orders/1/summary`).respond(200, res); $httpBackend.expect('GET', `Orders/1/summary`); diff --git a/modules/order/front/volume/index.spec.js b/modules/order/front/volume/index.spec.js index ba597c6e7..c5fe0f2cf 100644 --- a/modules/order/front/volume/index.spec.js +++ b/modules/order/front/volume/index.spec.js @@ -39,7 +39,7 @@ describe('Order', () => { it('should set $scope.descriptor.itemFk, $scope.descriptor.parent and call $scope.descriptor.show()', () => { let event = {target: 1}; let itemFk = 1; - spyOn(controller.$scope.descriptor, 'show'); + jest.spyOn(controller.$scope.descriptor, 'show'); controller.showDescriptor(event, itemFk); expect(controller.$scope.descriptor.itemFk).toBe(1); @@ -50,7 +50,7 @@ describe('Order', () => { describe('onDescriptorLoad()', () => { it('should call $scope.popover.relocate()', () => { - spyOn(controller.$scope.popover, 'relocate'); + jest.spyOn(controller.$scope.popover, 'relocate'); controller.onDescriptorLoad(); expect(controller.$scope.popover.relocate).toHaveBeenCalledWith(); diff --git a/modules/route/front/descriptor-popover/index.spec.js b/modules/route/front/descriptor-popover/index.spec.js index be33d366d..e3277a9c1 100644 --- a/modules/route/front/descriptor-popover/index.spec.js +++ b/modules/route/front/descriptor-popover/index.spec.js @@ -22,7 +22,7 @@ describe('vnRouteDescriptorPopover', () => { it(`should do nothing if the received id isn't a new one`, () => { controller.route = 'I exist!'; controller._routeFk = 1; - spyOn(controller, 'getCard'); + jest.spyOn(controller, 'getCard'); controller.routeFk = 1; expect(controller.route).toEqual('I exist!'); @@ -33,7 +33,7 @@ describe('vnRouteDescriptorPopover', () => { it(`should set the received id, set the route null and then call getCard()`, () => { controller.route = `Please don't`; controller._routeFk = 1; - spyOn(controller, 'getCard'); + jest.spyOn(controller, 'getCard'); controller.routeFk = 999; expect(controller.route).toBeNull(); @@ -44,7 +44,7 @@ describe('vnRouteDescriptorPopover', () => { describe('route()', () => { it(`should save the client on the controller and then call relocate()`, () => { - spyOn(controller.$.popover, 'relocate'); + jest.spyOn(controller.$.popover, 'relocate'); let route = `i'm the route!`; controller.route = route; $timeout.flush(); @@ -56,7 +56,7 @@ describe('vnRouteDescriptorPopover', () => { describe('show()', () => { it(`should call the popover show() method`, () => { - spyOn(controller.$.popover, 'show'); + jest.spyOn(controller.$.popover, 'show'); controller.show(); expect(controller.$.popover.show).toHaveBeenCalledWith(); diff --git a/modules/route/front/tickets/index.spec.js b/modules/route/front/tickets/index.spec.js index 36e0b9687..d07aa9690 100644 --- a/modules/route/front/tickets/index.spec.js +++ b/modules/route/front/tickets/index.spec.js @@ -87,8 +87,8 @@ describe('Route', () => { describe('setPriority()', () => { it('should set a ticket priority', () => { controller.$.model = {refresh: () => {}}; - spyOn(controller.$.model, 'refresh'); - spyOn(controller.vnApp, 'showSuccess'); + jest.spyOn(controller.$.model, 'refresh'); + jest.spyOn(controller.vnApp, 'showSuccess'); const ticketId = 1; const priority = 999; @@ -119,7 +119,7 @@ describe('Route', () => { describe('goToBuscaman()', () => { it('should open buscaman with the given arguments', () => { - spyOn(window, 'open'); + jest.spyOn(window, 'open'); const expectedUrl = 'http://gps.buscalia.com/usuario/localizar.aspx?bmi=true&addr=46460 Av Espioca 100+to:n19 London my street'; controller.route = {vehicleFk: 1}; const url = `Routes/${controller.route.vehicleFk}/getDeliveryPoint`; @@ -147,7 +147,7 @@ describe('Route', () => { describe('showDeleteConfirm()', () => { it('should open a confirm dialog after setting the selected ticket into the controller', () => { controller.$.confirm = {show: () => {}}; - spyOn(controller.$.confirm, 'show'); + jest.spyOn(controller.$.confirm, 'show'); let ticketId = 1; controller.showDeleteConfirm(ticketId); @@ -159,8 +159,8 @@ describe('Route', () => { describe('removeTicketFromRoute()', () => { it('should perform a patch query then call showSuccess and updateVolume methods', () => { - spyOn(controller, 'updateVolume'); - spyOn(controller.vnApp, 'showSuccess'); + jest.spyOn(controller, 'updateVolume').mockReturnValue('ok!'); + jest.spyOn(controller.vnApp, 'showSuccess'); let ticketId = 1; controller.selectedTicket = ticketId; @@ -178,8 +178,8 @@ describe('Route', () => { controller.$.model = {refresh: () => {}}; controller.card = {reload: () => {}}; controller.$stateParamds = {id: 999}; - spyOn(controller.$.model, 'refresh'); - spyOn(controller.card, 'reload'); + jest.spyOn(controller.$.model, 'refresh'); + jest.spyOn(controller.card, 'reload'); let ticketId = 1; controller.selectedTicket = ticketId; @@ -197,8 +197,8 @@ describe('Route', () => { describe('guessPriority()', () => { it('should perform a GET query then call both refresh and showSuccess methods', () => { controller.$.model = {refresh: () => {}}; - spyOn(controller.$.model, 'refresh'); - spyOn(controller.vnApp, 'showSuccess'); + jest.spyOn(controller.$.model, 'refresh'); + jest.spyOn(controller.vnApp, 'showSuccess'); controller.$stateParams = {id: 99}; const url = `Routes/${controller.$stateParams.id}/guessPriority/`; @@ -214,9 +214,9 @@ describe('Route', () => { describe('showTicketDescriptor()', () => { it('should call the descriptor show function after setting the parent and the ticket id', () => { controller.$.ticketDescriptor = {show: () => {}}; - spyOn(controller.$.ticketDescriptor, 'show'); + jest.spyOn(controller.$.ticketDescriptor, 'show'); const event = {target: {}, preventDefault: () => {}}; - spyOn(event, 'preventDefault'); + jest.spyOn(event, 'preventDefault'); const ticketId = 999; controller.showTicketDescriptor(event, ticketId); @@ -229,9 +229,9 @@ describe('Route', () => { describe('showClientDescriptor()', () => { it('should call the descriptor show method after setting the parent and the client id', () => { controller.$.clientDescriptor = {show: () => {}}; - spyOn(controller.$.clientDescriptor, 'show'); + jest.spyOn(controller.$.clientDescriptor, 'show'); const event = {target: {}, preventDefault: () => {}}; - spyOn(event, 'preventDefault'); + jest.spyOn(event, 'preventDefault'); const clientId = 999; controller.showClientDescriptor(event, clientId); @@ -244,9 +244,9 @@ describe('Route', () => { describe('openPossibleTicketsDialog()', () => { it('should call both refresh and show methods in posible tickets model and dialog', () => { controller.$.possibleTicketsModel = {refresh: () => {}}; - spyOn(controller.$.possibleTicketsModel, 'refresh'); + jest.spyOn(controller.$.possibleTicketsModel, 'refresh'); controller.$.possibleTicketsDialog = {show: () => {}}; - spyOn(controller.$.possibleTicketsDialog, 'show'); + jest.spyOn(controller.$.possibleTicketsDialog, 'show'); controller.openPossibleTicketsDialog(); @@ -258,7 +258,7 @@ describe('Route', () => { describe('setTicketsRoute()', () => { it('should perform a POST query to add tickets to the route', done => { controller.$.possibleTicketsModel = {save: () => {}}; - spyOn(controller.$.possibleTicketsModel, 'save').and.returnValue(Promise.resolve()); + jest.spyOn(controller.$.possibleTicketsModel, 'save').mockReturnValue(Promise.resolve()); controller.$.model = {data: [ {id: 1, checked: false} ]}; diff --git a/modules/ticket/front/basic-data/step-one/index.spec.js b/modules/ticket/front/basic-data/step-one/index.spec.js index 690399131..86977a738 100644 --- a/modules/ticket/front/basic-data/step-one/index.spec.js +++ b/modules/ticket/front/basic-data/step-one/index.spec.js @@ -23,14 +23,14 @@ describe('Ticket', () => { describe('ticket() setter', () => { it('should set ticket property and call onChangeClient() method', () => { - spyOn(controller, 'onChangeClient'); + jest.spyOn(controller, 'onChangeClient'); controller.ticket = {id: 1, clientFk: 101}; expect(controller.onChangeClient).toHaveBeenCalledWith(101); }); it(`should not call onChangeClient() method as the ticket doesn't have an ID`, () => { - spyOn(controller, 'onChangeClient'); + jest.spyOn(controller, 'onChangeClient'); controller.ticket = {}; expect(controller.onChangeClient).not.toHaveBeenCalledWith(); @@ -47,7 +47,7 @@ describe('Ticket', () => { describe('clientId() setter', () => { it('should set clientId property and call onChangeClient() method ', () => { - spyOn(controller, 'onChangeClient'); + jest.spyOn(controller, 'onChangeClient'); controller.ticket = {id: 1, clientId: 101}; controller.clientId = 102; @@ -65,7 +65,7 @@ describe('Ticket', () => { describe('addressId() setter', () => { it('should set addressId property and call getShipped() method ', () => { - spyOn(controller, 'getShipped'); + jest.spyOn(controller, 'getShipped'); controller.ticket.addressFk = 99; controller.addressId = 100; const landed = new Date(); @@ -92,7 +92,7 @@ describe('Ticket', () => { describe('warehouseId() setter', () => { it('should set warehouseId property and call getShipped() method ', () => { - spyOn(controller, 'getShipped'); + jest.spyOn(controller, 'getShipped'); controller.ticket.warehouseId = 1; controller.warehouseId = 2; const landed = new Date(); @@ -120,7 +120,7 @@ describe('Ticket', () => { describe('shipped() setter', () => { it('should set shipped property and call getLanded() method ', () => { - spyOn(controller, 'getLanded'); + jest.spyOn(controller, 'getLanded'); const shipped = new Date(); const expectedResult = { shipped: shipped, @@ -145,7 +145,7 @@ describe('Ticket', () => { describe('landed() setter', () => { it('should set shipped property and call getShipped() method ', () => { - spyOn(controller, 'getShipped'); + jest.spyOn(controller, 'getShipped'); const landed = new Date(); const expectedResult = { landed: landed, @@ -170,7 +170,7 @@ describe('Ticket', () => { describe('agencyModeId() setter', () => { it('should set agencyModeId property and call getLanded() method', () => { - spyOn(controller, 'getLanded'); + jest.spyOn(controller, 'getLanded'); const shipped = new Date(); const agencyModeId = 8; const expectedResult = { @@ -186,7 +186,7 @@ describe('Ticket', () => { }); it('should do nothing if attempting to set the same agencyMode id', () => { - spyOn(controller, 'getShipped'); + jest.spyOn(controller, 'getShipped'); const landed = new Date(); const agencyModeId = 7; const expectedResult = { @@ -213,7 +213,7 @@ describe('Ticket', () => { describe('zoneId() setter', () => { it('should set zoneId property and call onChangeZone() method ', () => { const zoneId = 5; - spyOn(controller, 'onChangeZone'); + jest.spyOn(controller, 'onChangeZone'); controller.ticket = {id: 1}; controller.zoneId = 5; @@ -222,7 +222,7 @@ describe('Ticket', () => { it('should do nothing if attempting to set the same zone id', () => { const zoneId = 5; - spyOn(controller, 'onChangeZone'); + jest.spyOn(controller, 'onChangeZone'); controller.ticket = {id: 1, zoneFk: zoneId}; controller.zoneId = zoneId; diff --git a/modules/ticket/front/descriptor-popover/index.spec.js b/modules/ticket/front/descriptor-popover/index.spec.js index 2fd94f668..17682e5de 100644 --- a/modules/ticket/front/descriptor-popover/index.spec.js +++ b/modules/ticket/front/descriptor-popover/index.spec.js @@ -22,7 +22,7 @@ describe('ticket Component vnTicketDescriptorPopover', () => { it(`should not apply any changes if the received id is the same stored in _ticketFk`, () => { controller.ticket = 'I exist!'; controller._ticketFk = 1; - spyOn(controller, 'getCard'); + jest.spyOn(controller, 'getCard'); controller.ticketFk = 1; expect(controller.ticket).toEqual('I exist!'); @@ -33,7 +33,7 @@ describe('ticket Component vnTicketDescriptorPopover', () => { it(`should set the received id into _ticketFk, set the ticket to null and then call getCard()`, () => { controller.ticket = `Please don't`; controller._ticketFk = 1; - spyOn(controller, 'getCard'); + jest.spyOn(controller, 'getCard'); controller.ticketFk = 999; expect(controller.ticket).toBeNull(); @@ -44,7 +44,7 @@ describe('ticket Component vnTicketDescriptorPopover', () => { describe('ticket()', () => { it(`should save the ticket into _ticket and then call relocate()`, () => { - spyOn(controller.$.popover, 'relocate'); + jest.spyOn(controller.$.popover, 'relocate'); controller.ticket = `i'm the ticket!`; $timeout.flush(); @@ -55,7 +55,7 @@ describe('ticket Component vnTicketDescriptorPopover', () => { describe('show()', () => { it(`should call the show()`, () => { - spyOn(controller.$.popover, 'show'); + jest.spyOn(controller.$.popover, 'show'); controller.show(); expect(controller.$.popover.show).toHaveBeenCalledWith(); diff --git a/modules/ticket/front/descriptor/index.spec.js b/modules/ticket/front/descriptor/index.spec.js index eb554218e..21b4fc0eb 100644 --- a/modules/ticket/front/descriptor/index.spec.js +++ b/modules/ticket/front/descriptor/index.spec.js @@ -29,7 +29,7 @@ describe('Ticket Component vnTicketDescriptor', () => { describe('showAddTurnDialog()', () => { it('should call controller.$.addTurn.show()', () => { controller.$.addTurn = {show: () => {}}; - spyOn(controller.$.addTurn, 'show'); + jest.spyOn(controller.$.addTurn, 'show'); controller.showAddTurnDialog(); expect(controller.$.addTurn.show).toHaveBeenCalledWith(); @@ -39,7 +39,7 @@ describe('Ticket Component vnTicketDescriptor', () => { describe('addTurn()', () => { it('should make a query and call $.addTurn.hide() and vnApp.showSuccess()', () => { controller.$.addTurn = {hide: () => {}}; - spyOn(controller.$.addTurn, 'hide'); + jest.spyOn(controller.$.addTurn, 'hide'); $httpBackend.expectPATCH(`TicketWeeklies`).respond(); controller.addTurn(1); @@ -52,7 +52,7 @@ describe('Ticket Component vnTicketDescriptor', () => { describe('showDeleteTicketDialog()', () => { it('should call vnApp.showError() if the ticket isnt editable', () => { controller.ticket.tracking = {state: {alertLevel: 3}}; - spyOn(controller.vnApp, 'showError'); + jest.spyOn(controller.vnApp, 'showError'); controller.showDeleteTicketDialog(); expect(controller.vnApp.showError).toHaveBeenCalledWith('This ticket cant be deleted'); @@ -61,7 +61,7 @@ describe('Ticket Component vnTicketDescriptor', () => { it('should call deleteConfirmation.show() if the ticket is editable', () => { controller.ticket.tracking = {state: {alertLevel: 0}}; controller.$.deleteConfirmation = {show: () => {}}; - spyOn(controller.$.deleteConfirmation, 'show'); + jest.spyOn(controller.$.deleteConfirmation, 'show'); controller.showDeleteTicketDialog(); expect(controller.$.deleteConfirmation.show).toHaveBeenCalledWith(); @@ -70,8 +70,8 @@ describe('Ticket Component vnTicketDescriptor', () => { describe('deleteTicket()', () => { it('should make a query and call vnApp.showSuccess() if the response is accept', () => { - spyOn(controller.$state, 'go'); - spyOn(controller.vnApp, 'showSuccess'); + jest.spyOn(controller.$state, 'go').mockReturnValue('ok'); + jest.spyOn(controller.vnApp, 'showSuccess'); $httpBackend.expectPOST(`Tickets/2/setDeleted`).respond(); controller.deleteTicket('accept'); @@ -90,7 +90,7 @@ describe('Ticket Component vnTicketDescriptor', () => { }; const serializedParams = $httpParamSerializer(params); let expectedPath = `api/report/delivery-note?${serializedParams}`; - spyOn(window, 'open'); + jest.spyOn(window, 'open'); controller.showDeliveryNote(); expect(window.open).toHaveBeenCalledWith(expectedPath); @@ -99,7 +99,7 @@ describe('Ticket Component vnTicketDescriptor', () => { describe('sendDeliveryNote()', () => { it('should make a query and call vnApp.showMessage()', () => { - spyOn(controller.vnApp, 'showMessage'); + jest.spyOn(controller.vnApp, 'showMessage'); const params = { recipient: 'client@email', @@ -119,8 +119,8 @@ describe('Ticket Component vnTicketDescriptor', () => { describe('makeInvoice()', () => { it('should make a query and call $state.reload() method if the response is accept', () => { - spyOn(controller.$state, 'reload'); - spyOn(controller.vnApp, 'showSuccess'); + jest.spyOn(controller.$state, 'reload').mockReturnValue('ok!'); + jest.spyOn(controller.vnApp, 'showSuccess'); $httpBackend.when('POST', 'Tickets/2/makeInvoice').respond(); $httpBackend.expect('POST', 'Tickets/2/makeInvoice').respond(); @@ -134,7 +134,7 @@ describe('Ticket Component vnTicketDescriptor', () => { describe('regenerateInvoice()', () => { it('should make a query and show a success snackbar if the response is accept', () => { - spyOn(controller.vnApp, 'showSuccess'); + jest.spyOn(controller.vnApp, 'showSuccess'); $httpBackend.when('POST', 'InvoiceOuts/1/regenerate').respond(); $httpBackend.expect('POST', 'InvoiceOuts/1/regenerate').respond(); @@ -148,8 +148,8 @@ describe('Ticket Component vnTicketDescriptor', () => { describe('changeShipped()', () => { it('should make a query and change the shipped hour if the response is accept', () => { controller.ticket.id = 12; - spyOn(controller.vnApp, 'showSuccess'); - spyOn(controller, 'cardReload'); + jest.spyOn(controller.vnApp, 'showSuccess'); + jest.spyOn(controller, 'cardReload'); $httpBackend.when('POST', 'Tickets/12/updateEditableTicket').respond(); $httpBackend.expect('POST', 'Tickets/12/updateEditableTicket').respond(); @@ -185,7 +185,7 @@ describe('Ticket Component vnTicketDescriptor', () => { describe('canStowaway()', () => { it('should make a query and return if the ticket can be stowawayed', () => { controller.ticket.id = 16; - spyOn(controller, 'isTicketModule').and.callThrough(); + jest.spyOn(controller, 'isTicketModule'); $httpBackend.when('GET', 'Tickets/16/canHaveStowaway').respond(true); $httpBackend.expect('GET', 'Tickets/16/canHaveStowaway').respond(true); controller.canStowaway(); @@ -203,7 +203,7 @@ describe('Ticket Component vnTicketDescriptor', () => { {state: {name: 'client'}} ]; }; - spyOn(controller, 'isTicketModule').and.callThrough(); + jest.spyOn(controller, 'isTicketModule'); controller.canStowaway(); expect(controller.canShowStowaway).toBeUndefined(); @@ -213,7 +213,7 @@ describe('Ticket Component vnTicketDescriptor', () => { describe('recalculateComponents()', () => { it('should make a query and show a success snackbar', () => { - spyOn(controller.vnApp, 'showSuccess'); + jest.spyOn(controller.vnApp, 'showSuccess'); $httpBackend.when('POST', 'Tickets/2/recalculateComponents').respond(); $httpBackend.expect('POST', 'Tickets/2/recalculateComponents').respond(); diff --git a/modules/ticket/front/dms/create/index.spec.js b/modules/ticket/front/dms/create/index.spec.js index c8b63358f..f0d7ad7c5 100644 --- a/modules/ticket/front/dms/create/index.spec.js +++ b/modules/ticket/front/dms/create/index.spec.js @@ -24,8 +24,8 @@ describe('Ticket', () => { describe('client() setter', () => { it('should set the ticket data and then call setDefaultParams() and getAllowedContentTypes()', () => { - spyOn(controller, 'setDefaultParams'); - spyOn(controller, 'getAllowedContentTypes'); + jest.spyOn(controller, 'setDefaultParams'); + jest.spyOn(controller, 'getAllowedContentTypes'); controller.ticket = { id: 15, name: 'Bruce wayne' diff --git a/modules/ticket/front/dms/edit/index.spec.js b/modules/ticket/front/dms/edit/index.spec.js index 493deae77..757ca24ef 100644 --- a/modules/ticket/front/dms/edit/index.spec.js +++ b/modules/ticket/front/dms/edit/index.spec.js @@ -19,8 +19,8 @@ describe('Ticket', () => { describe('ticket() setter', () => { it('should set the ticket data and then call setDefaultParams() and getAllowedContentTypes()', () => { - spyOn(controller, 'setDefaultParams'); - spyOn(controller, 'getAllowedContentTypes'); + jest.spyOn(controller, 'setDefaultParams'); + jest.spyOn(controller, 'getAllowedContentTypes'); controller._ticket = undefined; controller.ticket = { id: 15 diff --git a/modules/ticket/front/dms/index/index.spec.js b/modules/ticket/front/dms/index/index.spec.js index ab28d750d..8916a5c63 100644 --- a/modules/ticket/front/dms/index/index.spec.js +++ b/modules/ticket/front/dms/index/index.spec.js @@ -22,8 +22,8 @@ describe('Ticket', () => { it('should make an HTTP Post query', () => { const dmsId = 1; const dmsIndex = 0; - spyOn(controller.vnApp, 'showSuccess'); - spyOn(controller.$.model, 'remove'); + jest.spyOn(controller.vnApp, 'showSuccess'); + jest.spyOn(controller.$.model, 'remove'); controller.ticketDms = [{dmsFk: 1}]; controller.dmsIndex = dmsIndex; diff --git a/modules/ticket/front/expedition/index.spec.js b/modules/ticket/front/expedition/index.spec.js index 843c4fff3..2985f698c 100644 --- a/modules/ticket/front/expedition/index.spec.js +++ b/modules/ticket/front/expedition/index.spec.js @@ -21,7 +21,7 @@ describe('Ticket', () => { describe('returnDialog()', () => { it('should perform a DELETE query', () => { - spyOn($scope.model, 'refresh'); + jest.spyOn($scope.model, 'refresh'); let response = 'accept'; controller.expeditionId = 1; diff --git a/modules/ticket/front/index/index.spec.js b/modules/ticket/front/index/index.spec.js index dd1e3009e..987accd02 100644 --- a/modules/ticket/front/index/index.spec.js +++ b/modules/ticket/front/index/index.spec.js @@ -69,7 +69,7 @@ describe('Component vnTicketIndex', () => { describe('preview()', () => { it('should show the dialog summary', () => { controller.$.summary = {show: () => {}}; - spyOn(controller.$.summary, 'show'); + jest.spyOn(controller.$.summary, 'show'); let event = new MouseEvent('click', { view: $window, diff --git a/modules/ticket/front/sale/index.js b/modules/ticket/front/sale/index.js index 1ecb6fe41..5159f7e82 100644 --- a/modules/ticket/front/sale/index.js +++ b/modules/ticket/front/sale/index.js @@ -206,7 +206,7 @@ class Controller { onStateChange(value) { let params = {ticketFk: this.$state.params.id, stateFk: value}; - this.$http.post(`TicketTrackings/changeState`, params).then(() => { + this.$http.post('TicketTrackings/changeState', params).then(() => { this.card.reload(); this.vnApp.showSuccess(this.$translate.instant('Data saved!')); }).finally(() => { diff --git a/modules/ticket/front/sale/specs/editDiscount.spec.js b/modules/ticket/front/sale/specs/editDiscount.spec.js index 97fe4771d..8937d25c6 100644 --- a/modules/ticket/front/sale/specs/editDiscount.spec.js +++ b/modules/ticket/front/sale/specs/editDiscount.spec.js @@ -26,7 +26,7 @@ describe('Ticket', () => { describe('edit() setter', () => { it('should set _edit value and call setNewDiscount', () => { - spyOn(controller, 'setNewDiscount'); + jest.spyOn(controller, 'setNewDiscount'); controller.edit = {id: 1}; expect(controller.edit).toEqual({id: 1}); @@ -36,7 +36,7 @@ describe('Ticket', () => { describe('bulk() setter', () => { it('should set _bulk value and call setNewDiscount', () => { - spyOn(controller, 'setNewDiscount'); + jest.spyOn(controller, 'setNewDiscount'); controller.bulk = true; expect(controller.bulk).toEqual(true); @@ -68,7 +68,7 @@ describe('Ticket', () => { controller.bulk = false; controller.newDiscount = 15; controller.edit = [{discount: 15}]; - spyOn(controller.vnApp, 'showError'); + jest.spyOn(controller.vnApp, 'showError'); controller.updateDiscount(); expect(controller.vnApp.showError).toHaveBeenCalledWith('There are no changes to save'); diff --git a/modules/ticket/front/sale/specs/index.spec.js b/modules/ticket/front/sale/specs/index.spec.js index a23c6f204..ed5b5c733 100644 --- a/modules/ticket/front/sale/specs/index.spec.js +++ b/modules/ticket/front/sale/specs/index.spec.js @@ -61,7 +61,7 @@ describe('Ticket', () => { describe('createClaim()', () => { it('should perform a query and call windows open', () => { - spyOn(controller.$state, 'go'); + jest.spyOn(controller.$state, 'go'); const claim = {id: 1}; const sales = [{id: 1}, {id: 2}]; @@ -110,7 +110,7 @@ describe('Ticket', () => { let filter = {where: {code: 'OK'}, fields: ['id']}; filter = encodeURIComponent(JSON.stringify(filter)); let res = [{id: 3}]; - spyOn(controller, 'onStateChange'); + jest.spyOn(controller, 'onStateChange').mockReturnValue('ok!'); $httpBackend.whenGET(`States?filter=${filter}`).respond(res); $httpBackend.expectGET(`Tickets/1/subtotal`).respond(200, 227.5); @@ -151,7 +151,7 @@ describe('Ticket', () => { describe('unmarkAsReserved()', () => { it('should call setReserved with false', () => { - spyOn(controller, 'setReserved'); + jest.spyOn(controller, 'setReserved'); controller.unmarkAsReserved(false); @@ -161,7 +161,7 @@ describe('Ticket', () => { describe('markAsReserved()', () => { it('should call setReserved with true', () => { - spyOn(controller, 'setReserved'); + jest.spyOn(controller, 'setReserved'); controller.markAsReserved(true); @@ -190,7 +190,7 @@ describe('Ticket', () => { describe('showSMSDialog()', () => { it('should open an SMS dialog with specified data', () => { - spyOn(controller.$scope.sms, 'open'); + jest.spyOn(controller.$scope.sms, 'open'); controller.sales[0].checked = true; controller.showSMSDialog(); @@ -203,7 +203,7 @@ describe('Ticket', () => { describe('updateQuantity()', () => { it('should make a POST query saving sale quantity', () => { - spyOn(controller.$scope.watcher, 'updateOriginalData'); + jest.spyOn(controller.$scope.watcher, 'updateOriginalData'); const data = {quantity: 10}; const sale = sales[0]; sale.quantity = 10; @@ -222,7 +222,7 @@ describe('Ticket', () => { describe('updateConcept()', () => { it('should make a POST query saving sale concept', () => { - spyOn(controller.$scope.watcher, 'updateOriginalData'); + jest.spyOn(controller.$scope.watcher, 'updateOriginalData'); const data = {newConcept: 'My new weapon'}; const sale = sales[0]; sale.concept = 'My new weapon'; @@ -241,7 +241,7 @@ describe('Ticket', () => { describe('addSale()', () => { it('should make a POST query adding a new sale', () => { - spyOn(controller.$scope.watcher, 'updateOriginalData'); + jest.spyOn(controller.$scope.watcher, 'updateOriginalData'); const newSale = {itemFk: 4, quantity: 10}; const params = {itemId: 4, quantity: 10}; @@ -271,7 +271,7 @@ describe('Ticket', () => { describe('transferSales()', () => { it('should transfer sales to a ticket', () => { - spyOn(controller, 'goToTicket'); + jest.spyOn(controller, 'goToTicket'); controller.transfer = { sales: [{id: 1, itemFk: 1}, {id: 2, itemFk: 4}] }; diff --git a/modules/ticket/front/sms/index.spec.js b/modules/ticket/front/sms/index.spec.js index 96c10edd1..cd397b9fa 100644 --- a/modules/ticket/front/sms/index.spec.js +++ b/modules/ticket/front/sms/index.spec.js @@ -26,7 +26,7 @@ describe('Ticket', () => { let params = {destinationFk: 101, destination: 111111111, message: 'My SMS'}; controller.sms = {destinationFk: 101, destination: 111111111, message: 'My SMS'}; - spyOn(controller.vnApp, 'showMessage'); + jest.spyOn(controller.vnApp, 'showMessage'); $httpBackend.expect('POST', `Tickets/11/sendSms`, params).respond(200, params); controller.onResponse('accept'); @@ -38,7 +38,7 @@ describe('Ticket', () => { it('should call onResponse without the destination and show an error snackbar', () => { controller.sms = {destinationFk: 101, message: 'My SMS'}; - spyOn(controller.vnApp, 'showError'); + jest.spyOn(controller.vnApp, 'showError'); controller.onResponse('accept'); @@ -48,7 +48,7 @@ describe('Ticket', () => { it('should call onResponse without the message and show an error snackbar', () => { controller.sms = {destinationFk: 101, destination: 222222222}; - spyOn(controller.vnApp, 'showError'); + jest.spyOn(controller.vnApp, 'showError'); controller.onResponse('accept'); diff --git a/modules/ticket/front/summary/index.spec.js b/modules/ticket/front/summary/index.spec.js index 86b154b72..08557e36e 100644 --- a/modules/ticket/front/summary/index.spec.js +++ b/modules/ticket/front/summary/index.spec.js @@ -14,7 +14,7 @@ describe('Ticket', () => { })); describe('ticket()', () => { - it('should perform a GET query and define summary property', () => { + it('should perform a GET query and define the summary property', () => { let res = {id: 1, nickname: 'Batman'}; $httpBackend.when('GET', `Tickets/1/summary`).respond(200, res); $httpBackend.expect('GET', `Tickets/1/summary`); diff --git a/modules/ticket/front/tracking/edit/index.spec.js b/modules/ticket/front/tracking/edit/index.spec.js index 979be07be..313a25b73 100644 --- a/modules/ticket/front/tracking/edit/index.spec.js +++ b/modules/ticket/front/tracking/edit/index.spec.js @@ -55,10 +55,10 @@ describe('Ticket', () => { describe('onSubmit()', () => { it('should POST the data, call updateOriginalData, reload, showSuccess and go functions', () => { controller.params = {stateFk: 22, workerFk: 101}; - spyOn(controller.card, 'reload'); - spyOn(controller.$.watcher, 'updateOriginalData'); - spyOn(controller.vnApp, 'showSuccess'); - spyOn(controller.$state, 'go'); + jest.spyOn(controller.card, 'reload'); + jest.spyOn(controller.$.watcher, 'updateOriginalData'); + jest.spyOn(controller.vnApp, 'showSuccess'); + jest.spyOn(controller.$state, 'go'); $httpBackend.expectPOST(`TicketTrackings/changeState`, controller.params).respond({}); controller.onSubmit(); diff --git a/modules/ticket/front/volume/index.spec.js b/modules/ticket/front/volume/index.spec.js index 7f40c53d1..6c2a808eb 100644 --- a/modules/ticket/front/volume/index.spec.js +++ b/modules/ticket/front/volume/index.spec.js @@ -24,7 +24,7 @@ describe('ticket', () => { describe('sales() setter', () => { it('should set sales property on controller an then call applyVolumes() method', () => { - spyOn(controller, 'applyVolumes'); + jest.spyOn(controller, 'applyVolumes'); controller.sales = [{id: 1}]; @@ -34,7 +34,7 @@ describe('ticket', () => { describe('volumes() setter', () => { it('should set volumes property on controller an then call applyVolumes() method', () => { - spyOn(controller, 'applyVolumes'); + jest.spyOn(controller, 'applyVolumes'); controller.volumes = [{id: 1}]; diff --git a/modules/travel/front/basic-data/index.spec.js b/modules/travel/front/basic-data/index.spec.js index ed5c287b1..ed874d7e8 100644 --- a/modules/travel/front/basic-data/index.spec.js +++ b/modules/travel/front/basic-data/index.spec.js @@ -16,8 +16,8 @@ describe('Travel Component vnTravelBasicData', () => { describe('onSubmit()', () => { it('should call the card reload method after the watcher submits', done => { - spyOn(controller.card, 'reload'); - spyOn(controller.$.watcher, 'submit').and.returnValue(Promise.resolve()); + jest.spyOn(controller.card, 'reload'); + jest.spyOn(controller.$.watcher, 'submit').mockReturnValue(Promise.resolve()); controller.onSubmit().then(() => { expect(controller.card.reload).toHaveBeenCalledWith(); diff --git a/modules/travel/front/create/index.spec.js b/modules/travel/front/create/index.spec.js index 88152120e..63f0eda42 100644 --- a/modules/travel/front/create/index.spec.js +++ b/modules/travel/front/create/index.spec.js @@ -19,7 +19,7 @@ describe('Travel Component vnTravelCreate', () => { describe('onSubmit()', () => { it(`should call submit() on the watcher then expect a callback`, () => { - spyOn($state, 'go'); + jest.spyOn($state, 'go'); controller.onSubmit(); diff --git a/modules/travel/front/descriptor-popover/index.spec.js b/modules/travel/front/descriptor-popover/index.spec.js index 12ad364bf..0403c902a 100644 --- a/modules/travel/front/descriptor-popover/index.spec.js +++ b/modules/travel/front/descriptor-popover/index.spec.js @@ -22,7 +22,7 @@ describe('travel Component vnTravelDescriptorPopover', () => { it(`should not apply any changes if the received id is the same stored in _travelId`, () => { controller.travel = 'I exist!'; controller._travelId = 1; - spyOn(controller, 'loadData'); + jest.spyOn(controller, 'loadData'); controller.travelId = 1; expect(controller.travel).toEqual('I exist!'); @@ -33,7 +33,7 @@ describe('travel Component vnTravelDescriptorPopover', () => { it(`should set the received id into _travelId, set the travel to null and then call loadData()`, () => { controller.travel = `Please don't`; controller._travelId = 1; - spyOn(controller, 'loadData'); + jest.spyOn(controller, 'loadData'); controller.travelId = 999; expect(controller.travel).toBeNull(); @@ -44,7 +44,7 @@ describe('travel Component vnTravelDescriptorPopover', () => { describe('show()', () => { it(`should call the show()`, () => { - spyOn(controller.$.popover, 'show'); + jest.spyOn(controller.$.popover, 'show'); controller.show(); expect(controller.$.popover.show).toHaveBeenCalledWith(); diff --git a/modules/travel/front/summary/index.spec.js b/modules/travel/front/summary/index.spec.js index 593d2cfcc..202c66637 100644 --- a/modules/travel/front/summary/index.spec.js +++ b/modules/travel/front/summary/index.spec.js @@ -21,9 +21,9 @@ describe('component vnTravelSummary', () => { describe('travel setter/getter', () => { it('should return the travel and then call both getTravel() and getEntries()', () => { - spyOn(controller, 'getTravel'); - spyOn(controller, 'getEntries'); - spyOn(controller, 'getThermographs'); + jest.spyOn(controller, 'getTravel'); + jest.spyOn(controller, 'getEntries'); + jest.spyOn(controller, 'getThermographs'); controller.travel = {id: 99}; diff --git a/modules/travel/front/thermograph/create/index.spec.js b/modules/travel/front/thermograph/create/index.spec.js index bf5b8bec5..625f5bb20 100644 --- a/modules/travel/front/thermograph/create/index.spec.js +++ b/modules/travel/front/thermograph/create/index.spec.js @@ -23,8 +23,8 @@ describe('Ticket', () => { describe('travel() setter', () => { it('should set the travel data and then call setDefaultParams() and getAllowedContentTypes()', () => { - spyOn(controller, 'setDefaultParams'); - spyOn(controller, 'getAllowedContentTypes'); + jest.spyOn(controller, 'setDefaultParams'); + jest.spyOn(controller, 'getAllowedContentTypes'); controller.travel = { id: travelId }; diff --git a/modules/worker/front/descriptor-popover/index.spec.js b/modules/worker/front/descriptor-popover/index.spec.js index 14fe07ee1..dc524bc2d 100644 --- a/modules/worker/front/descriptor-popover/index.spec.js +++ b/modules/worker/front/descriptor-popover/index.spec.js @@ -22,7 +22,7 @@ describe('worker Component vnWorkerDescriptorPopover', () => { it(`should not apply any changes if the received id is the same stored in _workerFk`, () => { controller.worker = 'I exist!'; controller._workerFk = 1; - spyOn(controller, 'loadData'); + jest.spyOn(controller, 'loadData'); controller.workerFk = 1; expect(controller.worker).toEqual('I exist!'); @@ -33,7 +33,7 @@ describe('worker Component vnWorkerDescriptorPopover', () => { it(`should set the received id into _workerFk, set the worker to null and then call loadData()`, () => { controller.worker = `Please don't`; controller._workerFk = 1; - spyOn(controller, 'loadData'); + jest.spyOn(controller, 'loadData'); controller.workerFk = 999; expect(controller.worker).toBeNull(); @@ -44,7 +44,7 @@ describe('worker Component vnWorkerDescriptorPopover', () => { describe('show()', () => { it(`should call the show()`, () => { - spyOn(controller.$.popover, 'show'); + jest.spyOn(controller.$.popover, 'show'); controller.show(); expect(controller.$.popover.show).toHaveBeenCalledWith(); diff --git a/modules/worker/front/dms/create/index.spec.js b/modules/worker/front/dms/create/index.spec.js index 41fe0e0ca..6202032af 100644 --- a/modules/worker/front/dms/create/index.spec.js +++ b/modules/worker/front/dms/create/index.spec.js @@ -21,8 +21,8 @@ describe('Client', () => { describe('worker() setter', () => { it('should set the worker data and then call setDefaultParams() and getAllowedContentTypes()', () => { - spyOn(controller, 'setDefaultParams'); - spyOn(controller, 'getAllowedContentTypes'); + jest.spyOn(controller, 'setDefaultParams'); + jest.spyOn(controller, 'getAllowedContentTypes'); controller.worker = { id: 15, name: 'Bruce wayne' diff --git a/modules/worker/front/dms/edit/index.spec.js b/modules/worker/front/dms/edit/index.spec.js index b883d4472..7dfad9643 100644 --- a/modules/worker/front/dms/edit/index.spec.js +++ b/modules/worker/front/dms/edit/index.spec.js @@ -20,8 +20,8 @@ describe('Worker', () => { describe('worker() setter', () => { it('should set the worker data and then call setDefaultParams() and getAllowedContentTypes()', () => { - spyOn(controller, 'setDefaultParams'); - spyOn(controller, 'getAllowedContentTypes'); + jest.spyOn(controller, 'setDefaultParams'); + jest.spyOn(controller, 'getAllowedContentTypes'); controller._worker = undefined; controller.worker = { id: 106 diff --git a/modules/worker/front/dms/index/index.spec.js b/modules/worker/front/dms/index/index.spec.js index 6220d051c..a354b74e9 100644 --- a/modules/worker/front/dms/index/index.spec.js +++ b/modules/worker/front/dms/index/index.spec.js @@ -24,8 +24,8 @@ describe('Worker', () => { it('should make an HTTP Post query', () => { const dmsId = 4; const dmsIndex = 0; - spyOn(controller.vnApp, 'showSuccess'); - spyOn(controller.$.model, 'remove'); + jest.spyOn(controller.vnApp, 'showSuccess'); + jest.spyOn(controller.$.model, 'remove'); controller.workerDms = [{dmsFk: 4}]; controller.dmsIndex = dmsIndex; diff --git a/modules/worker/front/time-control/index.spec.js b/modules/worker/front/time-control/index.spec.js index abfe95580..faa234c4f 100644 --- a/modules/worker/front/time-control/index.spec.js +++ b/modules/worker/front/time-control/index.spec.js @@ -20,7 +20,7 @@ describe('Component vnWorkerTimeControl', () => { describe('date() setter', () => { it(`should set the weekDays, the date in the controller and call fetchHours`, () => { let today = new Date(); - spyOn(controller, 'fetchHours'); + jest.spyOn(controller, 'fetchHours').mockReturnValue('ok!'); controller.date = today; @@ -35,7 +35,7 @@ describe('Component vnWorkerTimeControl', () => { describe('hours() setter', () => { it(`should set hours data at it's corresponding week day`, () => { let today = new Date(); - spyOn(controller, 'fetchHours'); + jest.spyOn(controller, 'fetchHours').mockReturnValue('ok!'); controller.date = today; @@ -64,9 +64,9 @@ describe('Component vnWorkerTimeControl', () => { }); describe('getWorkedHours() ', () => { - it(`should `, () => { + it('should set the weekdays expected and worked hours plus the total worked hours', () => { let today = new Date(); - spyOn(controller, 'fetchHours'); + jest.spyOn(controller, 'fetchHours').mockReturnValue('ok!'); controller.date = today; diff --git a/modules/zone/front/create/index.spec.js b/modules/zone/front/create/index.spec.js index 5041e5095..472ac2aa1 100644 --- a/modules/zone/front/create/index.spec.js +++ b/modules/zone/front/create/index.spec.js @@ -24,7 +24,7 @@ describe('Agency Component vnZoneCreate', () => { describe('onSubmit()', () => { it(`should call submit() on the watcher then expect a callback`, () => { - spyOn($state, 'go'); + jest.spyOn($state, 'go'); controller.zone = { name: 'Zone One' diff --git a/modules/zone/front/summary/index.spec.js b/modules/zone/front/summary/index.spec.js index 03faf4cfd..9025af766 100644 --- a/modules/zone/front/summary/index.spec.js +++ b/modules/zone/front/summary/index.spec.js @@ -19,8 +19,8 @@ describe('component vnZoneSummary', () => { describe('zone setter', () => { it('should set the zone and then call both getSummary() and getWarehouses()', () => { - spyOn(controller, 'getSummary'); - spyOn(controller, 'getWarehouses'); + jest.spyOn(controller, 'getSummary'); + jest.spyOn(controller, 'getWarehouses'); controller.zone = {id: 1}; From d66c53dbf2e2cc23ef7edee3a5fb25d5ab2ad8d8 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 26 Feb 2020 14:30:30 +0100 Subject: [PATCH 09/31] 2127 - Disable preview on sepa core sample --- db/changes/10161-postValentineDay/00-sample.sql | 6 ++++++ modules/client/back/models/sample.json | 5 ++++- modules/client/front/sample/create/index.html | 9 ++++++--- modules/client/front/sample/create/index.js | 12 ++++++------ 4 files changed, 22 insertions(+), 10 deletions(-) create mode 100644 db/changes/10161-postValentineDay/00-sample.sql diff --git a/db/changes/10161-postValentineDay/00-sample.sql b/db/changes/10161-postValentineDay/00-sample.sql new file mode 100644 index 000000000..d34835888 --- /dev/null +++ b/db/changes/10161-postValentineDay/00-sample.sql @@ -0,0 +1,6 @@ +ALTER TABLE `vn`.`sample` +ADD COLUMN `hasPreview` TINYINT(1) UNSIGNED NOT NULL DEFAULT '1' AFTER `hasCompany`, +CHANGE COLUMN `isVisible` `isVisible` TINYINT(1) UNSIGNED NOT NULL DEFAULT '1' , +CHANGE COLUMN `hasCompany` `hasCompany` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0' ; + +UPDATE `vn`.`sample` SET `hasPreview` = '0' WHERE (`id` = '14'); diff --git a/modules/client/back/models/sample.json b/modules/client/back/models/sample.json index 8993250f3..725bfb9c7 100644 --- a/modules/client/back/models/sample.json +++ b/modules/client/back/models/sample.json @@ -22,7 +22,10 @@ "type": "Boolean" }, "hasCompany": { - "type": "Number" + "type": "Boolean" + }, + "hasPreview": { + "type": "Boolean" } }, "scopes": { diff --git a/modules/client/front/sample/create/index.html b/modules/client/front/sample/create/index.html index cd3412868..22f95eb20 100644 --- a/modules/client/front/sample/create/index.html +++ b/modules/client/front/sample/create/index.html @@ -23,7 +23,7 @@ - + + diff --git a/modules/client/front/sample/create/index.js b/modules/client/front/sample/create/index.js index e3504785d..f478243c7 100644 --- a/modules/client/front/sample/create/index.js +++ b/modules/client/front/sample/create/index.js @@ -26,13 +26,13 @@ class Controller extends Component { } get companyId() { - if (!this.clientSample.companyId) - this.clientSample.companyId = this.vnConfig.companyFk; - return this.clientSample.companyId; + if (!this.clientSample.companyFk) + this.clientSample.companyFk = this.vnConfig.companyFk; + return this.clientSample.companyFk; } set companyId(value) { - this.clientSample.companyId = value; + this.clientSample.companyFk = value; } onSubmit() { @@ -74,11 +74,11 @@ class Controller extends Component { if (!sampleType) return this.vnApp.showError(this.$translate.instant('Choose a sample')); - if (sampleType.hasCompany && !this.clientSample.companyId) + if (sampleType.hasCompany && !this.clientSample.companyFk) return this.vnApp.showError(this.$translate.instant('Choose a company')); if (sampleType.hasCompany) - params.companyId = this.clientSample.companyId; + params.companyId = this.clientSample.companyFk; if (isPreview) params.isPreview = true; From 1d326a52c8e010eaa7aa1d8d503e43488bdfa585 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 26 Feb 2020 14:45:47 +0100 Subject: [PATCH 10/31] updated unit tests --- .../client/front/sample/create/index.spec.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/modules/client/front/sample/create/index.spec.js b/modules/client/front/sample/create/index.spec.js index da9a557f1..d3817a439 100644 --- a/modules/client/front/sample/create/index.spec.js +++ b/modules/client/front/sample/create/index.spec.js @@ -107,7 +107,7 @@ describe('Client', () => { expect(controller.$http.get).not.toHaveBeenCalled(); }); - it(`should perform an HTTP query without passing companyId param`, () => { + it(`should perform an HTTP query without passing companyFk param`, () => { controller.$.sampleType.selection = { hasCompany: false, code: 'MyReport' @@ -116,25 +116,34 @@ describe('Client', () => { clientId: 101, recipient: 'client@email.com' }; + const expectedParams = { + clientId: 101, + recipient: 'client@email.com' + }; + const serializedParams = $httpParamSerializer(expectedParams); - const serializedParams = $httpParamSerializer(controller.clientSample); $httpBackend.expect('GET', `email/MyReport?${serializedParams}`).respond(true); controller.send(false, () => {}); $httpBackend.flush(); }); - it(`should perform an HTTP query passing companyId param`, () => { + it(`should perform an HTTP query passing companyFk param`, () => { controller.$.sampleType.selection = { hasCompany: true, code: 'MyReport' }; controller.clientSample = { + clientId: 101, + recipient: 'client@email.com', + companyFk: 442 + }; + const expectedParams = { clientId: 101, recipient: 'client@email.com', companyId: 442 }; + const serializedParams = $httpParamSerializer(expectedParams); - const serializedParams = $httpParamSerializer(controller.clientSample); $httpBackend.expect('GET', `email/MyReport?${serializedParams}`).respond(true); controller.send(false, () => {}); $httpBackend.flush(); From 0fd012930ecf0879634e8beccdd0fec573170c49 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Wed, 26 Feb 2020 15:02:47 +0100 Subject: [PATCH 11/31] #2131 jest.spyOn --- modules/claim/front/descriptor/index.spec.js | 2 +- modules/client/front/balance/index/index.spec.js | 2 +- modules/entry/front/descriptor/index.spec.js | 2 +- modules/route/front/tickets/index.spec.js | 2 +- modules/ticket/front/descriptor/index.spec.js | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/claim/front/descriptor/index.spec.js b/modules/claim/front/descriptor/index.spec.js index 53fa289e0..a64d5ecc1 100644 --- a/modules/claim/front/descriptor/index.spec.js +++ b/modules/claim/front/descriptor/index.spec.js @@ -22,7 +22,7 @@ describe('Item Component vnClaimDescriptor', () => { }; const serializedParams = $httpParamSerializer(params); let expectedPath = `api/report/claim-pickup-order?${serializedParams}`; - jest.spyOn(window, 'open'); + jest.spyOn(window, 'open').mockReturnThis(); controller.showPickupOrder(); expect(window.open).toHaveBeenCalledWith(expectedPath); diff --git a/modules/client/front/balance/index/index.spec.js b/modules/client/front/balance/index/index.spec.js index 769164def..265c3176b 100644 --- a/modules/client/front/balance/index/index.spec.js +++ b/modules/client/front/balance/index/index.spec.js @@ -31,7 +31,7 @@ describe('Client', () => { it('should apply the filters on he models and get the client balance', () => { controller._companyId = 442; controller.$stateParams.id = 101; - jest.spyOn(controller, 'getBalances'); + jest.spyOn(controller, 'getBalances').mockReturnThis(); jest.spyOn(controller.$.model, 'applyFilter').mockReturnValue(Promise.resolve()); jest.spyOn(controller.$.riskModel, 'applyFilter').mockReturnValue(Promise.resolve()); diff --git a/modules/entry/front/descriptor/index.spec.js b/modules/entry/front/descriptor/index.spec.js index 69472eae1..f73604d51 100644 --- a/modules/entry/front/descriptor/index.spec.js +++ b/modules/entry/front/descriptor/index.spec.js @@ -26,7 +26,7 @@ describe('Entry Component vnEntryDescriptor', () => { }; const serializedParams = $httpParamSerializer(params); let expectedPath = `api/report/entry-order?${serializedParams}`; - jest.spyOn(window, 'open'); + jest.spyOn(window, 'open').mockReturnThis(); controller.showEntryReport(); expect(window.open).toHaveBeenCalledWith(expectedPath); diff --git a/modules/route/front/tickets/index.spec.js b/modules/route/front/tickets/index.spec.js index d07aa9690..e9278d031 100644 --- a/modules/route/front/tickets/index.spec.js +++ b/modules/route/front/tickets/index.spec.js @@ -119,7 +119,7 @@ describe('Route', () => { describe('goToBuscaman()', () => { it('should open buscaman with the given arguments', () => { - jest.spyOn(window, 'open'); + jest.spyOn(window, 'open').mockReturnThis(); const expectedUrl = 'http://gps.buscalia.com/usuario/localizar.aspx?bmi=true&addr=46460 Av Espioca 100+to:n19 London my street'; controller.route = {vehicleFk: 1}; const url = `Routes/${controller.route.vehicleFk}/getDeliveryPoint`; diff --git a/modules/ticket/front/descriptor/index.spec.js b/modules/ticket/front/descriptor/index.spec.js index 21b4fc0eb..645a9fcf1 100644 --- a/modules/ticket/front/descriptor/index.spec.js +++ b/modules/ticket/front/descriptor/index.spec.js @@ -90,7 +90,7 @@ describe('Ticket Component vnTicketDescriptor', () => { }; const serializedParams = $httpParamSerializer(params); let expectedPath = `api/report/delivery-note?${serializedParams}`; - jest.spyOn(window, 'open'); + jest.spyOn(window, 'open').mockReturnThis(); controller.showDeliveryNote(); expect(window.open).toHaveBeenCalledWith(expectedPath); From 83943cd66f446c7039818e4760f76c09042c7fa4 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Thu, 27 Feb 2020 07:17:09 +0100 Subject: [PATCH 12/31] 2053 e2e ticket request --- e2e/helpers/selectors.js | 8 ++-- e2e/paths/05-ticket/10_request.spec.js | 54 +++++++++++++++++++------- 2 files changed, 44 insertions(+), 18 deletions(-) diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 563b8d89a..7e3e726e4 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -511,14 +511,16 @@ export default { }, ticketRequests: { addRequestButton: 'vn-ticket-request-index > a > vn-float-button > button', - request: 'vn-ticket-request-index vn-table vn-tr', descriptionInput: 'vn-ticket-request-create [ng-model="$ctrl.ticketRequest.description"]', atender: 'vn-ticket-request-create vn-autocomplete[ng-model="$ctrl.ticketRequest.attenderFk"]', quantity: 'vn-ticket-request-create vn-input-number[ng-model="$ctrl.ticketRequest.quantity"]', price: 'vn-ticket-request-create vn-input-number[ng-model="$ctrl.ticketRequest.price"]', - firstRemoveRequestButton: 'vn-ticket-request-index vn-icon[icon="delete"]:nth-child(1)', + firstRequestQuantity: 'vn-ticket-request-index vn-table vn-tr:nth-child(1) > vn-td:nth-child(6) vn-input-number', + secondRequestQuantity: 'vn-ticket-request-index vn-table vn-tr:nth-child(2) > vn-td:nth-child(6) vn-input-number', + thirdDescription: 'vn-ticket-request-index vn-table vn-tr:nth-child(3) > vn-td:nth-child(2) vn-textfield', + thirdRemoveRequestButton: 'vn-ticket-request-index vn-tr:nth-child(3) vn-icon[icon="delete"]', + thirdRequestQuantity: 'vn-ticket-request-index vn-table vn-tr:nth-child(3) > vn-td:nth-child(6) vn-input-number', saveButton: 'vn-ticket-request-create button[type=submit]', - firstDescription: 'vn-ticket-request-index vn-table vn-tr:nth-child(1) > vn-td:nth-child(2) vn-textfield', }, ticketLog: { diff --git a/e2e/paths/05-ticket/10_request.spec.js b/e2e/paths/05-ticket/10_request.spec.js index ce2c3a324..f4c4c4abe 100644 --- a/e2e/paths/05-ticket/10_request.spec.js +++ b/e2e/paths/05-ticket/10_request.spec.js @@ -9,7 +9,7 @@ describe('Ticket purchase request path', () => { browser = await getBrowser(); page = browser.page; await page.loginAndModule('salesPerson', 'ticket'); - await page.accessToSearchResult('16'); + await page.accessToSearchResult('1'); await page.accessToSection('ticket.card.request.index'); }); @@ -17,10 +17,10 @@ describe('Ticket purchase request path', () => { await browser.close(); }); - it(`should add a new request`, async() => { + it('should add a new request', async() => { await page.waitToClick(selectors.ticketRequests.addRequestButton); await page.write(selectors.ticketRequests.descriptionInput, 'New stuff'); - await page.write(selectors.ticketRequests.quantity, '99'); + await page.write(selectors.ticketRequests.quantity, '9'); await page.autocompleteSearch(selectors.ticketRequests.atender, 'buyerNick'); await page.write(selectors.ticketRequests.price, '999'); await page.waitToClick(selectors.ticketRequests.saveButton); @@ -29,29 +29,53 @@ describe('Ticket purchase request path', () => { expect(result).toEqual('Data saved!'); }); - it(`should have been redirected to the request index`, async() => { + it('should have been redirected to the request index', async() => { let url = await page.expectURL('/request'); expect(url).toBe(true); }); - it(`should confirm the new request was added`, async() => { - await page.reloadSection('ticket.card.request.index'); - const result = await page.waitToGetProperty(selectors.ticketRequests.firstDescription, 'value'); - - expect(result).toEqual('New stuff'); - }); - - it(`should delete the added request`, async() => { - await page.waitToClick(selectors.ticketRequests.firstRemoveRequestButton); + it(`should edit the third request quantity as it's state is still new`, async() => { + // await page.clearInput(selectors.ticketRequests.thirdRequestQuantity); // clear input performs a post. is this intended? + await page.waitForContentLoaded(); + await page.write(selectors.ticketRequests.thirdRequestQuantity, '9'); + await page.keyboard.press('Enter'); const result = await page.waitForLastSnackbar(); expect(result).toEqual('Data saved!'); }); - it(`should confirm the request was deleted`, async() => { + it('should confirm the new request was added', async() => { + await page.reloadSection('ticket.card.request.index'); + const result = await page.waitToGetProperty(selectors.ticketRequests.thirdRequestQuantity, 'value'); + + expect(result).toEqual('99'); + }); + + it(`should confirm first request can't be edited as its state is different to new`, async() => { + await page.waitForClassPresent(selectors.ticketRequests.firstRequestQuantity, 'disabled'); + const result = await page.isDisabled(selectors.ticketRequests.firstRequestQuantity); + + expect(result).toBe(true); + }); + + it(`should confirm second request can't be edited as its state is different to new`, async() => { + await page.waitForClassPresent(selectors.ticketRequests.secondRequestQuantity, 'disabled'); + const result = await page.isDisabled(selectors.ticketRequests.secondRequestQuantity); + + expect(result).toBe(true); + }); + + it('should delete the added request', async() => { + await page.waitToClick(selectors.ticketRequests.thirdRemoveRequestButton); + const result = await page.waitForLastSnackbar(); + + expect(result).toEqual('Data saved!'); + }); + + it('should confirm the request was deleted', async() => { await page.reloadSection('ticket.card.request.index'); await page.wait(selectors.ticketRequests.addRequestButton); - await page.waitForSelector(selectors.ticketRequests.request, {hidden: true}); + await page.waitForSelector(selectors.ticketRequests.thirdDescription, {hidden: true}); }); }); From 6c668131a4397cc7c51f1d6b3c26048f746d9fd1 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Thu, 27 Feb 2020 07:19:42 +0100 Subject: [PATCH 13/31] replaced returnValur for returnThis --- front/core/components/watcher/watcher.spec.js | 2 +- modules/client/front/balance/index/index.spec.js | 4 ++-- modules/client/front/credit-insurance/index/index.spec.js | 2 +- modules/client/front/summary/index.spec.js | 2 +- modules/route/front/tickets/index.spec.js | 2 +- modules/ticket/front/descriptor/index.spec.js | 2 +- modules/ticket/front/sale/specs/index.spec.js | 2 +- modules/worker/front/time-control/index.spec.js | 6 +++--- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/front/core/components/watcher/watcher.spec.js b/front/core/components/watcher/watcher.spec.js index bad55b870..6c2567f7e 100644 --- a/front/core/components/watcher/watcher.spec.js +++ b/front/core/components/watcher/watcher.spec.js @@ -28,7 +28,7 @@ describe('Component vnWatcher', () => { it('should call fetchData() if controllers get and url properties are defined', () => { controller.get = () => {}; controller.url = 'test.com'; - jest.spyOn(controller, 'fetchData').mockReturnValue('ok!'); + jest.spyOn(controller, 'fetchData').mockReturnThis(); controller.$onInit(); expect(controller.fetchData).toHaveBeenCalledWith(); diff --git a/modules/client/front/balance/index/index.spec.js b/modules/client/front/balance/index/index.spec.js index 265c3176b..aaa12b2e3 100644 --- a/modules/client/front/balance/index/index.spec.js +++ b/modules/client/front/balance/index/index.spec.js @@ -45,7 +45,7 @@ describe('Client', () => { describe('company setter/getter', () => { it('should return the company and then call getData()', () => { - jest.spyOn(controller, 'getData').mockReturnValue('ok!'); + jest.spyOn(controller, 'getData').mockReturnThis(); controller.companyId = 442; expect(controller._companyId).toEqual(442); @@ -115,7 +115,7 @@ describe('Client', () => { }); it('should set the balances data and then call the getBalances() method', () => { - jest.spyOn(controller, 'getBalances').mockReturnValue('ok!'); + jest.spyOn(controller, 'getBalances').mockReturnThis(); controller.balances = [{ id: 1, debit: 1000, diff --git a/modules/client/front/credit-insurance/index/index.spec.js b/modules/client/front/credit-insurance/index/index.spec.js index b6a86e5dd..48403263e 100644 --- a/modules/client/front/credit-insurance/index/index.spec.js +++ b/modules/client/front/credit-insurance/index/index.spec.js @@ -72,7 +72,7 @@ describe('Client', () => { describe('returnDialog()', () => { it('should call the returnDialog method and perform a PATCH query, then call _getClassifications method', () => { - jest.spyOn(controller, '_getClassifications').mockReturnValue('ok!'); + jest.spyOn(controller, '_getClassifications').mockReturnThis(); controller.classificationId = 1; $httpBackend.when('PATCH', `CreditClassifications/1`).respond(200); $httpBackend.expect('PATCH', `CreditClassifications/1`); diff --git a/modules/client/front/summary/index.spec.js b/modules/client/front/summary/index.spec.js index 4835a01af..15607008a 100644 --- a/modules/client/front/summary/index.spec.js +++ b/modules/client/front/summary/index.spec.js @@ -17,7 +17,7 @@ describe('Client', () => { it('should perform a GET query and then define the summary property', () => { let res = {name: 'Superman', classifications: []}; - jest.spyOn(controller, 'sumRisk').mockReturnValue('ok!'); + jest.spyOn(controller, 'sumRisk').mockReturnThis(); $httpBackend.when('GET', `Clients/101/summary`).respond(200, res); $httpBackend.expect('GET', `Clients/101/summary`); diff --git a/modules/route/front/tickets/index.spec.js b/modules/route/front/tickets/index.spec.js index e9278d031..d1313dd65 100644 --- a/modules/route/front/tickets/index.spec.js +++ b/modules/route/front/tickets/index.spec.js @@ -159,7 +159,7 @@ describe('Route', () => { describe('removeTicketFromRoute()', () => { it('should perform a patch query then call showSuccess and updateVolume methods', () => { - jest.spyOn(controller, 'updateVolume').mockReturnValue('ok!'); + jest.spyOn(controller, 'updateVolume').mockReturnThis(); jest.spyOn(controller.vnApp, 'showSuccess'); let ticketId = 1; controller.selectedTicket = ticketId; diff --git a/modules/ticket/front/descriptor/index.spec.js b/modules/ticket/front/descriptor/index.spec.js index 645a9fcf1..a43561833 100644 --- a/modules/ticket/front/descriptor/index.spec.js +++ b/modules/ticket/front/descriptor/index.spec.js @@ -119,7 +119,7 @@ describe('Ticket Component vnTicketDescriptor', () => { describe('makeInvoice()', () => { it('should make a query and call $state.reload() method if the response is accept', () => { - jest.spyOn(controller.$state, 'reload').mockReturnValue('ok!'); + jest.spyOn(controller.$state, 'reload').mockReturnThis(); jest.spyOn(controller.vnApp, 'showSuccess'); $httpBackend.when('POST', 'Tickets/2/makeInvoice').respond(); diff --git a/modules/ticket/front/sale/specs/index.spec.js b/modules/ticket/front/sale/specs/index.spec.js index ed5b5c733..57ca1d295 100644 --- a/modules/ticket/front/sale/specs/index.spec.js +++ b/modules/ticket/front/sale/specs/index.spec.js @@ -110,7 +110,7 @@ describe('Ticket', () => { let filter = {where: {code: 'OK'}, fields: ['id']}; filter = encodeURIComponent(JSON.stringify(filter)); let res = [{id: 3}]; - jest.spyOn(controller, 'onStateChange').mockReturnValue('ok!'); + jest.spyOn(controller, 'onStateChange').mockReturnThis(); $httpBackend.whenGET(`States?filter=${filter}`).respond(res); $httpBackend.expectGET(`Tickets/1/subtotal`).respond(200, 227.5); diff --git a/modules/worker/front/time-control/index.spec.js b/modules/worker/front/time-control/index.spec.js index faa234c4f..7987c6a50 100644 --- a/modules/worker/front/time-control/index.spec.js +++ b/modules/worker/front/time-control/index.spec.js @@ -20,7 +20,7 @@ describe('Component vnWorkerTimeControl', () => { describe('date() setter', () => { it(`should set the weekDays, the date in the controller and call fetchHours`, () => { let today = new Date(); - jest.spyOn(controller, 'fetchHours').mockReturnValue('ok!'); + jest.spyOn(controller, 'fetchHours').mockReturnThis(); controller.date = today; @@ -35,7 +35,7 @@ describe('Component vnWorkerTimeControl', () => { describe('hours() setter', () => { it(`should set hours data at it's corresponding week day`, () => { let today = new Date(); - jest.spyOn(controller, 'fetchHours').mockReturnValue('ok!'); + jest.spyOn(controller, 'fetchHours').mockReturnThis(); controller.date = today; @@ -66,7 +66,7 @@ describe('Component vnWorkerTimeControl', () => { describe('getWorkedHours() ', () => { it('should set the weekdays expected and worked hours plus the total worked hours', () => { let today = new Date(); - jest.spyOn(controller, 'fetchHours').mockReturnValue('ok!'); + jest.spyOn(controller, 'fetchHours').mockReturnThis(); controller.date = today; From 21be73b7346d30c6ab5d21c95122b8fdb33e8468 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 26 Feb 2020 14:30:30 +0100 Subject: [PATCH 14/31] 2127 - Disable preview on sepa core sample --- db/changes/10161-postValentineDay/00-sample.sql | 6 ++++++ modules/client/back/models/sample.json | 5 ++++- modules/client/front/sample/create/index.html | 9 ++++++--- modules/client/front/sample/create/index.js | 12 ++++++------ 4 files changed, 22 insertions(+), 10 deletions(-) create mode 100644 db/changes/10161-postValentineDay/00-sample.sql diff --git a/db/changes/10161-postValentineDay/00-sample.sql b/db/changes/10161-postValentineDay/00-sample.sql new file mode 100644 index 000000000..d34835888 --- /dev/null +++ b/db/changes/10161-postValentineDay/00-sample.sql @@ -0,0 +1,6 @@ +ALTER TABLE `vn`.`sample` +ADD COLUMN `hasPreview` TINYINT(1) UNSIGNED NOT NULL DEFAULT '1' AFTER `hasCompany`, +CHANGE COLUMN `isVisible` `isVisible` TINYINT(1) UNSIGNED NOT NULL DEFAULT '1' , +CHANGE COLUMN `hasCompany` `hasCompany` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0' ; + +UPDATE `vn`.`sample` SET `hasPreview` = '0' WHERE (`id` = '14'); diff --git a/modules/client/back/models/sample.json b/modules/client/back/models/sample.json index 8993250f3..725bfb9c7 100644 --- a/modules/client/back/models/sample.json +++ b/modules/client/back/models/sample.json @@ -22,7 +22,10 @@ "type": "Boolean" }, "hasCompany": { - "type": "Number" + "type": "Boolean" + }, + "hasPreview": { + "type": "Boolean" } }, "scopes": { diff --git a/modules/client/front/sample/create/index.html b/modules/client/front/sample/create/index.html index cd3412868..22f95eb20 100644 --- a/modules/client/front/sample/create/index.html +++ b/modules/client/front/sample/create/index.html @@ -23,7 +23,7 @@ - + + diff --git a/modules/client/front/sample/create/index.js b/modules/client/front/sample/create/index.js index e3504785d..f478243c7 100644 --- a/modules/client/front/sample/create/index.js +++ b/modules/client/front/sample/create/index.js @@ -26,13 +26,13 @@ class Controller extends Component { } get companyId() { - if (!this.clientSample.companyId) - this.clientSample.companyId = this.vnConfig.companyFk; - return this.clientSample.companyId; + if (!this.clientSample.companyFk) + this.clientSample.companyFk = this.vnConfig.companyFk; + return this.clientSample.companyFk; } set companyId(value) { - this.clientSample.companyId = value; + this.clientSample.companyFk = value; } onSubmit() { @@ -74,11 +74,11 @@ class Controller extends Component { if (!sampleType) return this.vnApp.showError(this.$translate.instant('Choose a sample')); - if (sampleType.hasCompany && !this.clientSample.companyId) + if (sampleType.hasCompany && !this.clientSample.companyFk) return this.vnApp.showError(this.$translate.instant('Choose a company')); if (sampleType.hasCompany) - params.companyId = this.clientSample.companyId; + params.companyId = this.clientSample.companyFk; if (isPreview) params.isPreview = true; From a063722fbe098ff75599e9ef4841daa0f5bf0c0d Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 27 Feb 2020 07:53:38 +0100 Subject: [PATCH 15/31] Changed SQL sprint --- .../00-sample.sql | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename db/changes/{10161-postValentineDay => 10160-postValentineDay}/00-sample.sql (100%) diff --git a/db/changes/10161-postValentineDay/00-sample.sql b/db/changes/10160-postValentineDay/00-sample.sql similarity index 100% rename from db/changes/10161-postValentineDay/00-sample.sql rename to db/changes/10160-postValentineDay/00-sample.sql From 8a4e2620c214e0c15d70805dea5b6ac57229c3c4 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 27 Feb 2020 07:55:21 +0100 Subject: [PATCH 16/31] Changed sprint --- db/changes/10161-postValentineDay/00-sample.sql | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 db/changes/10161-postValentineDay/00-sample.sql diff --git a/db/changes/10161-postValentineDay/00-sample.sql b/db/changes/10161-postValentineDay/00-sample.sql deleted file mode 100644 index d34835888..000000000 --- a/db/changes/10161-postValentineDay/00-sample.sql +++ /dev/null @@ -1,6 +0,0 @@ -ALTER TABLE `vn`.`sample` -ADD COLUMN `hasPreview` TINYINT(1) UNSIGNED NOT NULL DEFAULT '1' AFTER `hasCompany`, -CHANGE COLUMN `isVisible` `isVisible` TINYINT(1) UNSIGNED NOT NULL DEFAULT '1' , -CHANGE COLUMN `hasCompany` `hasCompany` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0' ; - -UPDATE `vn`.`sample` SET `hasPreview` = '0' WHERE (`id` = '14'); From 6b8915a882f04bde7d422db39b8ac5f3af0dcbaf Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Thu, 27 Feb 2020 08:07:25 +0100 Subject: [PATCH 17/31] removed a commented line --- e2e/paths/05-ticket/10_request.spec.js | 1 - 1 file changed, 1 deletion(-) diff --git a/e2e/paths/05-ticket/10_request.spec.js b/e2e/paths/05-ticket/10_request.spec.js index f4c4c4abe..fd4231809 100644 --- a/e2e/paths/05-ticket/10_request.spec.js +++ b/e2e/paths/05-ticket/10_request.spec.js @@ -36,7 +36,6 @@ describe('Ticket purchase request path', () => { }); it(`should edit the third request quantity as it's state is still new`, async() => { - // await page.clearInput(selectors.ticketRequests.thirdRequestQuantity); // clear input performs a post. is this intended? await page.waitForContentLoaded(); await page.write(selectors.ticketRequests.thirdRequestQuantity, '9'); await page.keyboard.press('Enter'); From a86c7c9b8a6b1bbbdd3328f07fff1857710be4da Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 26 Feb 2020 14:45:47 +0100 Subject: [PATCH 18/31] updated unit tests --- .../client/front/sample/create/index.spec.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/modules/client/front/sample/create/index.spec.js b/modules/client/front/sample/create/index.spec.js index da9a557f1..d3817a439 100644 --- a/modules/client/front/sample/create/index.spec.js +++ b/modules/client/front/sample/create/index.spec.js @@ -107,7 +107,7 @@ describe('Client', () => { expect(controller.$http.get).not.toHaveBeenCalled(); }); - it(`should perform an HTTP query without passing companyId param`, () => { + it(`should perform an HTTP query without passing companyFk param`, () => { controller.$.sampleType.selection = { hasCompany: false, code: 'MyReport' @@ -116,25 +116,34 @@ describe('Client', () => { clientId: 101, recipient: 'client@email.com' }; + const expectedParams = { + clientId: 101, + recipient: 'client@email.com' + }; + const serializedParams = $httpParamSerializer(expectedParams); - const serializedParams = $httpParamSerializer(controller.clientSample); $httpBackend.expect('GET', `email/MyReport?${serializedParams}`).respond(true); controller.send(false, () => {}); $httpBackend.flush(); }); - it(`should perform an HTTP query passing companyId param`, () => { + it(`should perform an HTTP query passing companyFk param`, () => { controller.$.sampleType.selection = { hasCompany: true, code: 'MyReport' }; controller.clientSample = { + clientId: 101, + recipient: 'client@email.com', + companyFk: 442 + }; + const expectedParams = { clientId: 101, recipient: 'client@email.com', companyId: 442 }; + const serializedParams = $httpParamSerializer(expectedParams); - const serializedParams = $httpParamSerializer(controller.clientSample); $httpBackend.expect('GET', `email/MyReport?${serializedParams}`).respond(true); controller.send(false, () => {}); $httpBackend.flush(); From 05d038fa99147f246e0e08d2de0eaccfbeaa5322 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Thu, 27 Feb 2020 08:38:35 +0100 Subject: [PATCH 19/31] custom eslint rules updated --- .eslintrc.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.eslintrc.yml b/.eslintrc.yml index 163ff22a7..380cf915b 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -32,3 +32,5 @@ rules: indent: [error, 4] arrow-parens: [error, as-needed] jasmine/no-focused-tests: 0 + no-multiple-empty-lines: ["error", { "max": 1, "maxEOF": 1 }] + space-in-parens: ["error", "never"] \ No newline at end of file From 70210e87c9ae50310aacb901565ac54728142a7e Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 27 Feb 2020 09:03:36 +0100 Subject: [PATCH 20/31] Advanced filter by ref --- modules/travel/back/methods/travel/filter.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/travel/back/methods/travel/filter.js b/modules/travel/back/methods/travel/filter.js index ecf152b0c..bfe49c834 100644 --- a/modules/travel/back/methods/travel/filter.js +++ b/modules/travel/back/methods/travel/filter.js @@ -63,6 +63,10 @@ module.exports = Self => { type: 'Number', description: 'The totalEntries filter', http: {source: 'query'} + }, { + arg: 'ref', + type: 'string', + description: 'The reference' } ], returns: { @@ -82,7 +86,7 @@ module.exports = Self => { case 'search': return {'t.id': value}; case 'ref': - return {[param]: {regexp: value}}; + return {'t.ref': {like: `%${value}%`}}; case 'shippedFrom': return {'t.shipped': {gte: value}}; case 'shippedTo': From 262e0cd44708b0ac57978b4ca2f85c961fba7004 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Thu, 27 Feb 2020 10:58:58 +0100 Subject: [PATCH 21/31] fix --- e2e/paths/02-client/05_add_address.spec.js | 4 ++-- e2e/paths/05-ticket/10_request.spec.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/e2e/paths/02-client/05_add_address.spec.js b/e2e/paths/02-client/05_add_address.spec.js index e8c6120f8..737d6b05b 100644 --- a/e2e/paths/02-client/05_add_address.spec.js +++ b/e2e/paths/02-client/05_add_address.spec.js @@ -70,13 +70,13 @@ describe('Client Add address path', () => { }); it(`should confirm the new address exists and it's the default one`, async() => { + await page.waitFor(2000); // needs more than a single second to load the section const result = await page.waitToGetProperty(selectors.clientAddresses.defaultAddress, 'innerText'); expect(result).toContain('320 Park Avenue New York'); }); - it(`should click on the make default icon of the second address`, async() => { - await page.waitForContentLoaded(); + it('should click on the make default icon of the second address', async() => { await page.waitToClick(selectors.clientAddresses.secondMakeDefaultStar); const result = await page.waitForLastSnackbar(); diff --git a/e2e/paths/05-ticket/10_request.spec.js b/e2e/paths/05-ticket/10_request.spec.js index fd4231809..737d69048 100644 --- a/e2e/paths/05-ticket/10_request.spec.js +++ b/e2e/paths/05-ticket/10_request.spec.js @@ -36,7 +36,7 @@ describe('Ticket purchase request path', () => { }); it(`should edit the third request quantity as it's state is still new`, async() => { - await page.waitForContentLoaded(); + await page.waitFor(2000); // looks like it needs more than a single second some times to load await page.write(selectors.ticketRequests.thirdRequestQuantity, '9'); await page.keyboard.press('Enter'); const result = await page.waitForLastSnackbar(); From 893b634d3390e0729921ea3dc949f567619d3055 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 21 Feb 2020 08:37:37 +0100 Subject: [PATCH 22/31] Get phone from address and client --- .../back/methods/client/createAddress.js | 26 +++++++------- .../back/methods/client/updateAddress.js | 24 ++++++------- .../back/methods/client/updateFiscalData.js | 36 +++++++++---------- modules/client/front/descriptor/index.js | 5 +-- modules/ticket/front/card/index.js | 4 ++- modules/ticket/front/descriptor/index.js | 4 ++- modules/ticket/front/sale/index.js | 5 ++- 7 files changed, 56 insertions(+), 48 deletions(-) diff --git a/modules/client/back/methods/client/createAddress.js b/modules/client/back/methods/client/createAddress.js index 0319fc386..1a086b124 100644 --- a/modules/client/back/methods/client/createAddress.js +++ b/modules/client/back/methods/client/createAddress.js @@ -5,60 +5,60 @@ module.exports = function(Self) { description: 'Creates client address updating default address', accepts: [{ arg: 'id', - type: 'Number', + type: 'number', description: 'The client id', http: {source: 'path'} }, { arg: 'nickname', - type: 'String', + type: 'string', required: true }, { arg: 'city', - type: 'String', + type: 'string', required: true }, { arg: 'street', - type: 'String', + type: 'string', required: true }, { arg: 'phone', - type: 'String' + type: 'string' }, { arg: 'mobile', - type: 'String' + type: 'string' }, { arg: 'postalCode', - type: 'String' + type: 'string' }, { arg: 'provinceId', - type: 'Number' + type: 'number' }, { arg: 'agencyModeId', - type: 'Number' + type: 'number' }, { arg: 'incotermsId', - type: 'String' + type: 'string' }, { arg: 'customsAgentId', - type: 'Number' + type: 'number' }, { arg: 'isActive', - type: 'Boolean' + type: 'boolean' }, { arg: 'isDefaultAddress', - type: 'Boolean' + type: 'boolean' }], returns: { root: true, diff --git a/modules/client/back/methods/client/updateAddress.js b/modules/client/back/methods/client/updateAddress.js index b9270600f..aa0a7d178 100644 --- a/modules/client/back/methods/client/updateAddress.js +++ b/modules/client/back/methods/client/updateAddress.js @@ -10,55 +10,55 @@ module.exports = function(Self) { }, { arg: 'clientId', - type: 'Number', + type: ['number', 'null'], description: 'The client id', http: {source: 'path'} }, { arg: 'addressId', - type: 'Number', + type: ['number', 'null'], description: 'The address id', http: {source: 'path'} }, { arg: 'nickname', - type: 'String' + type: ['string'] }, { arg: 'city', - type: 'String' + type: ['string'] }, { arg: 'street', - type: 'String' + type: ['string'] }, { arg: 'phone', - type: 'String' + type: 'any' }, { arg: 'mobile', - type: 'String' + type: 'any' }, { arg: 'postalCode', - type: 'String' + type: 'any' }, { arg: 'provinceFk', - type: 'Number' + type: 'any' }, { arg: 'agencyModeFk', - type: 'Number' + type: 'any' }, { arg: 'incotermsFk', - type: 'String' + type: 'any' }, { arg: 'customsAgentFk', - type: 'Number' + type: 'any' }, { arg: 'isActive', diff --git a/modules/client/back/methods/client/updateFiscalData.js b/modules/client/back/methods/client/updateFiscalData.js index 4bc6fda9b..f16b0ef2b 100644 --- a/modules/client/back/methods/client/updateFiscalData.js +++ b/modules/client/back/methods/client/updateFiscalData.js @@ -17,75 +17,75 @@ module.exports = Self => { }, { arg: 'socialName', - type: 'String' + type: 'string' }, { arg: 'fi', - type: 'String' + type: 'string' }, { arg: 'street', - type: 'String' + type: 'string' }, { arg: 'postcode', - type: 'String' + type: 'string' }, { arg: 'city', - type: 'String' + type: 'string' }, { arg: 'countryFk', - type: 'Number' + type: 'number' }, { arg: 'provinceFk', - type: 'Number' + type: 'number' }, { arg: 'hasToInvoiceByAddress', - type: 'Boolean' + type: 'boolean' }, { arg: 'hasToInvoice', - type: 'Boolean' + type: 'boolean' }, { arg: 'isActive', - type: 'Boolean' + type: 'boolean' }, { arg: 'isFreezed', - type: 'Boolean' + type: 'boolean' }, { arg: 'isVies', - type: 'Boolean' + type: 'boolean' }, { arg: 'isToBeMailed', - type: 'Boolean' + type: 'boolean' }, { arg: 'isEqualizated', - type: 'Boolean' + type: 'boolean' }, { arg: 'isTaxDataVerified', - type: 'Boolean' + type: 'boolean' }, { arg: 'isTaxDataChecked', - type: 'Boolean' + type: 'boolean' }, { arg: 'despiteOfClient', - type: 'Number' + type: 'number' }], returns: { arg: 'res', - type: 'String', + type: 'string', root: true }, http: { diff --git a/modules/client/front/descriptor/index.js b/modules/client/front/descriptor/index.js index 3ef1e7616..95754b4df 100644 --- a/modules/client/front/descriptor/index.js +++ b/modules/client/front/descriptor/index.js @@ -55,10 +55,11 @@ class Controller extends Component { } showSMSDialog() { - const phone = this.$params.phone || this.client.phone; + const client = this.client; + const phone = this.$params.phone || client.mobile || client.phone; const message = this.$params.message || ''; this.newSMS = { - destinationFk: this.client.id, + destinationFk: client.id, destination: phone, message: message }; diff --git a/modules/ticket/front/card/index.js b/modules/ticket/front/card/index.js index 131968d65..3872259a9 100644 --- a/modules/ticket/front/card/index.js +++ b/modules/ticket/front/card/index.js @@ -27,7 +27,9 @@ class Controller extends ModuleCard { 'isFreezed', 'isTaxDataChecked', 'credit', - 'email' + 'email', + 'phone', + 'mobile' ], include: { relation: 'salesPerson', diff --git a/modules/ticket/front/descriptor/index.js b/modules/ticket/front/descriptor/index.js index 10da4cca9..d804a2eb2 100644 --- a/modules/ticket/front/descriptor/index.js +++ b/modules/ticket/front/descriptor/index.js @@ -241,7 +241,9 @@ class Controller extends Component { showSMSDialog() { const address = this.ticket.address; - const phone = this.$params.phone || address.mobile; + const client = this.ticket.client; + const phone = this.$params.phone || address.mobile || address.phone || + client.mobile || client.phone; const message = this.$params.message || this.$translate.instant('SMSPayment'); this.newSMS = { destinationFk: this.ticket.clientFk, diff --git a/modules/ticket/front/sale/index.js b/modules/ticket/front/sale/index.js index d0854c996..1ecb6fe41 100644 --- a/modules/ticket/front/sale/index.js +++ b/modules/ticket/front/sale/index.js @@ -431,6 +431,9 @@ class Controller { showSMSDialog() { const address = this.ticket.address; + const client = this.ticket.client; + const phone = address.mobile || address.phone || + client.mobile || client.phone; const sales = this.checkedLines(); const items = sales.map(sale => { return `${sale.quantity} ${sale.concept}`; @@ -443,7 +446,7 @@ class Controller { }; this.newSMS = { destinationFk: this.ticket.clientFk, - destination: address.mobile || null, + destination: phone, message: this.$translate.instant('SMSAvailability', params) }; this.$scope.sms.open(); From c920f0bc91e456abfeca3af8091ef96ea034d01d Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 21 Feb 2020 09:00:13 +0100 Subject: [PATCH 23/31] Requested changes --- .../client/back/methods/client/updateAddress.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/client/back/methods/client/updateAddress.js b/modules/client/back/methods/client/updateAddress.js index aa0a7d178..db8ed38d6 100644 --- a/modules/client/back/methods/client/updateAddress.js +++ b/modules/client/back/methods/client/updateAddress.js @@ -10,27 +10,27 @@ module.exports = function(Self) { }, { arg: 'clientId', - type: ['number', 'null'], + type: 'number', description: 'The client id', http: {source: 'path'} }, { arg: 'addressId', - type: ['number', 'null'], + type: 'number', description: 'The address id', http: {source: 'path'} }, { arg: 'nickname', - type: ['string'] + type: 'string' }, { arg: 'city', - type: ['string'] + type: 'string' }, { arg: 'street', - type: ['string'] + type: 'string' }, { arg: 'phone', @@ -62,11 +62,11 @@ module.exports = function(Self) { }, { arg: 'isActive', - type: 'Boolean' + type: 'boolean' }, { arg: 'isEqualizated', - type: 'Boolean' + type: 'boolean' }], returns: { root: true, From ccd28114ca226619d68c86ad93a861663c261034 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 27 Feb 2020 12:39:58 +0100 Subject: [PATCH 24/31] Updated unit tests --- modules/travel/back/methods/travel/filter.js | 4 ++- .../back/methods/travel/specs/filter.spec.js | 33 ++++++++++++++----- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/modules/travel/back/methods/travel/filter.js b/modules/travel/back/methods/travel/filter.js index bfe49c834..4d1be2d0e 100644 --- a/modules/travel/back/methods/travel/filter.js +++ b/modules/travel/back/methods/travel/filter.js @@ -84,7 +84,9 @@ module.exports = Self => { let where = buildFilter(ctx.args, (param, value) => { switch (param) { case 'search': - return {'t.id': value}; + return /^\d+$/.test(value) + ? {'t.id': value} + : {'t.ref': {like: `%${value}%`}}; case 'ref': return {'t.ref': {like: `%${value}%`}}; case 'shippedFrom': diff --git a/modules/travel/back/methods/travel/specs/filter.spec.js b/modules/travel/back/methods/travel/specs/filter.spec.js index 03849f2b0..d04b0f093 100644 --- a/modules/travel/back/methods/travel/specs/filter.spec.js +++ b/modules/travel/back/methods/travel/specs/filter.spec.js @@ -2,38 +2,53 @@ const app = require('vn-loopback/server/server'); describe('Travel filter()', () => { it('should return the travel matching "search"', async() => { - let ctx = { + const ctx = { args: { search: 1 } }; - let result = await app.models.Travel.filter(ctx); + const result = await app.models.Travel.filter(ctx); + const firstRow = result[0]; expect(result.length).toEqual(1); - expect(result[0].id).toEqual(1); + expect(firstRow.id).toEqual(1); + }); + + it('should return the travel matching "search" by ref', async() => { + const ctx = { + args: { + search: 'third' + } + }; + + const result = await app.models.Travel.filter(ctx); + const firstRow = result[0]; + + expect(result.length).toEqual(1); + expect(firstRow.id).toEqual(3); }); it('should return the travel matching "warehouse out"', async() => { - let ctx = { + const ctx = { args: { warehouseOutFk: 2 } }; - let result = await app.models.Travel.filter(ctx); + const result = await app.models.Travel.filter(ctx); expect(result.length).toEqual(8); }); it('should return the travel matching "total entries"', async() => { - let ctx = { + const ctx = { args: { totalEntries: 1, } }; - let result = await app.models.Travel.filter(ctx); + const result = await app.models.Travel.filter(ctx); expect(result.length).toEqual(5); }); @@ -44,14 +59,14 @@ describe('Travel filter()', () => { from.setHours(0, 0, 0, 0); to.setHours(23, 59, 59, 999); to.setDate(to.getDate() + 1); - let ctx = { + const ctx = { args: { shippedFrom: from, shippedTo: to } }; - let result = await app.models.Travel.filter(ctx); + const result = await app.models.Travel.filter(ctx); expect(result.length).toEqual(1); }); From 6dcfc340566175e313a52f7d91f593fbf67c9763 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 27 Feb 2020 13:33:40 +0100 Subject: [PATCH 25/31] Fix - Find duplicated client --- modules/client/front/fiscal-data/index.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/modules/client/front/fiscal-data/index.js b/modules/client/front/fiscal-data/index.js index 98773de75..b2602f7a4 100644 --- a/modules/client/front/fiscal-data/index.js +++ b/modules/client/front/fiscal-data/index.js @@ -24,14 +24,15 @@ export default class Controller extends Component { const filter = encodeURIComponent(JSON.stringify(filterObj)); const query = `Clients/findOne?filter=${filter}`; this.$http.get(query).then(res => { - if (res.data.id) { - const params = {clientId: res.data.id}; - const question = $t('Found a client with this phone or email', params, null, null, 'sanitizeParameters'); + const params = {clientId: res.data.id}; + const question = $t('Found a client with this phone or email', params, null, null, 'sanitizeParameters'); - this.client.despiteOfClient = params.clientId; - this.$.confirmDuplicatedClient.question = question; - this.$.confirmDuplicatedClient.show(); - } + this.client.despiteOfClient = params.clientId; + this.$.confirmDuplicatedClient.question = question; + this.$.confirmDuplicatedClient.show(); + }).catch(error => { + if (error.status == 404) + this.save(); }); } From 442541d0f8c63a7aef48f40da7df442f1a43e2b0 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 28 Feb 2020 07:24:36 +0100 Subject: [PATCH 26/31] Renamed rgb column --- modules/worker/back/models/calendar-holidays-type.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/worker/back/models/calendar-holidays-type.json b/modules/worker/back/models/calendar-holidays-type.json index a83dbc13c..178331b87 100644 --- a/modules/worker/back/models/calendar-holidays-type.json +++ b/modules/worker/back/models/calendar-holidays-type.json @@ -14,7 +14,7 @@ "name": { "type": "String" }, - "rgb": { + "hexColour": { "type": "String" } }, From 56b986ff95a2299895f7fd1f9a1ce9cfe61402b5 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 28 Feb 2020 07:26:19 +0100 Subject: [PATCH 27/31] No department error --- back/methods/chat/sendCheckingPresence.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/methods/chat/sendCheckingPresence.js b/back/methods/chat/sendCheckingPresence.js index b2a3ca725..7e74a6980 100644 --- a/back/methods/chat/sendCheckingPresence.js +++ b/back/methods/chat/sendCheckingPresence.js @@ -37,7 +37,7 @@ module.exports = Self => { } }); const department = workerDepartment && workerDepartment.department(); - const channelName = department.chatName; + const channelName = department && department.chatName; if (channelName) return Self.send(ctx, `#${channelName}`, `@${account.name} => ${message}`); From a8eea3d8f6a24f6713e3c1790e44eccbaaf56fb1 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 28 Feb 2020 08:19:37 +0100 Subject: [PATCH 28/31] Changed primary key --- modules/worker/back/models/worker-dms.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/worker/back/models/worker-dms.json b/modules/worker/back/models/worker-dms.json index 56cad65a6..f8ad824bc 100644 --- a/modules/worker/back/models/worker-dms.json +++ b/modules/worker/back/models/worker-dms.json @@ -13,10 +13,10 @@ }, "properties": { "id": { - "type": "Number", - "id": true + "type": "Number" }, "dmsFk": { + "id": true, "type": "Number", "required": true, "mysql": { From b0779fb2d363375792e76aa1a42bd0d634d3f79f Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 28 Feb 2020 08:24:01 +0100 Subject: [PATCH 29/31] Added error handler --- back/methods/chat/sendCheckingPresence.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/back/methods/chat/sendCheckingPresence.js b/back/methods/chat/sendCheckingPresence.js index 7e74a6980..5a4ee2fcf 100644 --- a/back/methods/chat/sendCheckingPresence.js +++ b/back/methods/chat/sendCheckingPresence.js @@ -26,6 +26,10 @@ module.exports = Self => { Self.sendCheckingPresence = async(ctx, workerId, message) => { const models = Self.app.models; const account = await models.Account.findById(workerId); + const userId = ctx.req.accessToken.userId; + + if (!account) + throw new Error(`Could not send message to worker id ${workerId} from user ${userId}`); const query = `SELECT worker_isWorking(?) isWorking`; const [result] = await Self.rawSql(query, [workerId]); From 3739548d0d2e7beeefd4ef11c18e3fd137e9731d Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 28 Feb 2020 08:39:59 +0100 Subject: [PATCH 30/31] Added error handling for worker not found --- back/methods/chat/sendCheckingPresence.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/methods/chat/sendCheckingPresence.js b/back/methods/chat/sendCheckingPresence.js index 5a4ee2fcf..f67fb6942 100644 --- a/back/methods/chat/sendCheckingPresence.js +++ b/back/methods/chat/sendCheckingPresence.js @@ -29,7 +29,7 @@ module.exports = Self => { const userId = ctx.req.accessToken.userId; if (!account) - throw new Error(`Could not send message to worker id ${workerId} from user ${userId}`); + throw new Error(`Could not send message "${message}" to worker id ${workerId} from user ${userId}`); const query = `SELECT worker_isWorking(?) isWorking`; const [result] = await Self.rawSql(query, [workerId]); From 96d98a6dcca83ee14c560676fc21b2e9816b4b72 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 28 Feb 2020 09:23:02 +0100 Subject: [PATCH 31/31] Added workerId validation --- back/methods/chat/sendCheckingPresence.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/back/methods/chat/sendCheckingPresence.js b/back/methods/chat/sendCheckingPresence.js index f67fb6942..6fa029b70 100644 --- a/back/methods/chat/sendCheckingPresence.js +++ b/back/methods/chat/sendCheckingPresence.js @@ -24,6 +24,8 @@ module.exports = Self => { }); Self.sendCheckingPresence = async(ctx, workerId, message) => { + if (!workerId) return false; + const models = Self.app.models; const account = await models.Account.findById(workerId); const userId = ctx.req.accessToken.userId;