salix/modules/client/front/credit/create/index.spec.js

96 lines
3.5 KiB
JavaScript
Raw Normal View History

2018-05-23 12:26:51 +00:00
import './index';
describe('Client', () => {
describe('Component vnClientCreditCreate', () => {
let controller;
let $httpBackend;
let $state;
let $scope;
let client;
2019-09-13 14:09:14 +00:00
beforeEach(angular.mock.module('client', $translateProvider => {
$translateProvider.translations('en', {});
}));
beforeEach(angular.mock.inject(($componentController, _$httpBackend_, $rootScope, _$state_) => {
$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_;
controller = $componentController('vnClientCreditCreate', {$scope, $state});
}));
2018-07-31 09:54:54 +00:00
describe('onSubmit()', () => {
it('should perform a query to check (GET) if the client has an active recovery', () => {
$httpBackend.whenGET(`/client/api/Recoveries/101/hasActiveRecovery`).respond(true);
$httpBackend.expectGET(`/client/api/Recoveries/101/hasActiveRecovery`);
controller.onSubmit();
$httpBackend.flush();
});
it('should call show() method when the client have a recovery', () => {
spyOn(controller.$scope.confirmation, 'show');
$httpBackend.whenGET(`/client/api/Recoveries/101/hasActiveRecovery`).respond(true);
$httpBackend.expectGET(`/client/api/Recoveries/101/hasActiveRecovery`);
controller.onSubmit();
$httpBackend.flush();
expect(controller.$scope.confirmation.show).toHaveBeenCalledWith();
});
it('should call addCredit() method when the client doesnt have a recovery', () => {
spyOn(controller, 'addCredit');
$httpBackend.whenGET(`/client/api/Recoveries/101/hasActiveRecovery`).respond(false);
$httpBackend.expectGET(`/client/api/Recoveries/101/hasActiveRecovery`);
controller.onSubmit();
$httpBackend.flush();
expect(controller.addCredit).toHaveBeenCalledWith();
});
});
2018-07-31 09:54:54 +00:00
describe('cancel()', () => {
it('should call goToIndex()', () => {
spyOn(controller, 'goToIndex');
controller.cancel();
expect(controller.goToIndex).toHaveBeenCalledWith();
});
});
describe('returnDialog()', () => {
2018-05-21 10:03:36 +00:00
it('should call addCredit() when is called with ACCEPT', () => {
spyOn(controller, 'addCredit');
2018-05-21 10:03:36 +00:00
controller.returnDialog('ACCEPT');
expect(controller.addCredit).toHaveBeenCalledWith();
});
});
2018-07-31 09:54:54 +00:00
describe('addCredit()', () => {
it('should call the function go() on $state to go to the credit list', () => {
spyOn($state, 'go');
client.credit = 1;
controller.addCredit();
expect(controller.$state.go).toHaveBeenCalledWith('client.card.credit.index');
});
});
});
});