import './index'; describe('component vnEntrySummary', () => { let controller; let $httpBackend; let $scope; beforeEach(angular.mock.module('entry', $translateProvider => { $translateProvider.translations('en', {}); })); beforeEach(inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => { $httpBackend = _$httpBackend_; $scope = $rootScope.$new(); const $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 = `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'); }); }); describe('getBuys()', () => { it('should perform a get asking for the buys of an entry', () => { controller._entry = {id: 999}; const thatQuery = `Entries/${controller._entry.id}/getEntry`; const query = `Entries/${controller._entry.id}/getBuys`; $httpBackend.whenGET(thatQuery).respond('My Entries'); $httpBackend.expectGET(query).respond('Some buys'); controller.getBuys(); $httpBackend.flush(); expect(controller.buys).toEqual('Some buys'); }); }); });