2019-02-12 06:42:19 +00:00
|
|
|
import './index.js';
|
|
|
|
|
|
|
|
describe('Item Component vnClaimDescriptor', () => {
|
2019-11-06 08:32:54 +00:00
|
|
|
let $httpParamSerializer;
|
2019-02-12 06:42:19 +00:00
|
|
|
let $httpBackend;
|
2020-03-05 13:49:41 +00:00
|
|
|
let $element;
|
|
|
|
let $scope;
|
2019-02-12 06:42:19 +00:00
|
|
|
let controller;
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('claim'));
|
2019-02-12 06:42:19 +00:00
|
|
|
|
2020-03-05 13:49:41 +00:00
|
|
|
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => {
|
2019-02-12 06:42:19 +00:00
|
|
|
$httpBackend = _$httpBackend_;
|
2019-11-06 08:32:54 +00:00
|
|
|
$httpParamSerializer = _$httpParamSerializer_;
|
2020-03-05 13:49:41 +00:00
|
|
|
$scope = $rootScope.$new();
|
|
|
|
|
|
|
|
$element = angular.element('<vn-claim-descriptor></vn-claim-descriptor>');
|
|
|
|
controller = $componentController('vnClaimDescriptor', {$element, $scope});
|
2019-11-06 08:32:54 +00:00
|
|
|
controller.claim = {id: 2, clientFk: 101, client: {email: 'client@email'}};
|
2019-02-12 06:42:19 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
describe('showPickupOrder()', () => {
|
|
|
|
it('should open a new window showing a pickup order PDF document', () => {
|
2019-11-06 08:32:54 +00:00
|
|
|
const params = {
|
|
|
|
clientId: controller.claim.clientFk,
|
|
|
|
claimId: controller.claim.id
|
|
|
|
};
|
|
|
|
const serializedParams = $httpParamSerializer(params);
|
|
|
|
let expectedPath = `api/report/claim-pickup-order?${serializedParams}`;
|
2020-02-26 14:02:47 +00:00
|
|
|
jest.spyOn(window, 'open').mockReturnThis();
|
2019-02-12 06:42:19 +00:00
|
|
|
controller.showPickupOrder();
|
|
|
|
|
|
|
|
expect(window.open).toHaveBeenCalledWith(expectedPath);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('confirmPickupOrder()', () => {
|
|
|
|
it('should call confirmPickupOrder.show()', () => {
|
2020-03-05 13:49:41 +00:00
|
|
|
controller.$.confirmPickupOrder = {
|
2019-02-12 06:42:19 +00:00
|
|
|
show: jasmine.createSpy('show')
|
|
|
|
};
|
|
|
|
controller.claim = {id: 2};
|
|
|
|
controller.confirmPickupOrder();
|
|
|
|
|
2020-03-05 13:49:41 +00:00
|
|
|
expect(controller.$.confirmPickupOrder.show).toHaveBeenCalledWith();
|
2019-02-12 06:42:19 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('sendPickupOrder(response)', () => {
|
2019-10-30 15:57:14 +00:00
|
|
|
it('should make a query and call vnApp.showMessage() if the response is accept', () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller.vnApp, 'showMessage');
|
2019-02-12 06:42:19 +00:00
|
|
|
|
2019-11-06 08:32:54 +00:00
|
|
|
const params = {
|
|
|
|
recipient: 'client@email',
|
|
|
|
clientId: controller.claim.clientFk,
|
|
|
|
claimId: controller.claim.id
|
|
|
|
};
|
|
|
|
const serializedParams = $httpParamSerializer(params);
|
|
|
|
|
|
|
|
$httpBackend.when('GET', `email/claim-pickup-order?${serializedParams}`).respond();
|
|
|
|
$httpBackend.expect('GET', `email/claim-pickup-order?${serializedParams}`).respond();
|
2019-10-30 15:57:14 +00:00
|
|
|
controller.sendPickupOrder('accept');
|
2019-02-12 06:42:19 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('Notification sent!');
|
|
|
|
});
|
|
|
|
});
|
2019-06-14 07:29:23 +00:00
|
|
|
|
|
|
|
describe('confirmDeleteClaim()', () => {
|
|
|
|
it('should call confirmDeleteClaim.show()', () => {
|
2020-03-05 13:49:41 +00:00
|
|
|
controller.$.confirmDeleteClaim = {
|
2019-06-14 07:29:23 +00:00
|
|
|
show: jasmine.createSpy('show')
|
|
|
|
};
|
|
|
|
controller.claim = {id: 2};
|
|
|
|
controller.confirmDeleteClaim();
|
|
|
|
|
2020-03-05 13:49:41 +00:00
|
|
|
expect(controller.$.confirmDeleteClaim.show).toHaveBeenCalledWith();
|
2019-06-14 07:29:23 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('deleteClaime(response)', () => {
|
2019-10-30 15:57:14 +00:00
|
|
|
it('should perform a query and call showSuccess if the response is accept', () => {
|
|
|
|
let response = 'accept';
|
2019-06-14 07:29:23 +00:00
|
|
|
controller.claim = {id: 2};
|
|
|
|
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
|
|
|
jest.spyOn(controller.$state, 'go');
|
2019-10-24 22:53:53 +00:00
|
|
|
$httpBackend.when('DELETE', `Claims/2`).respond(200);
|
|
|
|
$httpBackend.expect('DELETE', `Claims/2`);
|
2019-06-14 07:29:23 +00:00
|
|
|
controller.deleteClaim(response);
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Claim deleted!');
|
|
|
|
expect(controller.$state.go).toHaveBeenCalledWith('claim.index');
|
|
|
|
});
|
|
|
|
});
|
2019-02-12 06:42:19 +00:00
|
|
|
});
|
|
|
|
|