2018-05-25 08:03:45 +00:00
|
|
|
import './index.js';
|
2018-12-27 11:54:16 +00:00
|
|
|
import crudModel from 'core/mocks/crud-model';
|
2018-04-13 14:03:43 +00:00
|
|
|
|
|
|
|
describe('ticket', () => {
|
|
|
|
describe('Component vnTicketComponents', () => {
|
|
|
|
let controller;
|
|
|
|
|
2018-12-22 10:59:26 +00:00
|
|
|
beforeEach(ngModule('ticket'));
|
2018-04-13 14:03:43 +00:00
|
|
|
|
2018-12-22 10:59:26 +00:00
|
|
|
beforeEach(angular.mock.inject(($componentController, $rootScope, $state) => {
|
2018-05-25 08:03:45 +00:00
|
|
|
$state.params.id = '1';
|
2018-12-22 10:59:26 +00:00
|
|
|
let $scope = $rootScope.$new();
|
2018-08-31 05:53:38 +00:00
|
|
|
$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});
|
2018-04-13 14:03:43 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|