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

51 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-08-09 13:10:45 +00:00
import './index';
describe('Client', () => {
describe('Component vnClientSummary', () => {
let controller;
let $httpBackend;
beforeEach(ngModule('client'));
2018-08-09 13:10:45 +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()', () => {
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();
$httpBackend.when('GET', `Clients/101/summary`).respond(200, res);
$httpBackend.expect('GET', `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
});
});
});
});