import './index.js'; describe('Item Component vnClaimDescriptor', () => { let $httpParamSerializer; let $httpBackend; let $element; let $scope; let controller; beforeEach(ngModule('claim')); beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => { $httpBackend = _$httpBackend_; $httpParamSerializer = _$httpParamSerializer_; $scope = $rootScope.$new(); $element = angular.element(''); controller = $componentController('vnClaimDescriptor', {$element, $scope}); controller.claim = {id: 2, clientFk: 101, client: {email: 'client@email'}}; })); describe('showPickupOrder()', () => { it('should open a new window showing a pickup order PDF document', () => { const params = { clientId: controller.claim.clientFk, claimId: controller.claim.id }; const serializedParams = $httpParamSerializer(params); let expectedPath = `api/report/claim-pickup-order?${serializedParams}`; jest.spyOn(window, 'open').mockReturnThis(); controller.showPickupOrder(); expect(window.open).toHaveBeenCalledWith(expectedPath); }); }); describe('confirmPickupOrder()', () => { it('should call confirmPickupOrder.show()', () => { controller.$.confirmPickupOrder = { show: jasmine.createSpy('show') }; controller.claim = {id: 2}; controller.confirmPickupOrder(); expect(controller.$.confirmPickupOrder.show).toHaveBeenCalledWith(); }); }); describe('sendPickupOrder(response)', () => { it('should make a query and call vnApp.showMessage() if the response is accept', () => { jest.spyOn(controller.vnApp, 'showMessage'); 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(); controller.sendPickupOrder('accept'); $httpBackend.flush(); expect(controller.vnApp.showMessage).toHaveBeenCalledWith('Notification sent!'); }); }); describe('confirmDeleteClaim()', () => { it('should call confirmDeleteClaim.show()', () => { controller.$.confirmDeleteClaim = { show: jasmine.createSpy('show') }; controller.claim = {id: 2}; controller.confirmDeleteClaim(); expect(controller.$.confirmDeleteClaim.show).toHaveBeenCalledWith(); }); }); describe('deleteClaime(response)', () => { it('should perform a query and call showSuccess if the response is accept', () => { let response = 'accept'; controller.claim = {id: 2}; jest.spyOn(controller.vnApp, 'showSuccess'); jest.spyOn(controller.$state, 'go'); $httpBackend.when('DELETE', `Claims/2`).respond(200); $httpBackend.expect('DELETE', `Claims/2`); controller.deleteClaim(response); $httpBackend.flush(); expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Claim deleted!'); expect(controller.$state.go).toHaveBeenCalledWith('claim.index'); }); }); });