137 lines
4.6 KiB
JavaScript
137 lines
4.6 KiB
JavaScript
import './index.js';
|
|
import crudModel from 'core/mocks/crud-model';
|
|
|
|
describe('ticket', () => {
|
|
describe('Component vnTicketComponents', () => {
|
|
let controller;
|
|
let $httpBackend;
|
|
|
|
beforeEach(ngModule('ticket'));
|
|
|
|
beforeEach(inject(($componentController, $rootScope, $state, _$httpBackend_) => {
|
|
$state.params.id = '1';
|
|
let $scope = $rootScope.$new();
|
|
$httpBackend = _$httpBackend_;
|
|
$scope.model = crudModel;
|
|
$scope.model.data = [{
|
|
quantity: 1,
|
|
components: [
|
|
{
|
|
value: 5,
|
|
component: {
|
|
componentType: {
|
|
isBase: 1
|
|
}
|
|
}
|
|
},
|
|
{
|
|
value: 5,
|
|
component: {
|
|
componentType: {
|
|
isBase: 0
|
|
}
|
|
}
|
|
},
|
|
{
|
|
value: 5,
|
|
component: {
|
|
componentType: {
|
|
isBase: 0
|
|
}
|
|
}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
quantity: 5,
|
|
components: [
|
|
{
|
|
value: 1,
|
|
component: {
|
|
componentType: {
|
|
isBase: 1
|
|
}
|
|
}
|
|
},
|
|
{
|
|
value: 1,
|
|
component: {
|
|
componentType: {
|
|
isBase: 0
|
|
}
|
|
}
|
|
},
|
|
{
|
|
value: 1,
|
|
component: {
|
|
componentType: {
|
|
isBase: 0
|
|
}
|
|
}
|
|
},
|
|
]
|
|
}];
|
|
const $element = angular.element('<vn-ticket-components></vn-ticket-components>');
|
|
controller = $componentController('vnTicketComponents', {$element, $scope});
|
|
}));
|
|
|
|
describe('base()', () => {
|
|
it(`should return the sum from all componenets base in each sale`, () => {
|
|
let result = controller.base();
|
|
|
|
expect(result).toEqual(10);
|
|
});
|
|
});
|
|
|
|
describe('ticket setter', () => {
|
|
it('should set the ticket data and then call getTheoricalPorts() and getComponentsSum()', () => {
|
|
jest.spyOn(controller, 'getTheoricalPorts');
|
|
jest.spyOn(controller, 'getComponentsSum');
|
|
controller._ticket = undefined;
|
|
controller.ticket = {
|
|
id: 7
|
|
};
|
|
|
|
expect(controller.ticket).toBeDefined();
|
|
expect(controller.getTheoricalPorts).toHaveBeenCalledWith();
|
|
expect(controller.getComponentsSum).toHaveBeenCalledWith();
|
|
});
|
|
});
|
|
|
|
describe('getTotal()', () => {
|
|
it('should return the total sum of a ticket', () => {
|
|
let result = controller.getTotal();
|
|
|
|
expect(result).toEqual(30);
|
|
});
|
|
});
|
|
|
|
describe('getTheoricalPorts()', () => {
|
|
it('should make a request to get the theorical port of a ticket', () => {
|
|
controller._ticket = {
|
|
id: 7
|
|
};
|
|
$httpBackend.expect('GET', `Tickets/${controller._ticket.id}/freightPorts`).respond('My freight port');
|
|
controller.getTheoricalPorts();
|
|
$httpBackend.flush();
|
|
|
|
expect(controller.theoricalPorts).toBe('My freight port');
|
|
});
|
|
});
|
|
|
|
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');
|
|
});
|
|
});
|
|
});
|
|
});
|