2018-05-25 08:03:45 +00:00
|
|
|
import './index';
|
2018-04-16 14:47:04 +00:00
|
|
|
|
|
|
|
describe('ticket', () => {
|
|
|
|
describe('Component vnTicketVolume', () => {
|
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
|
|
|
let $state;
|
|
|
|
let $scope;
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('ticket'));
|
2018-04-16 14:47:04 +00:00
|
|
|
|
2020-07-23 14:46:16 +00:00
|
|
|
beforeEach(inject(($componentController, _$state_, _$httpBackend_, $rootScope) => {
|
2018-04-16 14:47:04 +00:00
|
|
|
$httpBackend = _$httpBackend_;
|
|
|
|
$scope = $rootScope.$new();
|
2018-07-17 06:44:31 +00:00
|
|
|
$scope.model = {data: [{id: 1}, {id: 2}], accept: () => {
|
2018-04-30 11:57:10 +00:00
|
|
|
return {
|
|
|
|
then: () => {}
|
|
|
|
};
|
|
|
|
}};
|
2018-05-28 07:30:00 +00:00
|
|
|
$state = _$state_;
|
2021-06-23 11:24:23 +00:00
|
|
|
$state.params.id = 1101;
|
2020-03-18 07:35:59 +00:00
|
|
|
const $element = angular.element('<vn-ticket-volume></vn-ticket-volume>');
|
|
|
|
controller = $componentController('vnTicketVolume', {$element, $scope});
|
2018-04-16 14:47:04 +00:00
|
|
|
}));
|
|
|
|
|
2019-03-26 08:33:54 +00:00
|
|
|
describe('sales() setter', () => {
|
|
|
|
it('should set sales property on controller an then call applyVolumes() method', () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller, 'applyVolumes');
|
2019-03-26 08:33:54 +00:00
|
|
|
|
|
|
|
controller.sales = [{id: 1}];
|
|
|
|
|
|
|
|
expect(controller.applyVolumes).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('applyVolumes()', () => {
|
2022-01-12 13:04:16 +00:00
|
|
|
const ticket = 1;
|
2022-01-17 12:17:06 +00:00
|
|
|
const response =
|
2022-01-12 13:04:16 +00:00
|
|
|
{
|
|
|
|
saleVolume: [
|
2022-01-17 12:17:06 +00:00
|
|
|
{saleFk: 1, volume: 0.012},
|
2022-01-12 13:04:16 +00:00
|
|
|
{saleFk: 2, volume: 0.015}
|
|
|
|
],
|
|
|
|
packingTypeVolume: [
|
2022-01-17 12:17:06 +00:00
|
|
|
{code: 'V', volume: 1},
|
|
|
|
{code: 'H', volume: 2}
|
2022-01-12 13:04:16 +00:00
|
|
|
]
|
|
|
|
};
|
2022-01-17 12:17:06 +00:00
|
|
|
|
2019-03-26 08:33:54 +00:00
|
|
|
it(`should not apply volumes to the sales if sales property is not defined on controller`, () => {
|
|
|
|
controller.sales = [{id: 1, name: 'Sale one'}, {id: 2, name: 'Sale two'}];
|
|
|
|
|
|
|
|
expect(controller.sales[0].volume).toBeUndefined();
|
|
|
|
expect(controller.sales[1].volume).toBeUndefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`should not apply volumes to the sales if sales property is not defined on controller`, () => {
|
|
|
|
controller.volumes = [{saleFk: 1, m3: 0.012}, {saleFk: 2, m3: 0.015}];
|
|
|
|
|
|
|
|
expect(controller.sales).toBeUndefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`should apply volumes to the sales if sales and volumes properties are defined on controller`, () => {
|
2022-01-17 12:17:06 +00:00
|
|
|
const expectedResultOne = response.saleVolume[0].volume;
|
|
|
|
const expectedResultTwo = response.saleVolume[1].volume;
|
|
|
|
$httpBackend.expectGET(`Tickets/${ticket}/getVolume`).respond(response);
|
2022-01-12 13:04:16 +00:00
|
|
|
controller.sales = [
|
2022-01-17 12:17:06 +00:00
|
|
|
{id: 1, name: 'Sale one', ticketFk: ticket},
|
2022-01-12 13:04:16 +00:00
|
|
|
{id: 2, name: 'Sale two'}
|
|
|
|
];
|
|
|
|
$httpBackend.flush();
|
2019-03-26 08:33:54 +00:00
|
|
|
|
2022-01-17 12:17:06 +00:00
|
|
|
expect(controller.sales[0].saleVolume.volume).toEqual(expectedResultOne);
|
|
|
|
expect(controller.sales[1].saleVolume.volume).toEqual(expectedResultTwo);
|
2019-03-26 08:33:54 +00:00
|
|
|
});
|
2022-01-12 13:04:16 +00:00
|
|
|
|
|
|
|
it(`should apply packing volumes to the sales if sales and volumes properties are defined on controller`, () => {
|
2022-01-17 12:17:06 +00:00
|
|
|
const expectedResultOne = response.packingTypeVolume[0].code;
|
|
|
|
const expectedResultTwo = response.packingTypeVolume[1].code;
|
|
|
|
$httpBackend.expectGET(`Tickets/${ticket}/getVolume`).respond(response);
|
2022-01-12 13:04:16 +00:00
|
|
|
controller.sales = [
|
2022-01-17 12:17:06 +00:00
|
|
|
{id: 1, name: 'Sale one', ticketFk: ticket},
|
2022-01-12 13:04:16 +00:00
|
|
|
{id: 2, name: 'Sale two'}
|
|
|
|
];
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
2022-01-17 12:17:06 +00:00
|
|
|
expect(controller.packingTypeVolume[0].code).toEqual(expectedResultOne);
|
|
|
|
expect(controller.packingTypeVolume[1].code).toEqual(expectedResultTwo);
|
2022-01-12 13:04:16 +00:00
|
|
|
});
|
2019-03-26 08:33:54 +00:00
|
|
|
});
|
2018-04-16 14:47:04 +00:00
|
|
|
});
|
|
|
|
});
|