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;
|
2020-09-09 06:20:27 +00:00
|
|
|
let $httpBackend;
|
2018-04-13 14:03:43 +00:00
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('ticket'));
|
2018-04-13 14:03:43 +00:00
|
|
|
|
2020-09-09 06:20:27 +00:00
|
|
|
beforeEach(inject(($componentController, $rootScope, $state, _$httpBackend_) => {
|
2018-05-25 08:03:45 +00:00
|
|
|
$state.params.id = '1';
|
2018-12-22 10:59:26 +00:00
|
|
|
let $scope = $rootScope.$new();
|
2020-09-09 06:20:27 +00:00
|
|
|
$httpBackend = _$httpBackend_;
|
2018-08-31 05:53:38 +00:00
|
|
|
$scope.model = crudModel;
|
|
|
|
$scope.model.data = [{
|
2020-09-09 06:20:27 +00:00
|
|
|
quantity: 1,
|
2018-08-31 05:53:38 +00:00
|
|
|
components: [
|
2019-04-02 06:00:16 +00:00
|
|
|
{
|
2020-09-09 06:20:27 +00:00
|
|
|
value: 5,
|
2019-12-27 07:01:53 +00:00
|
|
|
component: {
|
2019-04-02 06:00:16 +00:00
|
|
|
componentType: {
|
|
|
|
isBase: 1
|
|
|
|
}
|
2020-09-09 06:20:27 +00:00
|
|
|
}
|
2019-04-02 06:00:16 +00:00
|
|
|
},
|
|
|
|
{
|
2020-09-09 06:20:27 +00:00
|
|
|
value: 5,
|
2019-12-27 07:01:53 +00:00
|
|
|
component: {
|
2019-04-02 06:00:16 +00:00
|
|
|
componentType: {
|
|
|
|
isBase: 0
|
|
|
|
}
|
2020-09-09 06:20:27 +00:00
|
|
|
}
|
2019-04-02 06:00:16 +00:00
|
|
|
},
|
|
|
|
{
|
2020-09-09 06:20:27 +00:00
|
|
|
value: 5,
|
2019-12-27 07:01:53 +00:00
|
|
|
component: {
|
2019-04-02 06:00:16 +00:00
|
|
|
componentType: {
|
|
|
|
isBase: 0
|
|
|
|
}
|
2020-09-09 06:20:27 +00:00
|
|
|
}
|
2019-04-02 06:00:16 +00:00
|
|
|
}
|
2020-09-09 06:20:27 +00:00
|
|
|
]
|
2018-08-31 05:53:38 +00:00
|
|
|
},
|
|
|
|
{
|
2020-09-09 06:20:27 +00:00
|
|
|
quantity: 5,
|
2018-08-31 05:53:38 +00:00
|
|
|
components: [
|
2019-04-02 06:00:16 +00:00
|
|
|
{
|
2020-09-09 06:20:27 +00:00
|
|
|
value: 1,
|
2019-12-27 07:01:53 +00:00
|
|
|
component: {
|
2019-04-02 06:00:16 +00:00
|
|
|
componentType: {
|
|
|
|
isBase: 1
|
|
|
|
}
|
2020-09-09 06:20:27 +00:00
|
|
|
}
|
2019-04-02 06:00:16 +00:00
|
|
|
},
|
|
|
|
{
|
2020-09-09 06:20:27 +00:00
|
|
|
value: 1,
|
2019-12-27 07:01:53 +00:00
|
|
|
component: {
|
2019-04-02 06:00:16 +00:00
|
|
|
componentType: {
|
|
|
|
isBase: 0
|
|
|
|
}
|
2020-09-09 06:20:27 +00:00
|
|
|
}
|
2019-04-02 06:00:16 +00:00
|
|
|
},
|
|
|
|
{
|
2020-09-09 06:20:27 +00:00
|
|
|
value: 1,
|
2019-12-27 07:01:53 +00:00
|
|
|
component: {
|
2019-04-02 06:00:16 +00:00
|
|
|
componentType: {
|
|
|
|
isBase: 0
|
|
|
|
}
|
2020-09-09 06:20:27 +00:00
|
|
|
}
|
2019-04-02 06:00:16 +00:00
|
|
|
},
|
2020-09-09 06:20:27 +00:00
|
|
|
]
|
2018-08-31 05:53:38 +00:00
|
|
|
}];
|
2020-03-18 07:35:59 +00:00
|
|
|
const $element = angular.element('<vn-ticket-components></vn-ticket-components>');
|
|
|
|
controller = $componentController('vnTicketComponents', {$element, $scope});
|
2018-04-13 14:03:43 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
describe('base()', () => {
|
2019-04-02 06:00:16 +00:00
|
|
|
it(`should return the sum from all componenets base in each sale`, () => {
|
2018-04-13 14:03:43 +00:00
|
|
|
let result = controller.base();
|
|
|
|
|
|
|
|
expect(result).toEqual(10);
|
|
|
|
});
|
|
|
|
});
|
2020-09-09 06:20:27 +00:00
|
|
|
|
|
|
|
describe('ticket setter', () => {
|
2020-09-09 13:49:59 +00:00
|
|
|
it('should set the ticket data and then call getTheoricalCost() and getComponentsSum()', () => {
|
|
|
|
jest.spyOn(controller, 'getTheoricalCost');
|
2020-09-09 06:20:27 +00:00
|
|
|
jest.spyOn(controller, 'getComponentsSum');
|
|
|
|
controller._ticket = undefined;
|
|
|
|
controller.ticket = {
|
|
|
|
id: 7
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(controller.ticket).toBeDefined();
|
2020-09-09 13:49:59 +00:00
|
|
|
expect(controller.getTheoricalCost).toHaveBeenCalledWith();
|
2020-09-09 06:20:27 +00:00
|
|
|
expect(controller.getComponentsSum).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getTotal()', () => {
|
|
|
|
it('should return the total sum of a ticket', () => {
|
|
|
|
let result = controller.getTotal();
|
|
|
|
|
|
|
|
expect(result).toEqual(30);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-09-09 13:49:59 +00:00
|
|
|
describe('getTheoricalCost()', () => {
|
2020-09-10 08:46:56 +00:00
|
|
|
it('should make a request to get the theorical cost of a ticket', () => {
|
2020-09-09 06:20:27 +00:00
|
|
|
controller._ticket = {
|
|
|
|
id: 7
|
|
|
|
};
|
2020-09-10 08:46:56 +00:00
|
|
|
$httpBackend.expect('GET', `Tickets/${controller._ticket.id}/freightCost`).respond('My freight cost');
|
2020-09-09 13:49:59 +00:00
|
|
|
controller.getTheoricalCost();
|
2020-09-09 06:20:27 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
|
2020-09-10 08:46:56 +00:00
|
|
|
expect(controller.theoricalCost).toBe('My freight cost');
|
2020-09-09 06:20:27 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getComponentsSum()', () => {
|
|
|
|
it('should make a request to get the component list', () => {
|
|
|
|
controller._ticket = {
|
|
|
|
id: 7
|
|
|
|
};
|
|
|
|
|
|
|
|
$httpBackend.expect('GET', `Tickets/${controller._ticket.id}/getComponentsSum`).respond('My component list');
|
|
|
|
controller.getComponentsSum();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.componentsList).toBe('My component list');
|
|
|
|
});
|
|
|
|
});
|
2018-04-13 14:03:43 +00:00
|
|
|
});
|
|
|
|
});
|