2019-10-24 10:49:18 +00:00
|
|
|
import './index';
|
|
|
|
|
|
|
|
describe('component vnTravelSummary', () => {
|
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
2020-01-13 10:53:10 +00:00
|
|
|
let $scope;
|
|
|
|
let $element;
|
|
|
|
let $httpParamSerializer;
|
2019-10-24 10:49:18 +00:00
|
|
|
|
|
|
|
beforeEach(angular.mock.module('travel', $translateProvider => {
|
|
|
|
$translateProvider.translations('en', {});
|
|
|
|
}));
|
|
|
|
|
2020-01-13 10:53:10 +00:00
|
|
|
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => {
|
2019-10-24 10:49:18 +00:00
|
|
|
$httpBackend = _$httpBackend_;
|
2020-01-13 10:53:10 +00:00
|
|
|
$httpParamSerializer = _$httpParamSerializer_;
|
|
|
|
$scope = $rootScope.$new();
|
|
|
|
$element = angular.element(`<vn-travel-summary></vn-travel-summary>`);
|
|
|
|
controller = $componentController('vnTravelSummary', {$element, $scope});
|
2019-10-24 10:49:18 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
describe('travel setter/getter', () => {
|
|
|
|
it('should return the travel and then call both getTravel() and getEntries()', () => {
|
|
|
|
spyOn(controller, 'getTravel');
|
|
|
|
spyOn(controller, 'getEntries');
|
2020-01-13 10:53:10 +00:00
|
|
|
spyOn(controller, 'getThermographs');
|
2019-10-24 10:49:18 +00:00
|
|
|
controller.travel = {id: 99};
|
|
|
|
|
|
|
|
|
|
|
|
expect(controller._travel.id).toEqual(99);
|
|
|
|
expect(controller.getTravel).toHaveBeenCalledWith();
|
|
|
|
expect(controller.getEntries).toHaveBeenCalledWith();
|
2020-01-13 10:53:10 +00:00
|
|
|
expect(controller.getThermographs).toHaveBeenCalledWith();
|
2019-10-24 10:49:18 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getTravel()', () => {
|
|
|
|
it('should perform a get and then store data on the controller', () => {
|
|
|
|
controller._travel = {id: 999};
|
|
|
|
|
|
|
|
const query = `/api/Travels/${controller._travel.id}/getTravel`;
|
|
|
|
$httpBackend.expectGET(query).respond('I am the travelData');
|
|
|
|
controller.getTravel();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.travelData).toEqual('I am the travelData');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getEntries()', () => {
|
|
|
|
it('should call the getEntries method to get the entries data', () => {
|
|
|
|
controller._travel = {id: 999};
|
|
|
|
|
|
|
|
const query = `/api/Travels/${controller._travel.id}/getEntries`;
|
|
|
|
$httpBackend.expectGET(query).respond('I am the entries');
|
|
|
|
controller.getEntries();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.entries).toEqual('I am the entries');
|
|
|
|
});
|
|
|
|
});
|
2020-01-08 12:52:04 +00:00
|
|
|
|
2020-01-13 10:53:10 +00:00
|
|
|
describe('getThermographs()', () => {
|
|
|
|
it('should call the getThermographs method to get the thermographs', () => {
|
|
|
|
controller._travel = {id: 2};
|
|
|
|
const params = {
|
|
|
|
filter: {
|
|
|
|
include: {
|
|
|
|
relation: 'warehouse',
|
|
|
|
scope: {
|
|
|
|
fields: ['id', 'name']
|
|
|
|
}
|
|
|
|
},
|
|
|
|
where: {
|
|
|
|
travelFk: controller._travel.id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const serializedParams = $httpParamSerializer(params);
|
|
|
|
const query = `TravelThermographs?${serializedParams}`;
|
|
|
|
$httpBackend.expectGET(query).respond('I am the thermographs');
|
|
|
|
controller.getThermographs();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.travelThermographs).toEqual('I am the thermographs');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-01-08 12:52:04 +00:00
|
|
|
describe('total()', () => {
|
|
|
|
it('should calculate the total amount of a given property for every row', () => {
|
|
|
|
controller.entries = [
|
|
|
|
{id: 1, freightValue: 1, packageValue: 2, cc: 0.01},
|
|
|
|
{id: 2, freightValue: 1, packageValue: 2, cc: 0.01},
|
|
|
|
{id: 3, freightValue: 1, packageValue: 2, cc: 0.01}
|
|
|
|
];
|
|
|
|
|
|
|
|
expect(controller.total('freightValue')).toEqual(3);
|
|
|
|
expect(controller.total('packageValue')).toEqual(6);
|
|
|
|
expect(controller.total('cc')).toEqual(0.03);
|
|
|
|
});
|
|
|
|
});
|
2019-10-24 10:49:18 +00:00
|
|
|
});
|