2018-05-23 12:26:51 +00:00
|
|
|
import './index';
|
2018-05-11 09:16:16 +00:00
|
|
|
|
|
|
|
describe('Client', () => {
|
|
|
|
describe('Component vnClientCreditCreate', () => {
|
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
|
|
|
let $state;
|
|
|
|
let $scope;
|
|
|
|
let client;
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('client'));
|
2018-05-11 09:16:16 +00:00
|
|
|
|
2020-07-23 14:46:16 +00:00
|
|
|
beforeEach(inject(($componentController, _$httpBackend_, $rootScope, _$state_) => {
|
2018-05-11 09:16:16 +00:00
|
|
|
$scope = $rootScope.$new();
|
|
|
|
$scope.confirmation = {show: () => {
|
|
|
|
return {
|
|
|
|
then: () => {}
|
|
|
|
};
|
|
|
|
}};
|
|
|
|
$scope.watcher = {
|
|
|
|
submit: () => {
|
|
|
|
return {
|
|
|
|
then: callback => {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
client = {credit: 0};
|
|
|
|
$state = _$state_;
|
|
|
|
$state.params.id = 101;
|
|
|
|
$httpBackend = _$httpBackend_;
|
2020-03-17 10:17:50 +00:00
|
|
|
const $element = angular.element('<vn-client-credit-create></vn-client-credit-create>');
|
|
|
|
controller = $componentController('vnClientCreditCreate', {$element, $scope});
|
2018-05-11 09:16:16 +00:00
|
|
|
}));
|
2018-07-31 09:54:54 +00:00
|
|
|
|
2018-05-11 09:16:16 +00:00
|
|
|
describe('onSubmit()', () => {
|
|
|
|
it('should perform a query to check (GET) if the client has an active recovery', () => {
|
2019-10-24 22:53:53 +00:00
|
|
|
$httpBackend.whenGET(`Recoveries/101/hasActiveRecovery`).respond(true);
|
|
|
|
$httpBackend.expectGET(`Recoveries/101/hasActiveRecovery`);
|
2018-05-11 09:16:16 +00:00
|
|
|
controller.onSubmit();
|
|
|
|
$httpBackend.flush();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should call show() method when the client have a recovery', () => {
|
2020-03-17 10:17:50 +00:00
|
|
|
jest.spyOn(controller.$.confirmation, 'show');
|
2019-10-24 22:53:53 +00:00
|
|
|
$httpBackend.whenGET(`Recoveries/101/hasActiveRecovery`).respond(true);
|
|
|
|
$httpBackend.expectGET(`Recoveries/101/hasActiveRecovery`);
|
2018-05-11 09:16:16 +00:00
|
|
|
controller.onSubmit();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
2020-03-17 10:17:50 +00:00
|
|
|
expect(controller.$.confirmation.show).toHaveBeenCalledWith();
|
2018-05-11 09:16:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should call addCredit() method when the client doesnt have a recovery', () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller, 'addCredit');
|
2019-10-24 22:53:53 +00:00
|
|
|
$httpBackend.whenGET(`Recoveries/101/hasActiveRecovery`).respond(false);
|
|
|
|
$httpBackend.expectGET(`Recoveries/101/hasActiveRecovery`);
|
2018-05-11 09:16:16 +00:00
|
|
|
controller.onSubmit();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.addCredit).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
2018-07-31 09:54:54 +00:00
|
|
|
|
2018-08-10 15:13:25 +00:00
|
|
|
describe('cancel()', () => {
|
2018-10-17 07:28:38 +00:00
|
|
|
it('should call goToIndex()', () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller, 'goToIndex');
|
2018-10-17 07:28:38 +00:00
|
|
|
controller.cancel();
|
2018-08-10 15:13:25 +00:00
|
|
|
|
|
|
|
expect(controller.goToIndex).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-05-11 09:16:16 +00:00
|
|
|
describe('returnDialog()', () => {
|
2019-10-30 15:57:14 +00:00
|
|
|
it('should call addCredit() when is called with accept', () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller, 'addCredit');
|
2020-07-29 08:54:45 +00:00
|
|
|
controller.returnDialog();
|
2018-05-11 09:16:16 +00:00
|
|
|
|
|
|
|
expect(controller.addCredit).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
2018-07-31 09:54:54 +00:00
|
|
|
|
2018-05-11 09:16:16 +00:00
|
|
|
describe('addCredit()', () => {
|
|
|
|
it('should call the function go() on $state to go to the credit list', () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn($state, 'go');
|
2018-05-11 09:16:16 +00:00
|
|
|
client.credit = 1;
|
|
|
|
controller.addCredit();
|
|
|
|
|
2018-05-24 13:02:38 +00:00
|
|
|
expect(controller.$state.go).toHaveBeenCalledWith('client.card.credit.index');
|
2018-05-11 09:16:16 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|