diff --git a/modules/ticket/front/sale/index.js b/modules/ticket/front/sale/index.js index 22494dc003..bd3fa48138 100644 --- a/modules/ticket/front/sale/index.js +++ b/modules/ticket/front/sale/index.js @@ -221,6 +221,7 @@ class Controller extends Section { this.$http.post(query, {newPrice}).then(res => { sale.price = res.data.price; this.edit = null; + this.refreshTotal(); this.vnApp.showSuccess(this.$t('Data saved!')); }).finally(() => this.resetChanges()); } @@ -286,6 +287,7 @@ class Controller extends Section { sale.discount = this.edit.discount; this.edit = null; + this.refreshTotal(); }).finally(() => this.resetChanges()); } @@ -398,6 +400,7 @@ class Controller extends Section { updateQuantity(sale) { const data = {quantity: sale.quantity}; this.$http.post(`Sales/${sale.id}/updateQuantity`, data).then(() => { + this.refreshTotal(); this.vnApp.showSuccess(this.$t('Data saved!')); }).catch(e => { this.$.model.refresh(); @@ -440,6 +443,7 @@ class Controller extends Section { sale.price = newSale.price; sale.item = newSale.item; + this.refreshTotal(); this.vnApp.showSuccess(this.$t('Data saved!')); }).finally(() => this.resetChanges()); } @@ -461,6 +465,7 @@ class Controller extends Section { this.$http.post(query).then(() => { this.vnApp.showSuccess(this.$t('Data saved!')); this.$.model.refresh(); + this.refreshTotal(); }); } diff --git a/modules/ticket/front/sale/index.spec.js b/modules/ticket/front/sale/index.spec.js index c4ab79e769..ba08d9733c 100644 --- a/modules/ticket/front/sale/index.spec.js +++ b/modules/ticket/front/sale/index.spec.js @@ -353,6 +353,7 @@ describe('Ticket', () => { describe('updatePrice()', () => { it('should make an HTTP POST query, update the sale price and then call to the resetChanges() method', () => { + jest.spyOn(controller, 'refreshTotal').mockReturnThis(); jest.spyOn(controller.vnApp, 'showSuccess').mockReturnThis(); jest.spyOn(controller, 'resetChanges').mockReturnThis(); @@ -369,6 +370,7 @@ describe('Ticket', () => { $httpBackend.flush(); expect(selectedSale.price).toEqual(2); + expect(controller.refreshTotal).toHaveBeenCalledWith(); expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); expect(controller.$.editPricePopover.hide).toHaveBeenCalledWith(); expect(controller.resetChanges).toHaveBeenCalledWith(); @@ -447,6 +449,7 @@ describe('Ticket', () => { it('should make an HTTP POST query, update the sales discount and then call to the resetChanges() method', () => { jest.spyOn(controller, 'resetChanges').mockReturnThis(); jest.spyOn(controller.vnApp, 'showSuccess').mockReturnThis(); + jest.spyOn(controller, 'refreshTotal').mockReturnThis(); const expectedDiscount = 10; const firstSelectedSale = controller.sales[0]; @@ -468,6 +471,7 @@ describe('Ticket', () => { expect(firstSelectedSale.discount).toEqual(expectedDiscount); expect(secondSelectedSale.discount).toEqual(expectedDiscount); + expect(controller.refreshTotal).toHaveBeenCalledWith(); expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); expect(controller.resetChanges).toHaveBeenCalledWith(); }); @@ -616,6 +620,7 @@ describe('Ticket', () => { describe('updateQuantity()', () => { it('should make a POST query saving sale quantity', () => { + jest.spyOn(controller, 'refreshTotal').mockReturnThis(); jest.spyOn(controller, 'resetChanges').mockReturnThis(); const selectedSale = controller.sales[0]; @@ -627,6 +632,7 @@ describe('Ticket', () => { controller.updateQuantity(selectedSale); $httpBackend.flush(); + expect(controller.refreshTotal).toHaveBeenCalledWith(); expect(controller.resetChanges).toHaveBeenCalledWith(); }); }); @@ -651,6 +657,7 @@ describe('Ticket', () => { describe('addSale()', () => { it('should make a POST query adding a new sale', () => { jest.spyOn(controller.vnApp, 'showSuccess').mockReturnThis(); + jest.spyOn(controller, 'refreshTotal').mockReturnThis(); jest.spyOn(controller, 'resetChanges').mockReturnThis(); const newSale = {itemFk: 4, quantity: 10}; @@ -672,6 +679,7 @@ describe('Ticket', () => { $httpBackend.flush(); expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); + expect(controller.refreshTotal).toHaveBeenCalledWith(); expect(controller.resetChanges).toHaveBeenCalledWith(); }); }); @@ -702,6 +710,7 @@ describe('Ticket', () => { it('should make an HTTP post query ', () => { jest.spyOn(controller.vnApp, 'showSuccess').mockReturnThis(); jest.spyOn(controller.$.model, 'refresh').mockReturnThis(); + jest.spyOn(controller, 'refreshTotal').mockReturnThis(); const selectedSale = controller.sales[0]; selectedSale.checked = true; @@ -712,6 +721,7 @@ describe('Ticket', () => { expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); expect(controller.$.model.refresh).toHaveBeenCalledWith(); + expect(controller.refreshTotal).toHaveBeenCalledWith(); }); }); });