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

53 lines
1.7 KiB
JavaScript
Raw Normal View History

2020-10-20 07:44:44 +00:00
import './index';
describe('Client', () => {
describe('Component vnClientSummary', () => {
let controller;
let $httpBackend;
let $scope;
beforeEach(ngModule('client'));
beforeEach(inject(($componentController, _$httpBackend_, $rootScope) => {
$httpBackend = _$httpBackend_;
$scope = $rootScope.$new();
const $element = angular.element('<vn-client-summary></vn-client-summary>');
controller = $componentController('vnClientSummary', {$element, $scope});
controller.client = {id: 101};
}));
describe('$onChanges()', () => {
it('should perform a GET query and then define the summary property', () => {
let res = {name: 'Superman', classifications: []};
jest.spyOn(controller, 'sumRisk').mockReturnThis();
$httpBackend.expect('GET', `Clients/101/summary`).respond(200, res);
controller.$onChanges();
$httpBackend.flush();
expect(controller.summary).toBeDefined();
expect(controller.summary.name).toEqual('Superman');
});
});
describe('sumRisk()', () => {
it('should sum property amount of an array', () => {
controller.summary = {
clientRisks: [{
companyFk: 442,
amount: 100
},
{
companyFk: 567,
amount: 200
}]};
let result = controller.sumRisk();
expect(result).toEqual(300);
});
});
});
});