138 lines
5.0 KiB
JavaScript
138 lines
5.0 KiB
JavaScript
import './index';
|
|
|
|
describe('Client', () => {
|
|
describe('Component vnClientBalanceIndex', () => {
|
|
let controller;
|
|
|
|
beforeEach(ngModule('client'));
|
|
|
|
beforeEach(inject(($componentController, $rootScope) => {
|
|
let $scope = $rootScope.$new();
|
|
const $element = angular.element('<vn-client-balance-index></vn-client-balance-index>');
|
|
controller = $componentController('vnClientBalanceIndex', {$element, $scope});
|
|
controller.$.model = {applyFilter: () => {}};
|
|
controller.$.riskModel = {
|
|
applyFilter: () => {},
|
|
data:
|
|
[{
|
|
clientFk: 101,
|
|
companyFk: 442,
|
|
amount: 713.24,
|
|
company: {
|
|
id: 442,
|
|
code: 'VNL'
|
|
}
|
|
}]
|
|
};
|
|
}));
|
|
|
|
describe('getData()', () => {
|
|
it('should apply the filters on he models and get the client balance', () => {
|
|
controller._companyId = 442;
|
|
controller.$params.id = 101;
|
|
jest.spyOn(controller, 'getBalances').mockReturnThis();
|
|
jest.spyOn(controller.$.model, 'applyFilter').mockReturnValue(Promise.resolve());
|
|
jest.spyOn(controller.$.riskModel, 'applyFilter').mockReturnValue(Promise.resolve());
|
|
|
|
controller.getData().then(() => {
|
|
expect(controller.$.model.applyFilter).toHaveBeenCalledWith(null, {'clientId': 101, 'companyId': 442});
|
|
expect(controller.$.riskModel.applyFilter).toHaveBeenCalledWith({'where': {'clientFk': 101, 'companyFk': 442}});
|
|
expect(controller.getBalances).toHaveBeenCalledWith();
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('company setter/getter', () => {
|
|
it('should return the company and then call getData()', () => {
|
|
jest.spyOn(controller, 'getData').mockReturnThis();
|
|
controller.companyId = 442;
|
|
|
|
expect(controller._companyId).toEqual(442);
|
|
expect(controller.getData).toHaveBeenCalledWith();
|
|
});
|
|
});
|
|
|
|
describe('getCurrentBalance()', () => {
|
|
it('should return the client balance amount', () => {
|
|
controller._companyId = 442;
|
|
let result = controller.getCurrentBalance();
|
|
|
|
expect(result).toEqual(713.24);
|
|
});
|
|
});
|
|
|
|
describe('getBalances()', () => {
|
|
it('should return the total client balance amount', () => {
|
|
jest.spyOn(controller, 'getCurrentBalance');
|
|
controller._companyId = 442;
|
|
controller.$.model = {data:
|
|
[{
|
|
id: 1,
|
|
debit: 1000,
|
|
credit: null
|
|
},
|
|
{
|
|
id: 2,
|
|
debit: null,
|
|
credit: 500
|
|
},
|
|
{
|
|
id: 3,
|
|
debit: null,
|
|
credit: 300
|
|
}
|
|
]};
|
|
controller.getBalances();
|
|
const expectedBalances = controller.$.model.data;
|
|
|
|
expect(expectedBalances[0].balance).toEqual(713.24);
|
|
expect(expectedBalances[1].balance).toEqual(-286.76);
|
|
expect(expectedBalances[2].balance).toEqual(213.24);
|
|
});
|
|
});
|
|
|
|
describe('balances() setter', () => {
|
|
it('should set the balances data and not call the getBalances() method', () => {
|
|
jest.spyOn(controller, 'getBalances');
|
|
controller.$.riskModel.data = null;
|
|
controller.balances = [{
|
|
id: 1,
|
|
debit: 1000,
|
|
credit: null
|
|
}, {
|
|
id: 2,
|
|
debit: null,
|
|
credit: 500
|
|
}, {
|
|
id: 3,
|
|
debit: null,
|
|
credit: 300
|
|
}];
|
|
|
|
expect(controller.balances).toBeDefined();
|
|
expect(controller.getBalances).not.toHaveBeenCalledWith();
|
|
});
|
|
|
|
it('should set the balances data and then call the getBalances() method', () => {
|
|
jest.spyOn(controller, 'getBalances').mockReturnThis();
|
|
controller.balances = [{
|
|
id: 1,
|
|
debit: 1000,
|
|
credit: null
|
|
}, {
|
|
id: 2,
|
|
debit: null,
|
|
credit: 500
|
|
}, {
|
|
id: 3,
|
|
debit: null,
|
|
credit: 300
|
|
}];
|
|
|
|
expect(controller.balances).toBeDefined();
|
|
expect(controller.getBalances).toHaveBeenCalledWith();
|
|
});
|
|
});
|
|
});
|
|
});
|