diff --git a/modules/ticket/front/data/step-two/index.html b/modules/ticket/front/data/step-two/index.html index cb68694a6..f390d53ad 100644 --- a/modules/ticket/front/data/step-two/index.html +++ b/modules/ticket/front/data/step-two/index.html @@ -26,9 +26,9 @@ - {{$ctrl.ticket.sale.totalUnitPrice | currency: '€': 2}} - {{$ctrl.ticket.sale.totalNewPrice | currency: '€': 2}} - {{$ctrl.ticket.sale.totalDifference | currency: '€': 2}} + {{$ctrl.totalPrice | currency: '€': 2}} + {{$ctrl.totalNewPrice | currency: '€': 2}} + {{$ctrl.totalPriceDifference | currency: '€': 2}} diff --git a/modules/ticket/front/data/step-two/index.js b/modules/ticket/front/data/step-two/index.js index 493299f52..02f44b8cb 100644 --- a/modules/ticket/front/data/step-two/index.js +++ b/modules/ticket/front/data/step-two/index.js @@ -7,11 +7,41 @@ class Controller { $onInit() { this.data.registerChild(this); + this.getTotalPrice(); + this.getTotalNewPrice(); + this.getTotalDifferenceOfPrice(); } onStepChange(state) { return true; } + + getTotalPrice() { + let totalPrice = 0; + this.ticket.sale.items.forEach(item => { + let itemTotalPrice = item.quantity * item.price; + totalPrice += itemTotalPrice; + }); + this.totalPrice = totalPrice; + } + + getTotalNewPrice() { + let totalNewPrice = 0; + this.ticket.sale.items.forEach(item => { + let itemTotalNewPrice = item.quantity * item.component.newPrice; + totalNewPrice += itemTotalNewPrice; + }); + this.totalNewPrice = totalNewPrice; + } + + getTotalDifferenceOfPrice() { + let totalPriceDifference = 0; + this.ticket.sale.items.forEach(item => { + let itemTotalPriceDifference = item.quantity * item.component.difference; + totalPriceDifference += itemTotalPriceDifference; + }); + this.totalPriceDifference = totalPriceDifference; + } } Controller.$inject = ['$http']; diff --git a/modules/ticket/front/data/step-two/index.spec.js b/modules/ticket/front/data/step-two/index.spec.js new file mode 100644 index 000000000..8ee21da39 --- /dev/null +++ b/modules/ticket/front/data/step-two/index.spec.js @@ -0,0 +1,67 @@ +import './index.js'; + +describe('Ticket', () => { + describe('Component vnTicketDataStepTwo', () => { + let controller; + + beforeEach(ngModule('ticket')); + + beforeEach(angular.mock.inject($componentController => { + controller = $componentController('vnTicketDataStepTwo'); + })); + + describe('getTotalPrice()', () => { + it('should calculate the total price of the sale based on the data received', () => { + controller.ticket = { + sale: { + items: [{ + quantity: 10, + price: 0.1, + component: {newPrice: 0.2, difference: 0.3} + }] + } + }; + + controller.getTotalPrice(); + + expect(controller.totalPrice).toEqual(1); + }); + }); + + describe('getTotalNewPrice()', () => { + it('should calculate the total new price of the sale based on the data received', () => { + controller.ticket = { + sale: { + items: [{ + quantity: 10, + price: 0.1, + component: {newPrice: 0.2, difference: 0.3} + }] + } + }; + + controller.getTotalNewPrice(); + + expect(controller.totalNewPrice).toEqual(2); + }); + }); + + describe('getTotalDifferenceOfPrice()', () => { + it('should calculate the total price difference of the sale based on the data received', () => { + controller.ticket = { + sale: { + items: [{ + quantity: 10, + price: 0.1, + component: {newPrice: 0.2, difference: 0.3} + }] + } + }; + + controller.getTotalDifferenceOfPrice(); + + expect(controller.totalPriceDifference).toEqual(3); + }); + }); + }); +});