salix/modules/ticket/front/volume/index.spec.js

82 lines
3.2 KiB
JavaScript
Raw Normal View History

import './index';
describe('ticket', () => {
describe('Component vnTicketVolume', () => {
let controller;
let $httpBackend;
let $state;
let $scope;
beforeEach(ngModule('ticket'));
beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_, $rootScope) => {
$httpBackend = _$httpBackend_;
$scope = $rootScope.$new();
2018-07-17 06:44:31 +00:00
$scope.model = {data: [{id: 1}, {id: 2}], accept: () => {
return {
then: () => {}
};
}};
2018-05-28 07:30:00 +00:00
$state = _$state_;
$state.params.id = 101;
2020-03-18 07:35:59 +00:00
const $element = angular.element('<vn-ticket-volume></vn-ticket-volume>');
controller = $componentController('vnTicketVolume', {$element, $scope});
}));
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('volumes() setter', () => {
it('should set volumes 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.volumes = [{id: 1}];
expect(controller.applyVolumes).toHaveBeenCalledWith();
});
});
describe('applyVolumes()', () => {
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`, () => {
controller.sales = [{id: 1, name: 'Sale one'}, {id: 2, name: 'Sale two'}];
controller.volumes = [{saleFk: 1, m3: 0.012}, {saleFk: 2, m3: 0.015}];
expect(controller.sales[0].volume.m3).toEqual(0.012);
expect(controller.sales[1].volume.m3).toEqual(0.015);
});
});
/* it('should join the sale volumes to its respective sale', () => {
2018-04-16 15:13:58 +00:00
controller.ticket = {id: 1};
2018-05-28 07:30:00 +00:00
let response = {volumes: [{saleFk: 1, m3: 0.008}, {saleFk: 2, m3: 0.003}]};
$httpBackend.whenGET(`tickets/1/getVolume`).respond(response);
$httpBackend.expectGET(`tickets/1/getVolume`);
2018-07-17 06:44:31 +00:00
controller.onDataChange();
2018-04-16 15:13:58 +00:00
$httpBackend.flush();
2018-07-17 06:44:31 +00:00
expect($scope.model.data[0].volume.m3).toBe(0.008);
expect($scope.model.data[1].volume.m3).toBe(0.003);
2019-03-26 08:33:54 +00:00
}); */
});
});