import './index'; describe('Client', () => { describe('Component vnClientRiskIndex', () => { let $componentController; let $scope; let $httpBackend; let $httpParamSerializer; let controller; beforeEach(ngModule('client')); beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$httpBackend_, _$httpParamSerializer_) => { $componentController = _$componentController_; $httpBackend = _$httpBackend_; $httpParamSerializer = _$httpParamSerializer_; $scope = $rootScope.$new(); controller = $componentController('vnClientRiskIndex', {$scope}); })); describe('balances() setter', () => { it('should calculate the balance for each line from the oldest date to the newest', () => { controller.getCurrentBalance = jasmine.createSpy(controller, 'getCurrentBalance').and.returnValue(1000); let balances = [ {credit: -100, debit: 0}, {credit: 0, debit: 300}, {credit: 100, debit: 0}, {credit: 0, debit: -300} ]; const params = {filter: controller.filter}; let serializedParams = $httpParamSerializer(params); $httpBackend.when('GET', `/client/api/ClientRisks?${serializedParams}`).respond(balances); $httpBackend.expect('GET', `/client/api/ClientRisks?${serializedParams}`); controller.balances = balances; $httpBackend.flush(); expect(controller.balances[0].balance).toEqual(1000); expect(controller.balances[1].balance).toEqual(900); expect(controller.balances[2].balance).toEqual(600); expect(controller.balances[3].balance).toEqual(700); }); }); }); });