describe("Test Controller LaunchActionController", function() { 'use strict'; var scope, systemAlertService, $httpBackend, $log, $e, $q, rootScope, events, $timeout, createController, callback, objectValueMapperService, screenConfigurationModel, actionList, expressionEvaluatorService; beforeEach(module('myitsmApp', 'templates')); beforeEach(inject(function ($rootScope, _$httpBackend_, $controller, $injector, _screenConfigurationModel_, _systemAlertService_, _$log_, _$q_, _objectValueMapperService_, _expressionEvaluatorService_, _events_, _$timeout_) { scope = $rootScope.$new(); rootScope = $rootScope; var getLocale = function () { return readJSON('scripts/app/i18n/resources-locale_en.json'); }; $httpBackend = _$httpBackend_; $httpBackend.whenGET(/^scripts\/app\/i18n\/resources-locale_en.*$/).respond(200, getLocale()); $httpBackend.whenGET('/smartit/rest/v2/metadata?type=incident').respond(200, [{items: []}]); $httpBackend.when('POST', '/smartit/rest/v3/action/execute').respond(200); $httpBackend.whenGET('/smartit/rest/serverstates').respond(200); $httpBackend.whenGET('/smartit/rest/sessionstatus?getLicenseKey=true').respond(200); $httpBackend.whenGET('views/dashboard/index.html').respond(200); $httpBackend.whenGET('/smartit/rest/v2/metadata?type=global').respond(200, readJSON('mocks/metadata-global.json')); $httpBackend.whenGET('/smartit/restapi/person/supportgroupperson').respond(200); screenConfigurationModel = _screenConfigurationModel_; systemAlertService = _systemAlertService_; expressionEvaluatorService = _expressionEvaluatorService_; $log = _$log_; $q = _$q_; objectValueMapperService = _objectValueMapperService_; events = _events_; $timeout = _$timeout_; var deferred = $q.defer(), response = {}, actionResponse = new ActionVO(); actionList = [ { "resource": "incident", "actionType": "provider", "actionName": "PA_CHG_OTB_TO_OTB", "supportedPlatforms": [ "web" ], "url": "", "labels": { "default": "PA_CHG_OTBTO_OTB_Label" }, "sequenceNo": 1, "scope": {}, "target": "new", "mode": "both", "isOpen": false, "delete": false, "screenId": "AGGAA5V0HG8SIAOSYVXNABCS8RNIK3", "templateId": "IDGAA5V0HG8OSAP7DK8QP6GLRPETRX", "actionOrder": "", "mappings": [ { "type": "input-ticket", "mappedFieldId": 1000000000, "mappedFieldValue": "id" }, { "type": "output", "mappedFieldId": 1000000151, "mappedFieldValue": "desc" } ], "isExpression": false, "expressions": [ { "resource": "incident", "executeOn": "On Field Value Change", "condition": "$priority == 'High'", "sequenceNo": 1 } ], "mappedFields": [], "entryId": "000000000000001", "formName": "CHG:Infrastructure Change", "isSynchronous": true, "id": "AGGAA5V0HG8OSAP7F4UMP6I6DLFQIP", "label": "PA_CHG_OTBTO_OTB_Label" }, { "resource": "incident", "actionType": "provider", "actionName": "PA_CHG_OTB_TO_OTB", "supportedPlatforms": [ "web" ], "url": "", "labels": { "default": "PA_CHG_OTBTO_OTB_Label2" }, "sequenceNo": 1, "scope": {}, "target": "new", "mode": "both", "isOpen": false, "delete": false, "screenId": "AGGAA5V0HG8SIAOSYVXNABCS8RNIK2", "templateId": "IDGAA5V0HG8OSAP7DK8QP6GLRPETRX", "actionOrder": "", "mappings": [ { "type": "input-ticket", "mappedFieldId": 1000000151, "mappedFieldValue": "desc" }, { "type": "output", "mappedFieldId": 1000000150, "mappedFieldValue": "middleintial" } ], "isExpression": false, "expressions": [ { "resource": "incident", "executeOn": "On Field Value Change", "condition": "$desc == 'description'", "sequenceNo": 2 } ], "mappedFields": [], "entryId": "000000000000002", "formName": "CHG:Infrastructure Change", "isSynchronous": true, "id": "AGGAA5V0HG8OSAP7F4UMP6I6DLABCD", "label": "PA_CHG_OTBTO_OTB_Label2" } ]; scope.context = new TicketVO(); scope.launchActionCallback = function() {}; scope.context.type = EntityVO.TYPE_INCIDENT; scope.context.id = "cid"; callback = function() {}; spyOn(screenConfigurationModel, 'loadActionsNew').and.callFake(function () { screenConfigurationModel.actionList = actionList; deferred.resolve(actionResponse); return deferred.promise; }); spyOn(screenConfigurationModel, 'getTemplateById').and.callFake(function () { deferred.resolve(response); return deferred.promise; }); spyOn(screenConfigurationModel, 'executeProviderAction').and.callFake(function () { deferred.resolve(response); return deferred.promise; }); spyOn(objectValueMapperService, 'setFieldActionMapping'); spyOn(objectValueMapperService, 'addToProviderActionExpressionMapper'); createController = function () { return $controller('LaunchActionController', { '$scope': scope, '$log' : $log }); }; scope.providerActionsList = []; createController(); scope.$apply(); })); it(' should run launchAction method ',function(){ $e = document.createEvent("HTMLEvents"); scope.launchActionCallback = function() {}; scope.launchAction ({id:'1234213XSSD',name: 'test'},'provider',$e); scope.launchAction ({id:'1234213XSSD',name: 'test'},'launch',$e); scope.context.type = EntityVO.TYPE_WORKORDER; scope.launchAction ({id:'1234213XSSD',name: 'test'},'provider',$e); }); it(' should run showEditor method ',function(){ $e = document.createEvent("HTMLEvents"); var params = {}, ticketObj = new TicketVO(), contextId = 'w23sdfs'; scope.showEditor (callback,params,ticketObj, contextId ); }); it(' should run displaypromptModal method ',function(){ var params = {prompt:[{mappedFieldId:234234}]}, ticketObj = new TicketVO(), contextId = 'w23sdfs', templateId= 'sdf23423423'; scope.displaypromptModal (callback, params,templateId,ticketObj,contextId); }); describe('Input prompt dialog', function () { var characterField, numberField, cBoxField, dropDownField, radioField, dateOnlyField, dateTimeField, timeOnlyField, customTypeField; function removeModalContent($promptModal) { $promptModal.scope().cancelExecution(); $promptModal.scope().$digest(); $promptModal.remove(); } beforeEach(inject(function ($q, ticketModel) { characterField = new FieldVO().build({ name: 'characterField', type: FieldVO.prototype.CHARACTER_FIELD, dataType: FieldVO.prototype.DATA_TYPE_TEXT, id: 'text' }); numberField = new FieldVO().build({ name: 'numberField', type: FieldVO.prototype.NUMBER_FIELD, dataType: FieldVO.prototype.DATA_TYPE_INTEGER, id: 'number' }); cBoxField = new FieldVO().build({ name: 'cBoxField', type: FieldVO.prototype.STATIC_SELECTION_FIELD, dataType: FieldVO.prototype.DATA_TYPE_CHECKBOX, id: 'cbox', options: [{ index: 0, name: 'confirm', label: 'Confirm' }] }); dropDownField = new FieldVO().build({ name: 'dropDownField', type: FieldVO.prototype.STATIC_SELECTION_FIELD, dataType: FieldVO.prototype.DATA_TYPE_DROPDOWN, id: 'dropdown', ootb: true, options: [{ index: 0, name: 'opt1', label: 'Option 1' }, { index: 1, name: 'opt2', label: 'Option 2' }] }); radioField = new FieldVO().build({ name: 'radioField', type: FieldVO.prototype.STATIC_SELECTION_FIELD, dataType: FieldVO.prototype.DATA_TYPE_RADIO, id: 'cbox', ootb: true, options: [{ index: 0, name: 'yes', label: 'Yes' }, { index: 1, name: 'no', label: 'No' }] }); dateOnlyField = new FieldVO().build({ name: 'dateOnlyField', type: FieldVO.prototype.DATE_FIELD, dataType: FieldVO.prototype.DATA_TYPE_DATE, id: 'date' }); dateTimeField = new FieldVO().build({ name: 'dateTimeField', type: FieldVO.prototype.DATE_TIME_FIELD, dataType: FieldVO.prototype.DATA_TYPE_DATE_TIME, id: 'dateTime' }); timeOnlyField = new FieldVO().build({ name: 'timeOnlyField', type: FieldVO.prototype.DATE_TIME_FIELD, dataType: FieldVO.prototype.DATA_TYPE_TIME, id: 'time' }); customTypeField = new FieldVO().build({ name: 'customTypeField', type: 'customType', dataType: 'customDataType', id: 'custom' }); $httpBackend.whenGET(/smartit\/rest\/v2\/incident/).respond(200, [{ items: [{ id: 'incidentId', type: EntityVO.TYPE_INCIDENT }] }]); $httpBackend.whenGET(/smartit\/rest\/attachment\/info\/incident/).respond(200, [{ items: [] }]); spyOn(ticketModel, 'getTicket').and.callFake(function () { var fakeIncident = new IncidentVO().build({ id: 'test', type: EntityVO.TYPE_INCIDENT, accessMappings: { detailsEditAllowed:true } }); ticketModel.cache['test'] = fakeIncident; return $q.when(fakeIncident); }); // jasmine.clock().install(); })); afterEach(function () { var $promptDialog = angular.element(document).find('.provider-user-prompt'); $promptDialog.remove(); // jasmine.clock().uninstall() }); it('should open modal with different type of inputs', function () { var promptParams = [characterField, numberField, cBoxField, dropDownField, radioField, dateOnlyField, dateTimeField, timeOnlyField, customTypeField] .map(function (field) { return { type: 'input', defaultValue: '', mappedFieldId: field.id, mappedFieldName: field.name, mappedField: field } }); scope.showEditor(callback, { prompt: promptParams }, { resource: EntityVO.TYPE_INCIDENT }, 'incidentId'); scope.$apply(); var $promptModal = angular.element(document).find('.provider-user-prompt'), $textInput = $promptModal.find('input[name="characterField"]'), $customTypeField = $promptModal.find('input[name="customTypeField"]'), $numberInput = $promptModal.find('input[name="numberField"]'), $cBoxField = $promptModal.find('input[name="cBoxField"]'), $dropDownField = $promptModal.find('.select-custom-dropdown'), $radioField = $promptModal.find('.custom-field__radio'), $dateTimeField = $promptModal.find('.custom-field__date_time_container'), $dateOnlyField = $promptModal.find('.custom-field__date_single'), $timeOnlyField = $promptModal.find('.custom-field__time_single'); expect($promptModal.length).toEqual(1); expect($textInput[0]).toBeDefined(); expect($numberInput[0]).toBeDefined(); expect($customTypeField[0]).toBeDefined(); expect($cBoxField[0]).toBeDefined(); expect($dropDownField[0]).toBeDefined(); expect($radioField[0]).toBeDefined(); expect($dateTimeField[0]).toBeDefined(); expect($dateOnlyField[0]).toBeDefined(); expect($timeOnlyField[0]).toBeDefined(); expect($numberInput[0].type).toBe('number'); expect($customTypeField[0].type).toBe('text'); expect($cBoxField[0].type).toBe('checkbox'); expect($radioField.find('input[name="radioField"]').length).toEqual(2); expect($radioField.find('input[name="radioField"]')[0].type).toBe('radio'); }); it('should set default value for text and number fields', function () { var promptParams = [characterField, numberField, customTypeField].map(function (field) { var defaultValue; if (field.isTextField()) { defaultValue = 'text123'; } else if (field.isNumberField()) { defaultValue = 100; } else { defaultValue = 'custom123'; } return { type: 'input', defaultValue: defaultValue, mappedFieldId: field.id, mappedFieldName: field.name, mappedField: field } }); scope.showEditor(callback, { prompt: promptParams }, { resource: EntityVO.TYPE_INCIDENT }, 'incidentId'); scope.$apply(); var $promptModal = angular.element(document).find('.provider-user-prompt'), $textInput = $promptModal.find('input[name="characterField"]'), $customTypeField = $promptModal.find('input[name="customTypeField"]'), $numberInput = $promptModal.find('input[name="numberField"]'); expect($textInput[0].value).toBe('text123'); expect($customTypeField[0].value).toBe('custom123'); expect($numberInput[0].value).toBe('100'); }); it('should set default value for dropdown and radio fields', function () { var promptParams = [dropDownField, radioField].map(function (field) { return { type: 'input', defaultValue: 'wrongValue', mappedFieldId: field.id, mappedFieldName: field.name, mappedField: field } }); scope.showEditor(callback, { prompt: promptParams }, { resource: EntityVO.TYPE_INCIDENT }, 'incidentId'); scope.$apply(); var $promptModal = angular.element(document).find('.provider-user-prompt'), $dropdownInputButton = $promptModal.find('.select-custom-dropdown .dropdown-input__button'), $radioField = $promptModal.find('.custom-field__radio'), $radioFieldInputs = $radioField.find('input[type="radio"]'); expect(dropDownField.value).toBe(null); expect($dropdownInputButton.text()).not.toEqual('wrongValue'); expect($radioFieldInputs.length).toEqual(2); expect($radioFieldInputs.find('input:checked').length).toEqual(0); promptParams = [dropDownField, radioField].map(function (field) { var defaultValue = field.options[0].label; // name and index properties are valid for defaultValue as well return { type: 'input', defaultValue: defaultValue, mappedFieldId: field.id, mappedFieldName: field.name, mappedField: field } }); removeModalContent($promptModal); scope.showEditor(callback, { prompt: promptParams }, { resource: EntityVO.TYPE_INCIDENT }, 'incidentId2'); scope.$apply(); var $promptModal2 = angular.element(document).find('.provider-user-prompt'); $dropdownInputButton = $promptModal2.find('.select-custom-dropdown .dropdown-input__button'); $radioField = $promptModal2.find('.custom-field__radio'); var $checkedRadioFieldInputs = $radioField.find('input[type="radio"]:checked'); expect(dropDownField.value).toBe(dropDownField.options[0].name); expect($dropdownInputButton.text().trim()).toEqual(dropDownField.options[0].label); expect($checkedRadioFieldInputs.length).toEqual(1); }); it('should set for checkbox field', function () { var promptParams = [{ type: 'input', defaultValue: 'wrongValue', mappedFieldId: cBoxField.id, mappedFieldName: cBoxField.name, mappedField: cBoxField }]; scope.showEditor(callback, { prompt: promptParams }, { resource: EntityVO.TYPE_INCIDENT }, 'incidentId'); scope.$apply(); var $promptModal = angular.element(document).find('.provider-user-prompt'), cbox = $promptModal.find('input[type="checkbox"]'); expect(cbox.length).toEqual(1); expect(cbox.prop('checked')).toBe(false); removeModalContent($promptModal); promptParams = [{ type: 'input', defaultValue: 'true', mappedFieldId: cBoxField.id, mappedFieldName: cBoxField.name, mappedField: cBoxField }]; scope.showEditor(callback, { prompt: promptParams }, { resource: EntityVO.TYPE_INCIDENT }, 'incidentId'); scope.$apply(); var $promptModal2 = angular.element(document).find('.provider-user-prompt'), cbox2 = $promptModal2.find('input[type="checkbox"]'); expect(cbox2.prop('checked')).toBe(true); removeModalContent($promptModal2); promptParams = [{ type: 'input', defaultValue: 'checked', mappedFieldId: cBoxField.id, mappedFieldName: cBoxField.name, mappedField: cBoxField }]; scope.showEditor(callback, { prompt: promptParams }, { resource: EntityVO.TYPE_INCIDENT }, 'incidentId'); scope.$apply(); var $promptModal3 = angular.element(document).find('.provider-user-prompt'), cbox3 = $promptModal3.find('input[type="checkbox"]'); expect(cbox3.prop('checked')).toBe(true); removeModalContent($promptModal3); promptParams = [{ type: 'input', defaultValue: 0, mappedFieldId: cBoxField.id, mappedFieldName: cBoxField.name, mappedField: cBoxField }]; scope.showEditor(callback, { prompt: promptParams }, { resource: EntityVO.TYPE_INCIDENT }, 'incidentId'); scope.$apply(); expect(cbox3.prop('checked')).toBe(true); }); it('should set default value for date and date-time field', function () { var promptParams = [ { type: 'input', defaultValue: '25-01-2018', // wrong date string mappedFieldId: dateOnlyField.id, mappedFieldName: dateOnlyField.name, mappedField: dateOnlyField }, { type: 'input', defaultValue: '25-01-2018', // wrong date string mappedFieldId: dateTimeField.id, mappedFieldName: dateTimeField.name, mappedField: dateTimeField } ]; scope.showEditor(callback, { prompt: promptParams }, { resource: EntityVO.TYPE_INCIDENT }, 'incidentId'); scope.$apply(); expect(dateOnlyField.value).toBe(null); expect(dateTimeField.value).toBe(null); var $promptModal = angular.element(document).find('.provider-user-prompt'); removeModalContent($promptModal); promptParams[0].defaultValue = '29 January 2018'; promptParams[1].defaultValue = '1/29/2018'; scope.showEditor(callback, { prompt: promptParams }, { resource: EntityVO.TYPE_INCIDENT }, 'incidentId'); scope.$apply(); expect(dateOnlyField.value.valueOf()).toBe(moment('29 January 2018').valueOf()); expect(dateTimeField.value.valueOf()).toBe(moment('1/29/2018').valueOf()); var $promptModal2 = angular.element(document).find('.provider-user-prompt'); removeModalContent($promptModal2); promptParams[0].defaultValue = 1516860000000; promptParams[1].defaultValue = '1516860000000'; scope.showEditor(callback, { prompt: promptParams }, { resource: EntityVO.TYPE_INCIDENT }, 'incidentId'); scope.$apply(); expect(dateOnlyField.value.valueOf()).toBe(1516860000000); expect(dateTimeField.value.valueOf()).toBe(1516860000000); }); }); it(' should run getInputParams method ',function(){ var actionObj = new ActionVO(), ticketObj = new TicketVO(), contextId = 'w23sdfs'; actionObj.mappings = [{mappedFieldValue:'xvyz', type:'input-prompt', mappedFieldId: '23423423'},{mappedFieldValue:'abcd', type:'input-ticket', mappedFieldId: '23423423'},{mappedFieldValue:'test', type:'input-default', mappedFieldId: '23423423'}, {mappedFieldValue:'sdfds', type:'output', mappedFieldId: '23423423'}]; var test = scope.getInputParams (actionObj,ticketObj,callback, contextId); expect(test).toBeDefined(); }); it(' should run executeActionCallback method ',function(){ var params = {}, actionObj = new ActionVO(), contextId = 'w23sdfs'; scope.executeActionCallback(params,actionObj, contextId); actionObj.isSynchronous = true; scope.executeActionCallback(params,actionObj, contextId); scope.$apply(); }); it(' should run checkForOutputMapping method ',function(){ var actionObj = new ActionVO(); actionObj.mappings = [{mappedFieldValue:'xvyz', type:'input-prompt', mappedFieldId: '23423423'},{mappedFieldValue:'abcd', type:'input-ticket', mappedFieldId: '23423423'},{mappedFieldValue:'test', type:'input-default', mappedFieldId: '23423423'}, {mappedFieldValue:'sdfds', type:'output', mappedFieldId: '23423423'}]; var test = scope.checkForOutputMapping (actionObj); expect(test).toBeTruthy(); }); it('should run launchActionFromExpression method',function(){ var actionList = []; scope.launchActionFromExpression(actionList); actionList = [{action: {id:'1234213XSSD',name: 'test'}, actionId: '1234213XSSD',expression: 'status == "Assigned"'}]; scope.launchActionFromExpression(actionList); }); it('should run launchAction method from action expression',function(){ var calledFromActionExpression = true; scope.launchAction({id:'1234213XSSD',name: 'test', isSynchronous: true}, 'provider', null, calledFromActionExpression); }); it('should extract provider action expression to expression mapper on ticket load',function() { expect(scope.AssociateActionLists).toBe(screenConfigurationModel.actionList); expect(scope.actionLists).toBe(screenConfigurationModel.actionList); expect(objectValueMapperService.setFieldActionMapping).toHaveBeenCalledWith(scope.fieldActionMapping, EntityVO.TYPE_INCIDENT); expect(objectValueMapperService.addToProviderActionExpressionMapper).toHaveBeenCalledWith(scope.AssociateActionLists[0].expressions[0].condition, scope.AssociateActionLists[0]); }); it('should trigger PROVIDER_ACTION events handler and should launch action from expression if provider action expression condition is matched in case of only one provider action',function() { var data = [{ actionId: "AGGAA5V0HG8OSAP7F4UMP6I6DLFQIP", expression: "$priority == 'High'", action: actionList[0] }], providerActionOutput = {1000000151: 'description'}; spyOn(objectValueMapperService, 'getProviderActionsList').and.returnValue(data); spyOn(expressionEvaluatorService, 'evaluate').and.returnValue(true); spyOn(objectValueMapperService, 'setFieldFromProvider').and.callFake(function () { let deferred = $q.defer(); deferred.resolve(true); return deferred.promise; }); spyOn(rootScope, '$broadcast'); spyOn(systemAlertService, 'success'); spyOn(objectValueMapperService, 'clearProviderActionFromList').and.callFake(function () { scope.providerActionsList = []; }); spyOn(screenConfigurationModel, 'executeProviderActionV3').and.callFake(function () { let deferred = $q.defer(); deferred.resolve(providerActionOutput); return deferred.promise; }); scope.$emit(events.PROVIDER_ACTION, data); scope.$apply(); $timeout.flush(); expect(scope.providerActionsList.length).toBe(0); expect(screenConfigurationModel.executeProviderActionV3).toHaveBeenCalledWith(data[0].actionId, scope.context.id, {1000000000: ""}); expect(objectValueMapperService.setFieldFromProvider).toHaveBeenCalledWith(providerActionOutput, actionList[0].mappings); expect(rootScope.$broadcast).toHaveBeenCalledWith(events.OPEN_EDIT_MODE); expect(systemAlertService.success).toHaveBeenCalled(); expect(objectValueMapperService.clearProviderActionFromList).toHaveBeenCalledWith(data[0].action); }); it('should trigger PROVIDER_ACTION events handler and should launch action from expression if provider action expression condition is matched in case of two provider actions',function() { var data = [{ actionId: "AGGAA5V0HG8OSAP7F4UMP6I6DLFQIP", expression: "$priority == 'High'", action: actionList[0] }, { actionId: "AGGAA5V0HG8OSAP7F4UMP6I6DLABCD", expression: "desc == 'description'", action: actionList[1] }], providerActionOutput1 = {1000000151: 'description'}, providerActionOutput2 = {1000000150: 'description'}; spyOn(objectValueMapperService, 'getProviderActionsList').and.returnValue(data); spyOn(expressionEvaluatorService, 'evaluate').and.returnValue(true); spyOn(objectValueMapperService, 'setFieldFromProvider').and.callFake(function () { let deferred = $q.defer(); deferred.resolve(true); return deferred.promise; }); spyOn(rootScope, '$broadcast'); spyOn(systemAlertService, 'success'); spyOn(objectValueMapperService, 'clearProviderActionFromList').and.callFake(function () { scope.providerActionsList.shift(); }); spyOn(screenConfigurationModel, 'executeProviderActionV3').and.callFake(function (id) { let deferred = $q.defer(); id == 'AGGAA5V0HG8OSAP7F4UMP6I6DLFQIP' ? deferred.resolve(providerActionOutput1) : deferred.resolve(providerActionOutput2); return deferred.promise; }); scope.$emit(events.PROVIDER_ACTION, data); scope.$apply(); $timeout.flush(); expect(scope.providerActionsList.length).toBe(0); expect(screenConfigurationModel.executeProviderActionV3).toHaveBeenCalledWith(actionList[0].id, scope.context.id, {1000000000: ""}); expect(objectValueMapperService.setFieldFromProvider).toHaveBeenCalledWith(providerActionOutput1, actionList[0].mappings); expect(rootScope.$broadcast).toHaveBeenCalledWith(events.OPEN_EDIT_MODE); expect(systemAlertService.success).toHaveBeenCalled(); expect(objectValueMapperService.clearProviderActionFromList).toHaveBeenCalledWith(actionList[0]); expect(screenConfigurationModel.executeProviderActionV3).toHaveBeenCalledWith(actionList[1].id, scope.context.id, {1000000151: ""}); expect(objectValueMapperService.setFieldFromProvider).toHaveBeenCalledWith(providerActionOutput2, actionList[1].mappings); expect(objectValueMapperService.clearProviderActionFromList).toHaveBeenCalledWith(actionList[1]); }); it('should trigger PROVIDER_ACTION events handler and should launch action from expression if provider action expression condition is matched and there is an error while executing provider action',function() { var data = [{ actionId: "AGGAA5V0HG8OSAP7F4UMP6I6DLFQIP", expression: "$priority == 'High'", action: actionList[0] }], errorMsg = { data: { error: 'Server Issue' } }; actionList[0].mappings = [ { "type": "input-ticket", "mappedFieldId": 1000000000, "mappedFieldValue": "requiredResolutionDate" }, { "type": "output", "mappedFieldId": 1000000151, "mappedFieldValue": "desc" } ]; spyOn(objectValueMapperService, 'getProviderActionsList').and.returnValue(data); spyOn(expressionEvaluatorService, 'evaluate').and.returnValue(true); spyOn(objectValueMapperService, 'setFieldFromProvider').and.callFake(function () { let deferred = $q.defer(); deferred.resolve(true); return deferred.promise; }); spyOn(systemAlertService, 'error'); spyOn(objectValueMapperService, 'clearProviderActionFromList').and.callFake(function () { scope.providerActionsList = []; }); spyOn(screenConfigurationModel, 'executeProviderActionV3').and.callFake(function () { let deferred = $q.defer(); deferred.reject(errorMsg); return deferred.promise; }); scope.$emit(events.PROVIDER_ACTION, data); scope.$apply(); //$timeout.flush(); expect(scope.providerActionsList.length).toBe(0); expect(screenConfigurationModel.executeProviderActionV3).toHaveBeenCalledWith(data[0].actionId, scope.context.id, {1000000000: ""}); expect(systemAlertService.error).toHaveBeenCalledWith({text: errorMsg.data.error, clear: false}); expect(objectValueMapperService.clearProviderActionFromList).toHaveBeenCalledWith(data[0].action); }); });