import './index.js'; describe('Item Component vnClaimDescriptor', () => { let $httpParamSerializer; let $httpBackend; let controller; beforeEach(ngModule('claim')); beforeEach(angular.mock.inject(($componentController, _$httpBackend_, _$httpParamSerializer_) => { $httpBackend = _$httpBackend_; $httpParamSerializer = _$httpParamSerializer_; controller = $componentController('vnClaimDescriptor'); 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}`; spyOn(window, 'open'); controller.showPickupOrder(); expect(window.open).toHaveBeenCalledWith(expectedPath); }); }); describe('confirmPickupOrder()', () => { it('should call confirmPickupOrder.show()', () => { controller.$scope.confirmPickupOrder = { show: jasmine.createSpy('show') }; controller.claim = {id: 2}; controller.confirmPickupOrder(); expect(controller.$scope.confirmPickupOrder.show).toHaveBeenCalledWith(); }); }); describe('sendPickupOrder(response)', () => { it('should make a query and call vnApp.showMessage() if the response is accept', () => { 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.$scope.confirmDeleteClaim = { show: jasmine.createSpy('show') }; controller.claim = {id: 2}; controller.confirmDeleteClaim(); expect(controller.$scope.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}; spyOn(controller.vnApp, 'showSuccess'); 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'); }); }); });