import './index'; describe('component vnTravelSummary', () => { let controller; let $httpBackend; beforeEach(angular.mock.module('travel', $translateProvider => { $translateProvider.translations('en', {}); })); beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => { $httpBackend = _$httpBackend_; controller = $componentController('vnTravelSummary'); })); describe('travel setter/getter', () => { it('should return the travel', () => { controller.travel = {id: null}; expect(controller.travel).toEqual(jasmine.any(Object)); }); it('should return the travel and then call both getTravel() and getEntries()', () => { spyOn(controller, 'getTravel'); spyOn(controller, 'getEntries'); controller.travel = {id: 99}; expect(controller._travel.id).toEqual(99); expect(controller.getTravel).toHaveBeenCalledWith(); expect(controller.getEntries).toHaveBeenCalledWith(); }); }); describe('getTravel()', () => { it('should perform a get and then store data on the controller', () => { controller._travel = {id: 999}; const query = `/api/Travels/${controller._travel.id}/getTravel`; $httpBackend.expectGET(query).respond('I am the travelData'); controller.getTravel(); $httpBackend.flush(); expect(controller.travelData).toEqual('I am the travelData'); }); }); describe('getEntries()', () => { it('should call the getEntries method to get the entries data', () => { controller._travel = {id: 999}; const query = `/api/Travels/${controller._travel.id}/getEntries`; $httpBackend.expectGET(query).respond('I am the entries'); controller.getEntries(); $httpBackend.flush(); expect(controller.entries).toEqual('I am the entries'); }); }); });