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

76 lines
2.6 KiB
JavaScript
Raw Normal View History

2019-10-24 10:49:18 +00:00
import './index';
describe('component vnTravelSummary', () => {
let controller;
let $httpBackend;
beforeEach(angular.mock.module('travel', $translateProvider => {
$translateProvider.translations('en', {});
}));
beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => {
$httpBackend = _$httpBackend_;
controller = $componentController('vnTravelSummary');
}));
describe('travel setter/getter', () => {
it('should return the travel', () => {
controller.travel = {id: null};
expect(controller.travel).toEqual(jasmine.any(Object));
});
it('should return the travel and then call both getTravel() and getEntries()', () => {
spyOn(controller, 'getTravel');
spyOn(controller, 'getEntries');
controller.travel = {id: 99};
expect(controller._travel.id).toEqual(99);
expect(controller.getTravel).toHaveBeenCalledWith();
expect(controller.getEntries).toHaveBeenCalledWith();
});
});
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
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
});