SmartIT_Extensions/BMC/smart-it-full/test/app/custom-widgets/affected-asset-directive.sp...

440 lines
15 KiB
JavaScript

describe('Test affected asset directive', function () {
var compile, scope, $httpBackend, customerData, resposeData, deferred, events;
beforeEach(module('myitsmApp','templates'));
beforeEach(function(){
inject(function($compile, $rootScope, $injector, objectValueMapperService, assetService, $q, _events_){
$httpBackend = $injector.get('$httpBackend');
var getLocale = function(){
return readJSON('scripts/app/i18n/resources-locale_en.json');
};
$httpBackend.whenGET(/^scripts\/app\/i18n\/resources-locale_en.*$/).respond(getLocale());
$httpBackend.whenGET('/smartit/rest/v2/metadata?type=global').respond(200);
$httpBackend.whenGET('/smartit/rest/v2/metadata?type=change').respond(200);
$httpBackend.whenGET(/^\/smartit\/rest\/foundation\/items*/).respond(200);
$httpBackend.whenGET('/smartit/rest/v2/metadata?type=incident').respond(200);
$httpBackend.whenGET('/smartit/rest/serverstates').respond(200);
$httpBackend.whenGET('/smartit/rest/sessionstatus?getLicenseKey=true').respond(200);
compile = $compile;
scope = $rootScope.$new();
events = _events_;
customerData = {
"firstName": "Paula",
"lastName": "Abdul",
"company": {
"name": "Petramco"
},
"site": {
"name": "Austin",
"address": {
"street": "10431 Morado Circle\nAvalon Building 5",
"city": "Austin",
"state": "Texas",
"country": "United States",
"zip": "78759",
"address": "10431 Morado Circle\nAvalon Building 5\r\nAustin, Texas 78759\r\nUnited States"
},
"region": "Americas",
"siteGroup": "Marketing"
},
"email": "pabdul@petramco.com",
"phone": "1 512 343-1919",
"loginId": "pabdul",
"personId": "GPL000000000746",
"organization": "Human Resources",
"isVIP": false,
"customFields": {},
"id": "pabdul",
"fullName": "Paula Abdul"
};
resposeData = [
{
"items": [
{
"objects": [
{
"name": "00:00:5a:99:ea:b8",
"desc": "",
"type": "Network",
"company": {
"name": "Petramco"
},
"product": {
"categorizations": [
{
"name": "product",
"tiers": {
"productCategoryTier1": "Network",
"productCategoryTier2": "Address",
"productCategoryTier3": "MAC Address"
}
}
]
},
"reconciliationId": "REHAA8F6F14F799A1D0144846A0B6D",
"classId": "BMC_LANENDPOINT",
"instanceId": "ASHAAFA09B42849BC66C3ADAFCDCD1",
"status": {
"value": "Deployed"
},
"assetExtension": {},
"needsReconciliation": false,
"dataSetId": "BMC.ASSET",
"assetId": "LNE000000002578",
"assetType": "Network",
"verified": false,
"customFields": {},
"id": "LNE000000002578",
"createDate": 1514889193000,
"modifiedDate": 1514889193000
}
],
"totalMatches": 5800
}
],
"syncTime": 1528096622199,
"dataSourceName": "asset"
}
];
deferred = $q.defer();
this.objectValueMapperService = objectValueMapperService;
this.assetService = assetService;
var menuFieldList = [
{
"name": "operationCategoryTier1",
"label": "Operational Categorization Tier 1",
"arFieldName": "Categorization Tier 1",
"type": "dynamicSelectionField",
"dataType": "menu",
"required": false,
"setValueFlag": "#$#",
"id": "AGGAA5V0GEXADAPG4GPDPF7KCGFJDS",
"itsmFieldId": 1000000063,
"ootb": true,
"parentId": "IDGAA5V0GEXADAPG4F3QPF78QTFIRF",
"groupEditable": true,
"valueLinkedField": null
},
{
"name": "productCategoryTier1",
"label": "Product Categorization Tier 1",
"arFieldName": "Product Categorization Tier 1",
"type": "dynamicSelectionField",
"dataType": "menu",
"required": false,
"setValueFlag": "#$#",
"id": "AGGAA5V0GEXADAPG4GPBPF7KCEFJCO",
"itsmFieldId": 200000003,
"ootb": true,
"parentId": "IDGAA5V0GEXADAPG4GPBPF7KCEFJCN",
"groupEditable": true,
"valueLinkedField": null
},
{
"name": "productCategoryTier2",
"label": "Product Categorization Tier 2",
"arFieldName": "Product Categorization Tier 2",
"type": "dynamicSelectionField",
"dataType": "menu",
"required": false,
"setValueFlag": "#$#",
"id": "AGGAA5V0GEXADAPG4GPBPF7KCEFJCY",
"itsmFieldId": 200000004,
"ootb": true,
"parentId": "IDGAA5V0GEXADAPG4GPBPF7KCEFJCN",
"groupEditable": false,
"valueLinkedField": null
},
{
"name": "productCategoryTier3",
"label": "Product Categorization Tier 3",
"arFieldName": "Product Categorization Tier 3",
"type": "dynamicSelectionField",
"dataType": "menu",
"required": false,
"setValueFlag": "#$#",
"id": "AGGAA5V0GEXADAPG4GPBPF7KCEFJDI",
"itsmFieldId": 200000005,
"ootb": true,
"parentId": "IDGAA5V0GEXADAPG4GPBPF7KCEFJCN",
"groupEditable": false,
"valueLinkedField": null
},
{
"name": "productName",
"label": "Product Name",
"arFieldName": "Product Name",
"type": "dynamicSelectionField",
"dataType": "menu",
"required": false,
"setValueFlag": "#$#",
"id": "AGGAA5V0GEXADAPG4GPBPF7KCEFJD8",
"itsmFieldId": 240001002,
"ootb": true,
"parentId": "IDGAA5V0GEXADAPG4GPBPF7KCEFJCN",
"groupEditable": false,
"valueLinkedField": null
}
];
spyOn(this.objectValueMapperService, 'getFieldsByType').and.callFake(function () {
return menuFieldList;
});
});
});
function getCompiledElement() {
var element = angular.element('<affected-asset data="data" ticket="ticket"></affected-asset>');
var compiledElement = compile(element)(scope);
scope.$digest();
return compiledElement;
}
it('should compile', function () {
var data = {
'name': 'impactedService',
'label': 'Affected Service',
'value': {}
},
ticket = {
"type": "change",
"accessMappings": {
"fieldMappings": {
"impactedService": "write",
"summary": "write"
},
"company": {
"name": "Petramco"
}
}
};
scope.data = new FieldVO().build(data);
scope.ticket = ticket;
spyOn(this.objectValueMapperService, 'getExactValueByFieldName').and.callFake(function () {
return '';
});
spyOn(this.objectValueMapperService, 'getValueByFieldName').and.callFake(function () {
return customerData;
});
var directiveElem = getCompiledElement();
var divElem = directiveElem[0];
expect(divElem).toBeDefined();
});
it('should update categories even when category tiers are split', function () {
var data = {
'name': 'impactedService',
'label': 'Affected Service',
'value': {}
},
ticket = {
"type": "change",
"accessMappings": {
"fieldMappings": {
"impactedService": "write",
"summary": "write"
},
"company": {
"name": "Petramco"
}
}
};
scope.data = new FieldVO().build(data);
scope.ticket = ticket;
var directiveElem = getCompiledElement();
var isolatedScope = directiveElem.isolateScope();
spyOn(isolatedScope, '$emit');
scope.data.value = {
'ci': {
'name': 'Email',
'desc': '',
'type': 'Business Service',
'company': {
'name': 'Calbro Services'
},
'product': {
'categorizations': [{
'name': 'product',
'tiers': {
'productCategoryTier1': 'Service',
'productCategoryTier2': 'Infrastructure',
'productCategoryTier3': 'Email'
}
}]
},
'reconciliationId': 'RE005056B551A0uelgSw83X7IARJAB',
'classId': 'BMC_BUSINESSSERVICE',
'instanceId': 'OI-520DEDF5A1A44736BFAFECA73B711BD3',
'site': {},
'status': {
'value': 'Deployed'
},
'assetExtension': {},
'needsReconciliation': false,
'dataSetId': 'BMC.ASSET',
'assetType': 'Business Service',
'verified': false,
'customFields': {},
'createDate': 1400840411000,
'modifiedDate': 1400840411000
},
'ticketType': 'incident',
'oldDataValue': null
};
scope.data.setValueFlag = angular.copy(scope.data.value);
scope.$apply();
expect(isolatedScope.$emit).toHaveBeenCalledWith('customFieldValueChange');
});
it('should make field read only', function () {
var data = {
'name': 'impactedService',
'label': 'Affected Service',
'value': {}
},
ticket = {
"type": "change",
"accessMappings": {
"fieldMappings": {
"impactedService": "write",
"summary": "write"
},
"company": {
"name": "Petramco"
}
}
};
scope.data = new FieldVO().build(data);
scope.ticket = ticket;
spyOn(this.objectValueMapperService, 'getExactValueByFieldName').and.callFake(function () {
return '';
});
spyOn(this.objectValueMapperService, 'getValueByFieldName').and.callFake(function () {
return '';
});
getCompiledElement();
expect(scope.data.isReadOnly).toBeTruthy();
});
it('should clear field', function () {
var data = {
'name': 'impactedService',
'label': 'Affected Service',
'value': {}
},
ticket = {
"type": "change",
"accessMappings": {
"fieldMappings": {
"impactedService": "write",
"summary": "write"
},
"company": {
"name": "Petramco"
}
}
};
scope.data = new FieldVO().build(data);
scope.ticket = ticket;
var directiveElem = getCompiledElement();
var isoScope = directiveElem.isolateScope();
isoScope.clearValue();
expect(scope.data.value.ci).toBe("");
});
it('should fetch asset list', function () {
var data = {
'name': 'impactedService',
'label': 'Affected Service',
'value': {}
},
ticket = {
"type": "change",
"accessMappings": {
"fieldMappings": {
"impactedService": "write",
"summary": "write"
},
"company": {
"name": "Petramco"
}
}
};
scope.data = new FieldVO().build(data);
scope.ticket = ticket;
spyOn(this.objectValueMapperService, 'getExactValueByFieldName').and.callFake(function () {
return 'Petramco';
});
spyOn(this.objectValueMapperService, 'getValueByFieldName').and.callFake(function () {
return customerData;
});
spyOn(this.assetService, 'getListOfAssetsForCompany').and.callFake(function () {
return resposeData;
});
spyOn(this.assetService, 'getListOfAssetsByTypeForCompany').and.callFake(function () {
deferred.resolve(resposeData);
return deferred.promise;
});
scope.$digest();
var directiveElem = getCompiledElement();
var isoScope = directiveElem.isolateScope();
isoScope.getList();
expect(scope.data.isReadOnly).toBeFalsy();
});
it('should fire widget value change event if user select any affected asset', function () {
var data = {
'name': 'causalCI',
'label': 'Affected Asset',
'value': {
"ci": {
"product": {
"categorizations": [
{
"name": "product",
"tiers": {
"productCategoryTier1": "Network",
"productCategoryTier2": "Address",
"productCategoryTier3": "MAC Address"
}
}
]
}
},
"ticketType": "incident"
}
},
ticket = {
"type": "incident",
"accessMappings": {
"fieldMappings": {
"affectedAsset": "write",
"summary": "write"
},
"company": {
"name": "Petramco"
}
}
};
scope.data = new FieldVO().build(data);
scope.ticket = ticket;
var directiveElem = getCompiledElement();
var isoScope = directiveElem.isolateScope();
spyOn(isoScope, '$emit');
isoScope.onValueChange();
isoScope.$apply();
expect(isoScope.$emit).toHaveBeenCalledWith(events.WIDGET_VALUE_CHANGE, {fieldName: isoScope.data.name, memberName: isoScope.data.name});
expect(isoScope.$emit).toHaveBeenCalledWith(events.AFFECTED_SERVICE_VALUE_CHANGED, isoScope.data.value.ci);
});
});