import './index.js'; import {crudModel} from '../../../helpers/crudModelHelper'; describe('ticket', () => { describe('Component vnTicketComponents', () => { let $componentController; let $state; let $scope; let controller; beforeEach(() => { angular.mock.module('ticket'); }); beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$state_) => { $componentController = _$componentController_; $state = _$state_; $state.params.id = '1'; $scope = $rootScope.$new(); $scope.model = crudModel; $scope.model.data = [{ components: [ {componentRate: {name: 'valor de compra'}, value: 5}, {componentRate: {name: 'reparto'}, value: 5}, {componentRate: {name: 'recobro'}, value: 5} ], quantity: 1 }, { components: [ {componentRate: {name: 'valor de compra'}, value: 1}, {componentRate: {name: 'reparto'}, value: 1}, {componentRate: {name: 'recobro'}, value: 1} ], quantity: 5 }]; controller = $componentController('vnTicketComponents', {$scope}); })); describe('total()', () => { it('should return the sum from all componenets in each sale', () => { let result = controller.total(); expect(result).toEqual(30); }); }); describe('base()', () => { it(`should return the sum from all 'valor de compra' componenets in each sale`, () => { controller.sales = [{ components: [ {componentRate: {name: 'valor de compra'}, value: 5}, {componentRate: {name: 'reparto'}, value: 5}, {componentRate: {name: 'recobro'}, value: 5} ], quantity: 1 }, { components: [ {componentRate: {name: 'valor de compra'}, value: 1}, {componentRate: {name: 'reparto'}, value: 1}, {componentRate: {name: 'recobro'}, value: 1} ], quantity: 5 } ]; let result = controller.base(); expect(result).toEqual(10); }); }); describe('profitMargin()', () => { it(`should return the sum from all componenets but 'valor de compra' in each sale`, () => { controller.sales = [{ components: [ {componentRate: {name: 'valor de compra'}, value: 5}, {componentRate: {name: 'reparto'}, value: 5}, {componentRate: {name: 'recobro'}, value: 5} ], quantity: 1 }, { components: [ {componentRate: {name: 'valor de compra'}, value: 1}, {componentRate: {name: 'reparto'}, value: 1}, {componentRate: {name: 'recobro'}, value: 1} ], quantity: 5 } ]; let result = controller.profitMargin(); expect(result).toEqual(20); }); }); }); });