2018-08-09 13:10:45 +00:00
|
|
|
import './index';
|
|
|
|
|
|
|
|
describe('Client', () => {
|
|
|
|
describe('Component vnClientSummary', () => {
|
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
|
|
|
|
2019-09-13 14:09:14 +00:00
|
|
|
beforeEach(angular.mock.module('client', $translateProvider => {
|
|
|
|
$translateProvider.translations('en', {});
|
|
|
|
}));
|
2018-08-09 13:10:45 +00:00
|
|
|
|
2018-12-22 10:59:26 +00:00
|
|
|
beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => {
|
2018-08-09 13:10:45 +00:00
|
|
|
$httpBackend = _$httpBackend_;
|
|
|
|
controller = $componentController('vnClientSummary');
|
|
|
|
controller.client = {id: 101};
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe('$onChanges()', () => {
|
|
|
|
it('should perform a GET query and define summary property', () => {
|
|
|
|
let res = {name: 'Superman', classifications: []};
|
2018-10-19 06:40:32 +00:00
|
|
|
|
2018-12-22 10:59:26 +00:00
|
|
|
spyOn(controller, 'sumRisk');
|
2018-08-09 13:10:45 +00:00
|
|
|
$httpBackend.when('GET', `/client/api/Clients/101/summary`).respond(200, res);
|
|
|
|
$httpBackend.expect('GET', `/client/api/Clients/101/summary`);
|
2018-10-19 06:40:32 +00:00
|
|
|
|
2018-08-09 13:10:45 +00:00
|
|
|
controller.$onChanges();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.summary).toBeDefined();
|
|
|
|
expect(controller.summary.name).toEqual('Superman');
|
|
|
|
});
|
2018-10-19 06:40:32 +00:00
|
|
|
});
|
2018-08-09 13:10:45 +00:00
|
|
|
|
2018-10-19 06:40:32 +00:00
|
|
|
describe('sumRisk()', () => {
|
|
|
|
it('should sum property amount of an array', () => {
|
|
|
|
controller.summary = {
|
|
|
|
clientRisks: [{
|
|
|
|
companyFk: 442,
|
|
|
|
amount: 100
|
|
|
|
},
|
|
|
|
{
|
|
|
|
companyFk: 567,
|
|
|
|
amount: 200
|
|
|
|
}]};
|
2018-08-09 13:10:45 +00:00
|
|
|
|
2018-10-19 06:40:32 +00:00
|
|
|
let result = controller.sumRisk();
|
|
|
|
|
|
|
|
expect(result).toEqual(300);
|
2018-08-09 13:10:45 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|