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

38 lines
1.3 KiB
JavaScript

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();
$scope.model = {data: [{id: 1}, {id: 2}], accept: () => {
return {
then: () => {}
};
}};
$state = _$state_;
$state.params.id = 101;
controller = $componentController('vnTicketVolume', {$scope, $httpBackend, $state});
}));
it('should join the sale volumes to its respective sale', () => {
controller.ticket = {id: 1};
let response = {volumes: [{saleFk: 1, m3: 0.008}, {saleFk: 2, m3: 0.003}]};
$httpBackend.whenGET(`/api/tickets/1/getVolume`).respond(response);
$httpBackend.expectGET(`/api/tickets/1/getVolume`);
controller.onDataChange();
$httpBackend.flush();
expect($scope.model.data[0].volume.m3).toBe(0.008);
expect($scope.model.data[1].volume.m3).toBe(0.003);
});
});
});