import './index'; import crudModel from 'core/mocks/crud-model'; describe('ticket weekly', () => { describe('Component vnTicketWeeklyIndex', () => { let controller; let $httpBackend; beforeEach(ngModule('ticket')); beforeEach(angular.mock.inject(($componentController, _$httpBackend_, $rootScope) => { $httpBackend = _$httpBackend_; const $scope = $rootScope.$new(); const $element = angular.element(''); controller = $componentController('vnTicketWeeklyIndex', {$element, $scope}); })); describe('onUpdate()', () => { it('should make a query and vnApp.showSuccess()', () => { jest.spyOn(controller.vnApp, 'showSuccess'); $httpBackend.expectPATCH(`TicketWeeklies`).respond(); controller.onUpdate('ticketFk', 'field', 'value'); $httpBackend.flush(); expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); }); }); describe('onDeleteWeeklyAccept()', () => { it('should make a query and showSuccess()', () => { controller.$.model = crudModel; controller.$.model.data = [{ticketFk: 'ticketFk'}]; jest.spyOn(controller.vnApp, 'showSuccess'); jest.spyOn(controller.$.model, 'remove'); $httpBackend.expectDELETE(`TicketWeeklies/ticketFk`).respond(); controller.onDeleteWeeklyAccept('ticketFk'); $httpBackend.flush(); expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); expect(controller.$.model.remove).toHaveBeenCalledWith(0); }); }); }); });