/** * Created by prenge on 16-03-2018. */ describe('ticket action service', function () { 'use strict'; var deferred, deferredResult, $httpBackend; beforeEach(module('myitsmApp', 'ticketModule')); beforeEach(inject(function (ticketActionService, ticketModel, $injector, $resource, $q, $modal, $rootScope) { this.ticketActionService = ticketActionService; this.ticketModel = ticketModel; this.$resource = $resource; this.$q = $q; this.$modal = $modal; this.scope = $rootScope.$new(); deferred = $q.defer(); deferredResult = $q.defer(); $httpBackend = $injector.get('$httpBackend'); $httpBackend.whenGET('scripts/app/i18n/resources-locale_en-US.json').respond(200); $httpBackend.whenGET('/smartit/rest/sessionstatus?getLicenseKey=true').respond(200); $httpBackend.whenGET('/smartit/rest/serverstates').respond(200); $httpBackend.whenGET('views/dashboard/index.html').respond(200); })); beforeEach(function () { this.action = 'resume' this.ticket = { id: 'RLGAA5V0GEOXXAPFO83NPERWOYGGK6', type: 'release' }; this.scope.basicData = { id: '' }; this.scope.state = { dataIsLoading: false }; }); it('should run apply action ()', function () { this.ticketActionService.applyAction(this.ticket, this.action, this.scope); this.scope.basicData.id = this.ticket.id; expect(this.scope.basicData.id).toEqual(this.ticket.id); }); it('should call assign function and update ticket after saving', function () { this.ticket.type = 'incident'; var fakeModal = { result: { then: function (confirmCallback) { //Store the callbacks this.confirmCallBack = confirmCallback; deferred.resolve({originalObject: {}}); return deferred.promise; } }, close: function (item) { //The user clicked OK on the modal dialog this.result.confirmCallBack({}); } }, mockEvent = { currentTarget: { focus: function () {} } }; spyOn(this.$modal, 'open').and.returnValue(fakeModal); spyOn(this.scope, '$broadcast').and.callThrough(); this.ticketActionService.assign(mockEvent, false, this.ticket, this.scope, ''); fakeModal.close(); expect(this.scope.$broadcast).toHaveBeenCalledWith('afterSavedChanges', this.ticket); }); it('should update ticket when assign to me is called', function () { this.ticket.type = 'problem'; this.ticket.company = { name: 'Calbro' }; var mockEvent = { currentTarget: { focus: function () {} } }, person = { id: 'Allen', loginId: 'Allen', company: { name: 'Calbro' } }; person = new PersonVO().build(person); spyOn(this.ticketModel, 'getTicketAssigneePersons').and.callFake(function () { deferred.resolve({results: [person]}); return deferred.promise; }); spyOn(this.ticketModel, 'update').and.callFake(function () { var result = _.cloneDeep(this.ticket); result = new ProblemVO().build(result); result.assignee = { id: 'Francie', loginId: 'Francie', company: { name: 'Calbro' }, fullName: 'Francie Stafford' }; result.supportGroup = { id: 'SGP000000000011', name: 'Service Desk' }; result.coordinator = { id: 'Allen', loginId: 'Allen', company: { name: 'Calbro' }, fullName: 'Allen Allbrook' }; result.coordinatorGroup = { id: 'SGP000000000009', name: 'Backoffice Support' }; deferredResult.resolve(result); return deferredResult.promise; }); this.ticketActionService.assignToMe(mockEvent, 'problemcoordinator', false, this.ticket, this.scope); this.scope.$apply(); expect(this.ticket.assignee.id).toEqual('Francie'); expect(this.ticket.supportGroup.name).toEqual('Service Desk'); expect(this.ticket.coordinator.id).toEqual('Allen'); expect(this.ticket.coordinatorGroup.name).toEqual('Backoffice Support'); }); });