import './index'; describe('Ticket', () => { describe('Component vnTicketSummary', () => { let controller; let $httpBackend; beforeEach(ngModule('ticket')); beforeEach(inject(($componentController, _$httpBackend_) => { $httpBackend = _$httpBackend_; const $element = angular.element(''); controller = $componentController('vnTicketSummary', {$element}); controller.ticket = {id: 1}; })); describe('ticket()', () => { it('should perform a GET query and define the summary property', () => { let res = {id: 1, nickname: 'Batman'}; $httpBackend.when('GET', `Tickets/1/summary`).respond(200, res); controller.ticket = {id: 1}; $httpBackend.flush(); expect(controller.summary).toBeDefined(); expect(controller.summary.nickname).toEqual('Batman'); }); }); describe('formattedAddress()', () => { it('should return the full fromatted address with city and province', () => { controller.summary = { address: { province: { name: 'Gotham' }, street: '1007 Mountain Drive', postalCode: 46060, city: 'Gotham' } }; expect(controller.formattedAddress).toEqual('1007 Mountain Drive - 46060 - Gotham (Gotham)'); }); }); describe('changeState()', () => { it('should change the state', () => { jest.spyOn(controller.vnApp, 'showSuccess'); const value = 'myTicketState'; let res = {id: 1, nickname: 'myNickname'}; $httpBackend.when('GET', `Tickets/1/summary`).respond(200, res); $httpBackend.expectPOST(`TicketTrackings/changeState`).respond(200, 'ok'); controller.changeState(value); $httpBackend.flush(); expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); }); }); }); });