import './index.js'; describe('ticket', () => { describe('Component vnTicketIndex', () => { let $componentController; let controller; beforeEach(() => { angular.mock.module('ticket'); }); beforeEach(angular.mock.inject(_$componentController_ => { $componentController = _$componentController_; controller = $componentController('vnTicketIndex'); })); describe('exprBuilder()', () => { it('should return a formated object with the id in case of search', () => { let param = 'search'; let value = 1; let result = controller.exprBuilder(param, value); expect(result).toEqual({id: 1}); }); it('should return a formated object with the nickname in case of search', () => { let param = 'search'; let value = 'Bruce'; let result = controller.exprBuilder(param, value); expect(result).toEqual({nickname: {like: 'Bruce'}}); }); it('should return a formated object with the date in case of from', () => { let param = 'from'; let value = 'Fri Aug 10 2018 11:39:21 GMT+0200'; let result = controller.exprBuilder(param, value); expect(result).toEqual({shipped: {gte: 'Fri Aug 10 2018 11:39:21 GMT+0200'}}); }); it('should return a formated object with the date in case of to', () => { let param = 'to'; let value = 'Fri Aug 10 2018 11:39:21 GMT+0200'; let result = controller.exprBuilder(param, value); expect(result).toEqual({shipped: {lte: 'Fri Aug 10 2018 11:39:21 GMT+0200'}}); }); it('should return a formated object with the nickname in case of nickname', () => { let param = 'nickname'; let value = 'Bruce'; let result = controller.exprBuilder(param, value); expect(result).toEqual({nickname: {like: 'Bruce'}}); }); it('should return a formated object with the warehouseFk in case of warehouseFk', () => { let param = 'warehouseFk'; let value = 'Silla'; let result = controller.exprBuilder(param, value); expect(result).toEqual({warehouseFk: 'Silla'}); }); }); describe('compareDate()', () => { it('should return warning when the date is the present', () => { let date = new Date(); let result = controller.compareDate(date); expect(result).toEqual('warning'); }); it('should return sucess when the date is in the future', () => { let futureDate = '2518-05-19T00:00:00.000Z'; let result = controller.compareDate(futureDate); expect(result).toEqual('success'); }); }); describe('preview()', () => { it('should call preventDefault and stopImmediatePropagation from event and show', () => { let event = jasmine.createSpyObj('event', ['preventDefault', 'stopImmediatePropagation']); controller.$scope = {dialogSummaryTicket: {show: () => {}}}; spyOn(controller.$scope.dialogSummaryTicket, 'show'); let ticket = {}; controller.preview(event, ticket); expect(event.preventDefault).toHaveBeenCalledWith(); expect(event.stopImmediatePropagation).toHaveBeenCalledWith(); expect(controller.$scope.dialogSummaryTicket.show).toHaveBeenCalledWith(); }); }); }); });