2018-05-23 12:26:51 +00:00
|
|
|
import './index';
|
2018-03-14 10:36:57 +00:00
|
|
|
|
2018-08-09 11:21:15 +00:00
|
|
|
describe('Client', () => {
|
2018-05-24 13:02:38 +00:00
|
|
|
describe('Component vnClientCreditInsuranceIndex', () => {
|
2018-03-14 10:36:57 +00:00
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
2020-03-17 10:17:50 +00:00
|
|
|
let $scope;
|
2018-03-14 10:36:57 +00:00
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('client'));
|
2018-03-14 10:36:57 +00:00
|
|
|
|
2020-07-23 14:46:16 +00:00
|
|
|
beforeEach(inject(($componentController, _$httpBackend_, $rootScope) => {
|
2018-03-14 10:36:57 +00:00
|
|
|
$httpBackend = _$httpBackend_;
|
2020-03-17 10:17:50 +00:00
|
|
|
$scope = $rootScope.$new();
|
|
|
|
const $element = angular.element('<vn-client-credit-insurance-index></vn-client-credit-insurance-index>');
|
|
|
|
controller = $componentController('vnClientCreditInsuranceIndex', {$element, $scope});
|
2018-08-09 10:54:29 +00:00
|
|
|
controller.client = {id: 101};
|
2018-03-14 10:36:57 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
describe('_getClassifications()', () => {
|
|
|
|
it('should perform a GET query to define the classifications property in the controller', () => {
|
|
|
|
let res = ['some classifications'];
|
2019-10-24 22:53:53 +00:00
|
|
|
let query = 'CreditClassifications?filter=%7B%22order%22%3A%22finished%20ASC%2C%20started%20DESC%22%2C%22include%22%3A%5B%7B%22relation%22%3A%22insurances%22%2C%22scope%22%3A%7B%22fields%22%3A%5B%22id%22%2C%22credit%22%2C%22created%22%2C%22grade%22%5D%2C%22order%22%3A%22created%20DESC%22%2C%22limit%22%3A2%7D%7D%5D%2C%22where%22%3A%7B%7D%7D';
|
2018-03-14 10:36:57 +00:00
|
|
|
|
|
|
|
$httpBackend.whenGET(query).respond(res);
|
|
|
|
$httpBackend.expectGET(query);
|
|
|
|
controller._getClassifications();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.classifications).toEqual(['some classifications']);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('canCreateNew()', () => {
|
|
|
|
it(`should return false if doesn't have classifications`, () => {
|
|
|
|
let result = controller.canCreateNew();
|
|
|
|
|
|
|
|
expect(result).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`should return false if finds a classification without due date`, () => {
|
|
|
|
controller.classifications = [
|
|
|
|
{finished: Date.now()},
|
|
|
|
{finished: null}
|
|
|
|
];
|
|
|
|
|
|
|
|
let result = controller.canCreateNew();
|
|
|
|
|
|
|
|
expect(result).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`should return true if all classifications are defined with due date`, () => {
|
|
|
|
controller.classifications = [
|
|
|
|
{finished: Date.now()},
|
|
|
|
{finished: Date.now()}
|
|
|
|
];
|
|
|
|
|
|
|
|
let result = controller.canCreateNew();
|
|
|
|
|
|
|
|
expect(result).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('closeContract()', () => {
|
2018-04-03 14:10:39 +00:00
|
|
|
it('should define the classificationId property of the controller and then call the show method()', () => {
|
2020-03-17 10:17:50 +00:00
|
|
|
controller.$.closeContract = {show: () => {}};
|
|
|
|
jest.spyOn(controller.$.closeContract, 'show');
|
2018-05-31 12:48:10 +00:00
|
|
|
|
2018-04-03 14:10:39 +00:00
|
|
|
expect(controller.classificationId).toBeFalsy();
|
|
|
|
controller.closeContract({id: 1});
|
|
|
|
|
|
|
|
expect(controller.classificationId).toEqual(1);
|
2020-03-17 10:17:50 +00:00
|
|
|
expect(controller.$.closeContract.show).toHaveBeenCalledWith();
|
2018-05-31 12:48:10 +00:00
|
|
|
});
|
2018-03-14 10:36:57 +00:00
|
|
|
});
|
2018-08-09 10:54:29 +00:00
|
|
|
|
|
|
|
describe('returnDialog()', () => {
|
|
|
|
it('should call the returnDialog method and perform a PATCH query, then call _getClassifications method', () => {
|
2020-02-27 06:19:42 +00:00
|
|
|
jest.spyOn(controller, '_getClassifications').mockReturnThis();
|
2018-08-09 10:54:29 +00:00
|
|
|
controller.classificationId = 1;
|
2020-07-23 15:10:07 +00:00
|
|
|
$httpBackend.expect('PATCH', `CreditClassifications/1`).respond(200);
|
2020-07-29 08:47:48 +00:00
|
|
|
controller.returnDialog();
|
2018-08-09 10:54:29 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller._getClassifications).toHaveBeenCalledWith(101);
|
|
|
|
});
|
|
|
|
});
|
2018-03-14 10:36:57 +00:00
|
|
|
});
|
|
|
|
});
|