import './index'; import crudModel from 'core/mocks/crud-model'; describe('Claim', () => { describe('Component vnClaimPhotos', () => { let $scope; let $httpBackend; let controller; beforeEach(ngModule('claim')); beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => { $httpBackend = _$httpBackend_; $scope = $rootScope.$new(); controller = $componentController('vnClaimPhotos', {$element: null, $scope}); controller.$.model = crudModel; controller.claim = { id: 1, client: {id: 101, name: 'Bruce Wayne'} }; })); describe('deleteDms()', () => { it('should make an HTTP Post query', () => { jest.spyOn(controller.vnApp, 'showSuccess'); jest.spyOn(controller.$.model, 'remove'); const dmsId = 1; const dmsIndex = 0; controller.photos = [{dmsFk: 1}]; $httpBackend.expectPOST(`ClaimDms/${dmsId}/removeFile`).respond(); controller.deleteDms(dmsIndex); $httpBackend.flush(); expect(controller.$.model.remove).toHaveBeenCalledWith(dmsIndex); expect(controller.vnApp.showSuccess).toHaveBeenCalled(); }); }); describe('setDefaultParams()', () => { it('should make an HTTP GET query, then set all dms properties', () => { $httpBackend.expectRoute('GET', `DmsTypes/findOne`).respond({}); controller.setDefaultParams(); $httpBackend.flush(); expect(controller.dms).toBeDefined(); }); }); describe('create()', () => { it('should make an HTTP Post query, then refresh the model data', () => { const claimId = 1; const dmsIndex = 0; jest.spyOn(controller.vnApp, 'showSuccess'); jest.spyOn(controller.$.model, 'refresh'); controller.photos = [{dmsFk: 1}]; controller.dmsIndex = dmsIndex; controller.dms = {files: []}; $httpBackend.expectPOST(`claims/${claimId}/uploadFile`).respond({}); controller.create(); $httpBackend.flush(); expect(controller.$.model.refresh).toHaveBeenCalled(); expect(controller.vnApp.showSuccess).toHaveBeenCalled(); }); }); }); });