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

45 lines
1.9 KiB
JavaScript
Raw Normal View History

2018-11-14 09:55:15 +00:00
import './index';
describe('Client', () => {
describe('Component vnClientBalanceIndex', () => {
2018-11-14 09:55:15 +00:00
let $componentController;
let $scope;
2019-04-05 11:20:34 +00:00
let $httpBackend;
let $httpParamSerializer;
2018-11-14 09:55:15 +00:00
let controller;
beforeEach(ngModule('client'));
2018-11-14 09:55:15 +00:00
2019-04-05 11:20:34 +00:00
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$httpBackend_, _$httpParamSerializer_) => {
2018-11-14 09:55:15 +00:00
$componentController = _$componentController_;
2019-04-05 11:20:34 +00:00
$httpBackend = _$httpBackend_;
$httpParamSerializer = _$httpParamSerializer_;
2018-11-14 09:55:15 +00:00
$scope = $rootScope.$new();
controller = $componentController('vnClientBalanceIndex', {$scope});
2018-11-14 09:55:15 +00:00
}));
2019-04-05 11:20:34 +00:00
describe('balances() setter', () => {
2018-11-14 09:55:15 +00:00
it('should calculate the balance for each line from the oldest date to the newest', () => {
2019-04-05 11:20:34 +00:00
controller.getCurrentBalance = jasmine.createSpy(controller, 'getCurrentBalance').and.returnValue(1000);
let balances = [
{credit: -100, debit: 0},
{credit: 0, debit: 300},
2018-11-14 09:55:15 +00:00
{credit: 100, debit: 0},
2019-04-05 11:20:34 +00:00
{credit: 0, debit: -300}
2018-11-14 09:55:15 +00:00
];
2019-04-05 11:20:34 +00:00
const params = {filter: controller.filter};
let serializedParams = $httpParamSerializer(params);
$httpBackend.when('GET', `ClientRisks?${serializedParams}`).respond(balances);
$httpBackend.expect('GET', `ClientRisks?${serializedParams}`);
2019-04-05 11:20:34 +00:00
controller.balances = balances;
$httpBackend.flush();
2018-11-14 09:55:15 +00:00
2019-04-05 11:20:34 +00:00
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);
2018-11-14 09:55:15 +00:00
});
});
});
});