salix/modules/travel/front/summary/index.spec.js

87 lines
3.2 KiB
JavaScript
Raw Normal View History

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 $httpParamSerializer;
2019-10-24 10:49:18 +00:00
beforeEach(angular.mock.module('travel', $translateProvider => {
$translateProvider.translations('en', {});
}));
2020-07-23 14:46:16 +00:00
beforeEach(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();
2020-03-18 11:55:22 +00:00
const $element = angular.element(`<vn-travel-summary></vn-travel-summary>`);
2020-01-13 10:53:10 +00:00
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()', () => {
2020-02-26 12:22:52 +00:00
jest.spyOn(controller, 'getTravel');
jest.spyOn(controller, 'getEntries');
jest.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};
2020-04-25 09:50:04 +00:00
const query = `Travels/${controller._travel.id}/getTravel`;
2019-10-24 10:49:18 +00:00
$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};
2020-04-25 09:50:04 +00:00
const query = `Travels/${controller._travel.id}/getEntries`;
2019-10-24 10:49:18 +00:00
$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};
2020-04-25 09:50:04 +00:00
$httpBackend.expectGET(`TravelThermographs`).respond('I am the thermographs');
2020-01-13 10:53:10 +00:00
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
});