2018-08-09 13:10:45 +00:00
|
|
|
import './index';
|
|
|
|
|
|
|
|
describe('Client', () => {
|
|
|
|
describe('Component vnClientSummary', () => {
|
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
2020-03-17 10:17:50 +00:00
|
|
|
let $scope;
|
2018-08-09 13:10:45 +00:00
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('client'));
|
2018-08-09 13:10:45 +00:00
|
|
|
|
2020-07-23 14:46:16 +00:00
|
|
|
beforeEach(inject(($componentController, _$httpBackend_, $rootScope) => {
|
2018-08-09 13:10:45 +00:00
|
|
|
$httpBackend = _$httpBackend_;
|
2020-03-17 10:17:50 +00:00
|
|
|
$scope = $rootScope.$new();
|
|
|
|
const $element = angular.element('<vn-client-summary></vn-client-summary>');
|
|
|
|
controller = $componentController('vnClientSummary', {$element, $scope});
|
2018-08-09 13:10:45 +00:00
|
|
|
controller.client = {id: 101};
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe('$onChanges()', () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
it('should perform a GET query and then define the summary property', () => {
|
2018-08-09 13:10:45 +00:00
|
|
|
let res = {name: 'Superman', classifications: []};
|
2018-10-19 06:40:32 +00:00
|
|
|
|
2020-02-27 06:19:42 +00:00
|
|
|
jest.spyOn(controller, 'sumRisk').mockReturnThis();
|
2020-07-23 15:10:07 +00:00
|
|
|
$httpBackend.expect('GET', `Clients/101/summary`).respond(200, res);
|
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
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|