salix/client/ticket/src/volume/index.spec.js

43 lines
1.5 KiB
JavaScript
Raw Normal View History

import './index';
describe('ticket', () => {
describe('Component vnTicketVolume', () => {
let $componentController;
let controller;
let $httpBackend;
let $state;
let $scope;
beforeEach(() => {
angular.mock.module('ticket');
});
beforeEach(angular.mock.inject((_$componentController_, _$state_, _$httpBackend_, $rootScope) => {
$componentController = _$componentController_;
$httpBackend = _$httpBackend_;
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
$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;
controller = $componentController('vnTicketVolume', {$scope: $scope}, {$httpBackend: $httpBackend}, {$state: $state});
}));
2018-04-16 15:13:58 +00:00
it('should join the sale volumes to its respective sale', () => {
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}]};
2018-04-16 15:13:58 +00:00
$httpBackend.whenGET(`/api/tickets/1/getVolume`).respond(response);
$httpBackend.expectGET(`/api/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);
});
});
});