import './index'; describe('component vnEntrySummary', () => { let controller; let $httpBackend; let $scope; let $element; beforeEach(angular.mock.module('entry', $translateProvider => { $translateProvider.translations('en', {}); })); beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => { $httpBackend = _$httpBackend_; $scope = $rootScope.$new(); $element = angular.element(``); controller = $componentController('vnEntrySummary', {$element, $scope}); })); describe('entry setter/getter', () => { it('should check if value.id is defined', () => { jest.spyOn(controller, 'getEntryData'); controller.entry = {id: 1}; expect(controller.getEntryData).toHaveBeenCalledWith(); }); it('should return the entry and then call getEntryData()', () => { jest.spyOn(controller, 'getEntryData'); controller.entry = {id: 99}; expect(controller._entry.id).toEqual(99); expect(controller.getEntryData).toHaveBeenCalledWith(); }); }); describe('getEntryData()', () => { it('should perform a get and then store data on the controller', () => { controller._entry = {id: 999}; const query = `/api/Entries/${controller._entry.id}/getEntry`; $httpBackend.expectGET(query).respond('I am the entryData'); controller.getEntryData(); $httpBackend.flush(); expect(controller.entryData).toEqual('I am the entryData'); }); }); });