describe('Test TicketController', function() { var element, scope, compile, rootScope, $httpBackend, events, createController, $q; beforeEach(module('myitsmApp', 'templates')); beforeEach(function () { inject(function ($compile, $rootScope, $injector, _events_, $controller, _$q_, ticketModel, screenConfigurationModel, categoriesService, approvalService, metadataModel, relationModel) { $httpBackend = $injector.get('$httpBackend'); this.ticketModel = ticketModel; this.screenConfigurationModel = screenConfigurationModel; this.categoriesService = categoriesService; this.approvalService = approvalService; this.metadataModel = metadataModel; this.relationModel = relationModel; var getLocale = function () { return readJSON('scripts/app/i18n/resources-locale_en.json'); }, deferred = _$q_.defer(), getTicketInfo = function (type, isMcsmTicket) { var mockFileName = 'mocks/' + type + '.json', response = readJSON(mockFileName); if (isMcsmTicket) { response[0].items[0].brokerVendorName = 'AWS'; } return response; }, getIncidentMetadata = function () { return readJSON('mocks/incident-metadata.json'); }, getIncidentScreenLayout = function () { return readJSON('mocks/incident-screenlayout.json'); }, getChangeScreenLayout = function () { return readJSON('mocks/changeViewLayout.json'); }, getIncidentScreenFieldMetadata = function () { return readJSON('mocks/incident-field-metadata.json'); }, getChangeScreenFieldMetadata = function () { return readJSON('mocks/incident-field-metadata.json'); }, getMetadataGlobal = function () { return readJSON('mocks/metadata-global.json'); }, getMetadataAllTypes = function () { return readJSON('mocks/metadata-allTypes.json'); }, getActionInfo = function () { return readJSON('mocks/action.json'); }, getMcsmInfo = function (type) { var mockFileName = 'mocks/' + type + '-mcsm.json'; return readJSON(mockFileName); }, getIncidentDataOnModify = function () { return readJSON('mocks/incident-put.json'); }, getApprovalData = function () { return readJSON('mocks/approval.json'); }; $httpBackend.whenGET(/^scripts\/app\/i18n\/resources-locale_en.*$/).respond(getLocale()); $httpBackend.whenGET('/smartit/rest/sessionstatus?getLicenseKey=true').respond(''); $httpBackend.whenGET('/smartit/rest/sberequest/23').respond(''); $httpBackend.whenGET('/smartit/rest/serverstates').respond(''); $httpBackend.whenGET("/smartit/rest/v2/metadata?type=incident").respond(getIncidentMetadata()); $httpBackend.whenGET('/smartit/rest/v2/metadata?type=global').respond(getMetadataGlobal()); $httpBackend.whenGET('/smartit/rest/v2/metadata?type=incident&type=workorder&type=task&type=request&type=change&type=asset&type=outage&type=problem&type=knownerror&type=dlp&type=release&type=activity').respond(getMetadataAllTypes()); $httpBackend.whenGET('/smartit/restapi/person/supportgroupperson').respond('[{"items": []}]'); $httpBackend.whenGET(/^\/smartit\/rest\/attachment\/info\/incident/).respond(''); $httpBackend.whenGET(/^\/smartit\/rest\/relations\/*\//).respond('[{"items": [{"objects": [], "totalMatches": 0}], "numMatch": 0}]'); $httpBackend.whenGET(/^\/smartit\/rest\/foundation\/items/).respond('[{"items": [{"objects": [], "totalMatches": 0}], "numMatch": 0}]'); $httpBackend.whenGET(/^\/smartit\/rest\/action\/search?/).respond(getActionInfo()); $httpBackend.whenGET('/smartit/rest/v2/customization/screenlayout?screen=incidentViewScreen').respond(getIncidentScreenLayout()); $httpBackend.whenGET('/smartit/rest/v2/customization/screenlayout?screen=changeViewScreen').respond(getChangeScreenLayout()); $httpBackend.whenGET('/smartit/rest/v2/customization/application/search?name=Galileo&phase=2&screen=incidentViewScreen').respond(getIncidentScreenFieldMetadata()); $httpBackend.whenGET('/smartit/rest/v2/customization/application/search?name=Galileo&phase=2&screen=changeViewScreen').respond(getChangeScreenFieldMetadata()); $httpBackend.whenGET('/smartit/rest/customization/field/summary/search?datasource=change').respond(200, {}); $httpBackend.whenGET('/smartit/rest/v3/action/search?resourceType=incident').respond(200, [{items: [{actionList:[]}]}]); $httpBackend.whenGET('/smartit/rest/v3/action/search?resourceType=change').respond(200, [{items: [{actionList:[]}]}]); $httpBackend.whenGET('/smartit/rest/customization/field/summary/search?datasource=incident').respond({}); $httpBackend.whenGET('/smartit/rest/v2/incident/1234').respond(getTicketInfo(EntityVO.TYPE_INCIDENT)); $httpBackend.whenGET('/smartit/rest/v2/incident/1234_mcsm').respond(getTicketInfo(EntityVO.TYPE_INCIDENT, true)); $httpBackend.whenGET('/smartit/rest/change/1234').respond(getTicketInfo(EntityVO.TYPE_CHANGE)); $httpBackend.whenGET('/smartit/rest/change/1234_mcsm').respond(getTicketInfo(EntityVO.TYPE_CHANGE, true)); $httpBackend.whenGET(/^\/smartit\/rest\/change\/plans\//).respond('[{"items": [{"objects": [], "totalMatches": 0}], "numMatch": 0}]'); $httpBackend.whenPOST('/smartit/rest/change/collisions/get').respond('[{"items": [{"objects": [], "totalMatches": 0}], "numMatch": 0}]'); $httpBackend.whenGET('/smartit/rest/mcsm/incident/remedy/INC1324').respond(getMcsmInfo(EntityVO.TYPE_INCIDENT)); $httpBackend.whenGET('/smartit/rest/mcsm/change/remedy/CRQ322').respond(getMcsmInfo(EntityVO.TYPE_CHANGE)); $httpBackend.whenPOST('/smartit/rest/asset/relationshiptypes').respond('[]'); $httpBackend.whenGET(/^\/smartit\/rest\/asset\/impactjob\//).respond('[{ "items": [{}], "numMatch": 1}]'); spyOn(this.ticketModel, 'update').and.callFake(function () { deferred.resolve(getIncidentDataOnModify()); return deferred.promise; }); spyOn(this.screenConfigurationModel, 'loadScreenConfigurationAndCustomFieldLabels').and.callFake(function () { var deferred = _$q_.defer(); deferred.resolve(getIncidentScreenFieldMetadata()); return deferred.promise; }); spyOn(this.categoriesService, 'checkCategoryTierData').and.callFake(function () { var deferred = _$q_.defer(); deferred.resolve(true); return deferred.promise; }); spyOn(this.approvalService, 'getListOfApprovers').and.callFake(function () { deferred.resolve(getApprovalData()); return deferred.promise; }); spyOn(this.metadataModel, 'getMetadataByType').and.callFake(function () { deferred.resolve(getMetadataGlobal()); return deferred.promise; }); spyOn(this.relationModel, 'getRelations').and.callFake(function () { deferred.resolve(true); return deferred.promise; }); compile = $compile; rootScope = $rootScope; scope = $rootScope.$new(); events = _events_; $q = _$q_; createController = function () { return $controller('TicketController', { $scope: scope }); }; }); }); function getCompiledElement(type, isMcsmTicket) { var ticketViewFileName = '"\'views/ticket/' + type + '-details.html\'" '; element = angular.element('