import './index.js'; import crudModel from 'core/mocks/crud-model'; describe('Claim', () => { describe('Component summary', () => { let controller; let $httpBackend; let $scope; beforeEach(ngModule('claim')); beforeEach(inject(($componentController, _$httpBackend_, $rootScope) => { $scope = $rootScope.$new(); $httpBackend = _$httpBackend_; const $element = angular.element(''); controller = $componentController('vnClaimSummary', {$element, $scope}); controller.claim = {id: 1}; controller.$.model = crudModel; })); describe('loadData()', () => { it('should perform a query to set summary', () => { $httpBackend.when('GET', `Claims/1/getSummary`).respond(200, 24); controller.loadData(); $httpBackend.flush(); expect(controller.summary).toEqual(24); }); }); describe('changeState()', () => { it('should make an HTTP post query, then call the showSuccess(), reload() and resetChanges() methods', () => { jest.spyOn(controller.vnApp, 'showSuccess').mockReturnThis(); const expectedParams = {id: 1, claimStateFk: 1}; $httpBackend.when('GET', `Claims/1/getSummary`).respond(200, 24); $httpBackend.expect('PATCH', `Claims/updateClaim/1`, expectedParams).respond(200); controller.changeState(1); $httpBackend.flush(); expect(controller.vnApp.showSuccess).toHaveBeenCalled(); }); }); describe('$onChanges()', () => { it('should call loadData when item.id is defined', () => { jest.spyOn(controller, 'loadData'); controller.$onChanges(); expect(controller.loadData).toHaveBeenCalledWith(); }); }); }); });