import './index'; describe('Ticket', () => { describe('Component vnTicketWeeklyCreate', () => { let $componentController; let $scope; let $state; let controller; beforeEach(angular.mock.module('ticket', $translateProvider => { $translateProvider.translations('en', {}); })); beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$state_) => { $componentController = _$componentController_; $scope = $rootScope.$new(); $state = _$state_; $scope.watcher = { submit: () => { return { then: callback => { callback({data: {id: '1234'}}); } }; } }; controller = $componentController('vnTicketWeeklyCreate', {$scope, $state}); })); describe('onChangeTicket() setter', () => { it(`should define clientFk and warehouseFk properties on ticketWeekly object`, () => { controller.onChangeTicket({clientFk: 101, warehouseFk: 1}); expect(controller.ticketWeekly.clientFk).toEqual(101); expect(controller.ticketWeekly.warehouseFk).toEqual(1); }); }); describe('clientSelection() setter', () => { it(`should define salesPersonFk property on ticketWeekly object`, () => { controller.clientSelection = {clientFk: 101, salesPersonFk: 106}; expect(controller.ticketWeekly.salesPersonFk).toEqual(106); }); }); describe('onSubmit()', () => { it(`should call submit() on the watcher then expect a callback`, () => { spyOn(controller.$state, 'go'); controller.ticketWeekly = { ticketFk: 11, weekDay: 0 }; controller.onSubmit(); expect(controller.$state.go).toHaveBeenCalledWith('ticket.weekly.index'); }); }); }); });