From 604f75c84be5063fb50e86f1228acfc67c3319b0 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Tue, 12 Feb 2019 07:42:19 +0100 Subject: [PATCH] Show/send claim pickup order #1106 --- modules/claim/front/descriptor/index.html | 8 +-- modules/claim/front/descriptor/index.js | 19 ++++--- modules/claim/front/descriptor/index.spec.js | 52 ++++++++++++++++++++ modules/claim/front/locale/es.yml | 6 ++- 4 files changed, 71 insertions(+), 14 deletions(-) create mode 100644 modules/claim/front/descriptor/index.spec.js diff --git a/modules/claim/front/descriptor/index.html b/modules/claim/front/descriptor/index.html index 91cc5802d..27d984fb6 100644 --- a/modules/claim/front/descriptor/index.html +++ b/modules/claim/front/descriptor/index.html @@ -70,8 +70,8 @@ + vn-id="confirm-pickup-order" + on-response="$ctrl.sendPickupOrder(response)" + question="Send Pickup order" + message="Are you sure you want to send it?"> \ No newline at end of file diff --git a/modules/claim/front/descriptor/index.js b/modules/claim/front/descriptor/index.js index abbdcf43f..266983c98 100644 --- a/modules/claim/front/descriptor/index.js +++ b/modules/claim/front/descriptor/index.js @@ -8,7 +8,8 @@ class Controller { this.$translate = $translate; this.vnApp = vnApp; this.moreOptions = [ - {callback: this.showConfirmDialog, name: 'Pickup order'} + {callback: this.showPickupOrder, name: 'Show Pickup order'}, + {callback: this.confirmPickupOrder, name: 'Send Pickup order'} ]; } @@ -47,15 +48,17 @@ class Controller { callback.call(this); } - showConfirmDialog() { - this.$scope.confirmDialog.show(); + showPickupOrder() { + let url = `/api/report/rpt-claim-pickup-order?claimFk=${this.claim.id}`; + window.open(url); } - returnDialog(response) { - if (response === 'CANCEL') { - let url = `/api/report/rpt-claim-pickup-order?claimFk=${this.claim.id}`; - window.open(url); - } else if (response === 'ACCEPT') { + confirmPickupOrder() { + this.$scope.confirmPickupOrder.show(); + } + + sendPickupOrder(response) { + if (response === 'ACCEPT') { this.$http.post(`/api/email/claim-pickup-order`, {claimFk: this.claim.id}).then( () => this.vnApp.showMessage(this.$translate.instant('Notification sent!')) ); diff --git a/modules/claim/front/descriptor/index.spec.js b/modules/claim/front/descriptor/index.spec.js new file mode 100644 index 000000000..97fa0f9c3 --- /dev/null +++ b/modules/claim/front/descriptor/index.spec.js @@ -0,0 +1,52 @@ +import './index.js'; + +describe('Item Component vnClaimDescriptor', () => { + let $httpBackend; + let controller; + + beforeEach(() => { + ngModule('claim'); + }); + + beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => { + $httpBackend = _$httpBackend_; + controller = $componentController('vnClaimDescriptor'); + controller.claim = {id: 2}; + })); + + describe('showPickupOrder()', () => { + it('should open a new window showing a pickup order PDF document', () => { + let expectedPath = '/api/report/rpt-claim-pickup-order?claimFk=2'; + spyOn(window, 'open'); + controller.showPickupOrder(); + + expect(window.open).toHaveBeenCalledWith(expectedPath); + }); + }); + + describe('confirmPickupOrder()', () => { + it('should call confirmPickupOrder.show()', () => { + controller.$scope.confirmPickupOrder = { + show: jasmine.createSpy('show') + }; + controller.claim = {id: 2}; + controller.confirmPickupOrder(); + + expect(controller.$scope.confirmPickupOrder.show).toHaveBeenCalledWith(); + }); + }); + + describe('sendPickupOrder(response)', () => { + it('should make a query and call vnApp.showMessage() if the response is ACCEPT', () => { + spyOn(controller.vnApp, 'showMessage'); + + $httpBackend.when('POST', `/api/email/claim-pickup-order`, {claimFk: 2}).respond(); + $httpBackend.expect('POST', `/api/email/claim-pickup-order`, {claimFk: 2}).respond(); + controller.sendPickupOrder('ACCEPT'); + $httpBackend.flush(); + + expect(controller.vnApp.showMessage).toHaveBeenCalledWith('Notification sent!'); + }); + }); +}); + diff --git a/modules/claim/front/locale/es.yml b/modules/claim/front/locale/es.yml index d348c8ff1..307494dcd 100644 --- a/modules/claim/front/locale/es.yml +++ b/modules/claim/front/locale/es.yml @@ -1,5 +1,6 @@ #Ordenar alfabeticamente Add sale: Añadir linea +Are you sure you want to send it?: ¿Seguro que quieres enviarlo? Client Id: Id cliente Claimed ticket: Ticket reclamado Observation: Observación @@ -7,5 +8,6 @@ Responsible: Responsable Remove sale: Borrar linea Claim Id: Id reclamación Created: Creado -Pickup order: Orden de recogida -Do you want to send it directly?: ¿Quieres enviarlo directamente? +Send Pickup order: Enviar orden de recogida +Show Pickup order: Ver orden de recogida +