import './index'; describe('Ticket Component vnTicketSearchPanel', () => { let $httpBackend; let controller; beforeEach(ngModule('ticket')); beforeEach(inject(($componentController, _$httpBackend_) => { $httpBackend = _$httpBackend_; controller = $componentController('vnTicketSearchPanel', {$element: null}); controller.$t = () => {}; controller.filter = {}; })); describe('getGroupedStates()', () => { it('should set an array of groupedStates with the adition of a name translation', () => { jest.spyOn(controller, '$t').mockReturnValue('miCodigo'); const data = [ { alertLevel: 9999, code: 'myCode' } ]; $httpBackend.whenGET('AlertLevels').respond(data); controller.getGroupedStates(); $httpBackend.flush(); expect(controller.groupedStates).toEqual([{ alertLevel: 9999, code: 'myCode', name: 'miCodigo' }]); }); }); describe('from() setter', () => { it('should clear the scope days when setting the from property', () => { controller.filter.scopeDays = 1; controller.from = new Date(); expect(controller.filter.scopeDays).toBeNull(); expect(controller.from).toBeDefined(); }); }); describe('to() setter', () => { it('should clear the scope days when setting the to property', () => { controller.filter.scopeDays = 1; controller.to = new Date(); expect(controller.filter.scopeDays).toBeNull(); expect(controller.to).toBeDefined(); }); }); describe('scopeDays() setter', () => { it('should clear the date range when setting the scopeDays property', () => { controller.filter.from = new Date(); controller.filter.to = new Date(); controller.scopeDays = 1; expect(controller.filter.from).toBeNull(); expect(controller.filter.to).toBeNull(); expect(controller.scopeDays).toBeDefined(); }); }); });