320 lines
12 KiB
JavaScript
320 lines
12 KiB
JavaScript
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('<div><div ' +
|
|
'ng-controller="TicketController" ' +
|
|
'ng-include=' + ticketViewFileName +
|
|
'class="full-height"></div></div>');
|
|
|
|
scope.id = isMcsmTicket ? '1234_mcsm' : '1234';
|
|
scope.type = type;
|
|
scope.ticket = {};
|
|
scope.progress = {};
|
|
|
|
var directiveElem = compile(element)(scope);
|
|
|
|
scope.$digest();
|
|
|
|
$httpBackend.flush();
|
|
|
|
return directiveElem;
|
|
}
|
|
|
|
it('should compile', function () {
|
|
var directiveElem = getCompiledElement(EntityVO.TYPE_INCIDENT),
|
|
divElem = directiveElem[0];
|
|
expect(divElem).toBeDefined();
|
|
});
|
|
|
|
it('should enable vendor section when incident contains brokerVendorName data', function () {
|
|
getCompiledElement(EntityVO.TYPE_INCIDENT);
|
|
|
|
expect(element.find('.ticket__vendor-info-section').length).toEqual(0);
|
|
|
|
getCompiledElement(EntityVO.TYPE_INCIDENT, true);
|
|
|
|
var vendorElement = element.find('.ticket__vendor-info-section');
|
|
|
|
expect(vendorElement.length).toEqual(1);
|
|
expect(vendorElement.html()).toContain('AWS_1234');
|
|
expect(vendorElement.html()).toContain('AWS TEST CASE--Please ignore');
|
|
});
|
|
|
|
it('should enable vendor section when change contains brokerVendorName data', function () {
|
|
getCompiledElement(EntityVO.TYPE_CHANGE);
|
|
|
|
expect(element.find('.ticket__vendor-info-section').length).toEqual(0);
|
|
|
|
getCompiledElement(EntityVO.TYPE_CHANGE, true);
|
|
|
|
var vendorElement = element.find('.ticket__vendor-info-section');
|
|
|
|
expect(vendorElement.length).toEqual(1);
|
|
expect(vendorElement.html()).toContain('JIRA_1234');
|
|
expect(vendorElement.html()).toContain('JIRA_5678');
|
|
});
|
|
|
|
it('should resolve ticket from knowledge', function () {
|
|
scope.id = '1234';
|
|
scope.type = EntityVO.TYPE_INCIDENT;
|
|
scope.ticket = {};
|
|
scope.progress = {};
|
|
|
|
createController();
|
|
spyOn(scope, '$broadcast');
|
|
var resourceItem = {
|
|
title: "abc",
|
|
updateCategories: false
|
|
};
|
|
rootScope.$broadcast('resolveTicketFromResourceSlice', resourceItem);
|
|
scope.$apply();
|
|
expect(scope.$broadcast).toHaveBeenCalledWith('afterSavedChanges', scope.basicData);
|
|
});
|
|
|
|
it('should resolve ticket from knowledge after updating categories', function () {
|
|
scope.id = '1234';
|
|
scope.type = EntityVO.TYPE_INCIDENT;
|
|
scope.ticket = {};
|
|
scope.progress = {};
|
|
scope.basicData = {
|
|
id: '1234',
|
|
type: EntityVO.TYPE_INCIDENT
|
|
};
|
|
|
|
createController();
|
|
spyOn(scope, '$broadcast');
|
|
var resourceItem = {
|
|
title: "abc",
|
|
updateCategories: true
|
|
};
|
|
resourceItem.categorizations = [
|
|
{
|
|
"name":"operational",
|
|
"tiers":{"operationCategoryTier1":"IT"},
|
|
"company":{"name":"Petramco"},
|
|
"primary":true
|
|
},
|
|
{
|
|
"name":"product",
|
|
"tiers":{"productCategoryTier1":"Software","productCategoryTier2":"Operating System","productCategoryTier3":"PC","productName":"Windows"},
|
|
"company":{"name":"Petramco"},
|
|
"primary":true
|
|
}
|
|
];
|
|
rootScope.$broadcast('resolveTicketFromResourceSlice', resourceItem);
|
|
scope.$apply();
|
|
expect(scope.$broadcast).toHaveBeenCalledWith('afterSavedChanges', scope.basicData);
|
|
});
|
|
|
|
it('should call approval rest call, when ticket type is sberequest and isInApproval is true ', function () {
|
|
scope.id = '23';
|
|
scope.type = EntityVO.TYPE_SBEREQUEST;
|
|
scope.basicData = {
|
|
type: EntityVO.TYPE_SBEREQUEST,
|
|
isInApproval: true,
|
|
isUserApprovalPending: true
|
|
};
|
|
createController();
|
|
scope.$digest();
|
|
expect(this.approvalService.getListOfApprovers).toHaveBeenCalled();
|
|
});
|
|
|
|
it('should call relations rest call and update relations model on controller load ', function () {
|
|
scope.id = '23';
|
|
scope.type = EntityVO.TYPE_SBEREQUEST;
|
|
scope.relations = null;
|
|
scope.basicData = {
|
|
type: EntityVO.TYPE_SBEREQUEST,
|
|
isInApproval: true,
|
|
isUserApprovalPending: true
|
|
};
|
|
createController();
|
|
scope.$digest();
|
|
expect(this.metadataModel.getMetadataByType).toHaveBeenCalled();
|
|
expect(this.relationModel.getRelations).toHaveBeenCalled();
|
|
expect(scope.relations).not.toBeNull();
|
|
});
|
|
|
|
it('should successfully fire the AFTER_SAVED_CHANGES event and refresh relations when user save the ticket and change the status to cancelled', function () {
|
|
var basicData = {
|
|
type: EntityVO.TYPE_INCIDENT,
|
|
isInApproval: true,
|
|
isUserApprovalPending: true,
|
|
categorizations: []
|
|
};
|
|
scope.id = '1234';
|
|
scope.type = EntityVO.TYPE_INCIDENT;
|
|
scope.relations = null;
|
|
spyOn(this.relationModel, 'refreshRelations').and.callFake(function () {
|
|
let deferred = $q.defer();
|
|
deferred.resolve([]);
|
|
return deferred.promise;
|
|
});
|
|
this.relationModel.cache = {
|
|
"IDGAA5V0GEPCCAP50KVKP43MX90ZNI": [
|
|
{
|
|
"displayId": "TAS000000000124",
|
|
"parentId": "IDGAA5V0GEPCCAP50KVKP43MX90ZNI",
|
|
"type": "task",
|
|
"id": "TMGAA5V0GEPCCAP59RY3P4MUA25UEA"
|
|
},
|
|
]
|
|
};
|
|
createController();
|
|
scope.ticket = new TicketVO().build({
|
|
status: {
|
|
value: 'Cancelled'
|
|
}
|
|
});
|
|
rootScope.$broadcast(events.AFTER_SAVED_CHANGES, basicData);
|
|
scope.$digest();
|
|
expect(this.relationModel.refreshRelations).toHaveBeenCalled();
|
|
expect(scope.relations['IDGAA5V0GEPCCAP50KVKP43MX90ZNI'][0].type).toBe('task');
|
|
});
|
|
});
|