396 lines
17 KiB
JavaScript
396 lines
17 KiB
JavaScript
describe('Test ticket risk directive', function () {
|
|
var compile, scope, $httpBackend, events, createTicketModel, $q, objectValueMapperService, rootScope;
|
|
|
|
beforeEach(module('myitsmApp', 'templates'));
|
|
beforeEach(function() {
|
|
inject(function($compile, $rootScope, $injector, _events_, _createTicketModel_, _$q_, _objectValueMapperService_) {
|
|
$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/serverstates').respond(200);
|
|
$httpBackend.whenGET('/smartit/rest/sessionstatus?getLicenseKey=true').respond(200);
|
|
$httpBackend.whenGET('/smartit/rest/v2/metadata?type=change').respond(200);
|
|
compile = $compile;
|
|
rootScope = $rootScope;
|
|
scope = $rootScope.$new();
|
|
events = _events_;
|
|
createTicketModel = _createTicketModel_;
|
|
$q = _$q_;
|
|
objectValueMapperService = _objectValueMapperService_;
|
|
spyOn(createTicketModel, 'getList').and.callFake(function(type, payload) {
|
|
var dfd = $q.defer();
|
|
if (payload && payload.categorizations && payload.categorizations[0] && payload.categorizations[0].tiers.operationCategoryTier1 === 'fakeOpCat1') {
|
|
dfd.resolve([
|
|
{
|
|
"weight": 5,
|
|
"company": "- Global -",
|
|
"options": [
|
|
{
|
|
"riskValue": "5",
|
|
"label": "No",
|
|
"value": "No",
|
|
"order": 1,
|
|
"id": "AG000F1F64B045_bOOQwSoI2AgUGkA"
|
|
},
|
|
{
|
|
"riskValue": "1",
|
|
"label": "Yes",
|
|
"value": "Yes",
|
|
"order": 2,
|
|
"id": "AG000F1F64B045#rOOQwwXY2AgS2kA"
|
|
}
|
|
],
|
|
"label": "Can this change be rolled back easily?",
|
|
"isRequired": false,
|
|
"isHidden": false,
|
|
"isReadOnly": false,
|
|
"questionnaireId": "CH001143D417CB7uT8Qgz4jxBQ4wAA",
|
|
"sortOrder": 2,
|
|
"format": "STATIC_MENU",
|
|
"id": "CH000F1F64B04557OOQwbS42AgRWkA",
|
|
"createDate": 1133425661000,
|
|
"modifiedDate": 1146257628000
|
|
}
|
|
]);
|
|
} else {
|
|
dfd.resolve([]);
|
|
}
|
|
return dfd.promise;
|
|
});
|
|
});
|
|
});
|
|
|
|
beforeEach(function() {
|
|
var field = {
|
|
"name": "changeRisk",
|
|
"value": {
|
|
"riskLevel": "Risk Level 3"
|
|
},
|
|
"id": "AGHAA5V0HGOWWAOU6TXPA9G04QBDBB"
|
|
}, context = {
|
|
"questionResponses": [
|
|
{
|
|
"company": "- Global -",
|
|
"questionnaireId": "CH001143D417CB7uT8Qgz4jxBQ4wAA",
|
|
"parentId": "AG00123F73CF5EWtETSQsWU8Ag_UgB",
|
|
"questionId": "CH000F1F64B04557OOQwbS42AgRWkA",
|
|
"questionText": "Can this change be rolled back easily?",
|
|
"id": "IDGAA5V0HHE9CAPJC5LXPIFP8AA85X",
|
|
"displayValue": "No",
|
|
"value": 5
|
|
}
|
|
],
|
|
"company": {
|
|
"name": "Calbro Services"
|
|
},
|
|
"categorizations": [
|
|
{
|
|
"name": "operational",
|
|
"tiers": {}
|
|
},
|
|
{
|
|
"name": "product",
|
|
"tiers": {}
|
|
}
|
|
]
|
|
}, metadata = {
|
|
"riskLevels": [
|
|
{
|
|
"index": 0,
|
|
"name": "Risk Level 1",
|
|
"label": "Risk Level 1"
|
|
},
|
|
{
|
|
"index": 1,
|
|
"name": "Risk Level 2",
|
|
"label": "Risk Level 2"
|
|
},
|
|
{
|
|
"index": 2,
|
|
"name": "Risk Level 3",
|
|
"label": "Risk Level 3"
|
|
},
|
|
{
|
|
"index": 3,
|
|
"name": "Risk Level 4",
|
|
"label": "Risk Level 4"
|
|
},
|
|
{
|
|
"index": 4,
|
|
"name": "Risk Level 5",
|
|
"label": "Risk Level 5"
|
|
}
|
|
]
|
|
};
|
|
|
|
scope.field = field;
|
|
scope.ticket = context;
|
|
scope.metadata = metadata;
|
|
scope.isEditable = true;
|
|
});
|
|
|
|
function getCompiledElement() {
|
|
var element = angular.element('<ticket-risk data="field" context="ticket" metadata="metadata" is-new="false" is-editable="isEditable"></ticket-risk>');
|
|
var compiledElement = compile(element)(scope);
|
|
scope.$digest();
|
|
return compiledElement;
|
|
}
|
|
|
|
it('should compile', function() {
|
|
var directiveElem = getCompiledElement();
|
|
var divElem = directiveElem[0];
|
|
expect(divElem).toBeDefined();
|
|
});
|
|
|
|
it('should set the default value of data.value and data.value.riskLevel if it is undefined', function() {
|
|
scope.field.value = {};
|
|
var directiveElem = getCompiledElement();
|
|
var isolateScope = directiveElem.isolateScope();
|
|
expect(isolateScope.data.value.mode).toBe('manual');
|
|
expect(isolateScope.data.value.riskLevel).toBe('Risk Level 1');
|
|
});
|
|
|
|
it('should return true if override risk level manually radio option is selected', function() {
|
|
scope.field.value.mode = 'manual';
|
|
var directiveElem = getCompiledElement();
|
|
var isolateScope = directiveElem.isolateScope();
|
|
expect(isolateScope.overrideRiskLevelEnabled()).toBeTruthy();
|
|
});
|
|
|
|
it('should set the risk object and return proper class name on click of Risk Level', function() {
|
|
var directiveElem = getCompiledElement();
|
|
var isolateScope = directiveElem.isolateScope();
|
|
var riskLevel = {
|
|
"index": 4,
|
|
"name": "Risk Level 5",
|
|
"label": "Risk Level 5"
|
|
}, reverseIndex = 0;
|
|
spyOn(isolateScope, '$emit');
|
|
isolateScope.riskLevelChanged(riskLevel);
|
|
expect(isolateScope.data.value.riskLevel).toBe('Risk Level 5');
|
|
expect(isolateScope.data.riskIsUserSpecified).toBeTruthy();
|
|
expect(isolateScope.$emit).toHaveBeenCalledWith(events.WIDGET_VALUE_CHANGE, { fieldName: 'changeRisk', fieldValue: 'Risk Level 5', memberName: 'riskLevel' });
|
|
|
|
expect(isolateScope.riskLevelCls(riskLevel, reverseIndex)).toBe('active ticket__risk-level-5');
|
|
});
|
|
|
|
it('should return false on click of Risk Level if isEditable is false', function() {
|
|
scope.isEditable = false;
|
|
var directiveElem = getCompiledElement();
|
|
var isolateScope = directiveElem.isolateScope();
|
|
expect(isolateScope.riskLevelChanged()).toBeFalsy();
|
|
});
|
|
|
|
it('should return true if Answer risk question radio option is selected', function() {
|
|
var directiveElem = getCompiledElement();
|
|
var isolateScope = directiveElem.isolateScope();
|
|
isolateScope.data.value.mode = 'auto';
|
|
expect(isolateScope.riskQuestionsEnabled()).toBeTruthy();
|
|
});
|
|
|
|
it('should select response question option and return true for active option selected', function() {
|
|
var question = {
|
|
"company": "- Global -",
|
|
"options": [
|
|
{
|
|
"label": "No",
|
|
"value": "No",
|
|
"id": "AG000F1F64B045FrOOQwf_wyAg5mgA"
|
|
},
|
|
{
|
|
"label": "Yes",
|
|
"value": "Yes",
|
|
"id": "AG000F1F64B045ErOOQwd#syAg4WgA"
|
|
}
|
|
],
|
|
"label": "Does this change need to be done during business hours?",
|
|
"id": "CH000F1F64B045sbKOQwuHExAg2WgA"
|
|
}, option = {
|
|
"riskValue": "5",
|
|
"label": "Yes",
|
|
"value": "Yes",
|
|
"id": "AG000F1F64B045ErOOQwd#syAg4WgA"
|
|
};
|
|
var directiveElem = getCompiledElement();
|
|
var isolateScope = directiveElem.isolateScope();
|
|
isolateScope.selectQuestionOption(question, option);
|
|
expect(isolateScope.questionResponsesCopy[question.id].value).toBe('Yes');
|
|
expect(isolateScope.data.value.questionResponses[question.id].label).toBe('Yes');
|
|
expect(isolateScope.questionOptionSelected(question, option)).toBeTruthy();
|
|
});
|
|
|
|
it('should update the value of checkMode on click of Override Risk Level Manually Radio button', function() {
|
|
var directiveElem = getCompiledElement();
|
|
var isolateScope = directiveElem.isolateScope();
|
|
isolateScope.data.modeCheck = true;
|
|
isolateScope.modeCheck();
|
|
expect(isolateScope.data.modeCheck).toBeFalsy();
|
|
});
|
|
|
|
it('should toggle the accordian of risk questions and responses', function() {
|
|
var directiveElem = getCompiledElement();
|
|
var isolateScope = directiveElem.isolateScope();
|
|
isolateScope.showRiskQuestions = true;
|
|
isolateScope.toggleRiskQuestions();
|
|
expect(isolateScope.showRiskQuestions).toBeFalsy();
|
|
});
|
|
|
|
describe('should update the value of reloadIf and ', function () {
|
|
var directiveElem, isolateScope;
|
|
beforeEach(function() {
|
|
directiveElem = getCompiledElement();
|
|
isolateScope = directiveElem.isolateScope();
|
|
isolateScope.reloadIf = false;
|
|
});
|
|
|
|
it('should update the value of checkMode and reloadIf on click of Answer risk questions radio button', function() {
|
|
isolateScope.reloadCheck();
|
|
expect(isolateScope.data.modeCheck).toBeTruthy();
|
|
expect(isolateScope.reloadIf).toBeTruthy();
|
|
});
|
|
|
|
it('should watch reloadIf and set the mode to manual if mode is already set to auto and no question found', function() {
|
|
var categories = [
|
|
{
|
|
"name": "operational",
|
|
"label": "Operational Category",
|
|
"value": {
|
|
"name": "operational",
|
|
"label": "Operational Category",
|
|
"listOfTiers": [
|
|
{
|
|
"name": "operationCategoryTier1",
|
|
"label": "Operational Categorization Tier 1+",
|
|
"index": 0,
|
|
"selectedValue": "operationCategoryTier1"
|
|
}
|
|
]
|
|
},
|
|
"id": "AGHAA5V0HGOWWAOU6TISA8NC28BCLI"
|
|
}], fieldList = [
|
|
{
|
|
name: 'operationCategory',
|
|
value: 'operationCategory'
|
|
}
|
|
];
|
|
spyOn(objectValueMapperService, 'getFieldsByType').and.returnValue(categories);
|
|
spyOn(objectValueMapperService, 'getFieldList').and.returnValue(fieldList);
|
|
|
|
isolateScope.reloadIf = true;
|
|
isolateScope.data.value.mode = 'auto';
|
|
isolateScope.$digest();
|
|
expect(isolateScope.data.value.mode).toBe('manual');
|
|
});
|
|
|
|
it('should watch reloadIf and load question accordingly', function() {
|
|
var categories = [
|
|
{
|
|
"name": "operational",
|
|
"label": "Operational Category",
|
|
"value": {
|
|
"name": "operational",
|
|
"label": "Operational Category",
|
|
"listOfTiers": [
|
|
{
|
|
"name": "operationCategoryTier1",
|
|
"label": "Operational Categorization Tier 1+",
|
|
"index": 0,
|
|
"selectedValue": "fakeOpCat1"
|
|
}
|
|
]
|
|
},
|
|
"id": "fakeid"
|
|
}], fieldList = [
|
|
{
|
|
name: 'operationCategory',
|
|
value: 'operationCategory'
|
|
}
|
|
];
|
|
spyOn(objectValueMapperService, 'getFieldsByType').and.returnValue(categories);
|
|
spyOn(objectValueMapperService, 'getFieldList').and.returnValue(fieldList);
|
|
// spyOn(createTicketModel, 'getList').and.callFake(function() {
|
|
// deferred.resolve(questionList);
|
|
// return deferred.promise;
|
|
// });
|
|
isolateScope.reloadIf = true;
|
|
isolateScope.responsesCopy = [
|
|
{
|
|
"company": "- Global -",
|
|
"questionnaireId": "CH001143D417CB7uT8Qgz4jxBQ4wAA",
|
|
"parentId": "AG00123F73CF5EWtETSQsWU8Ag_UgB",
|
|
"questionId": "CH000F1F64B04557OOQwbS42AgRWkA",
|
|
"questionText": "Can this change be rolled back easily?",
|
|
"id": "IDGAA5V0HHE9CAPJC5LXPIFP8AA85X",
|
|
"optionId": "AG000F1F64B045_bOOQwSoI2AgUGkA"
|
|
}
|
|
];
|
|
isolateScope.$digest();
|
|
expect(isolateScope.data.value.questionResponses[isolateScope.responsesCopy[0].questionId].label).toBe('No');
|
|
});
|
|
});
|
|
|
|
it('should successfully call events.AFTER_SAVED_CHANGES event handler on click of save button', function() {
|
|
var directiveElem = getCompiledElement();
|
|
var isolateScope = directiveElem.isolateScope();
|
|
rootScope.$broadcast(events.AFTER_SAVED_CHANGES, { riskLevel: 'Risk Level 1' });
|
|
expect(isolateScope.data.value.riskLevel).toBe('Risk Level 1');
|
|
expect(isolateScope.data.value.questionResponses[0].displayValue).toBe('No');
|
|
});
|
|
|
|
it('should return the value of riskLevel if it has any value otherwise return empty string', function() {
|
|
var directiveElem = getCompiledElement();
|
|
var isolateScope = directiveElem.isolateScope();
|
|
isolateScope.data.value.riskLevel = 'Risk Level 1';
|
|
expect(isolateScope.riskLevel()).toBe('Risk Level 1');
|
|
isolateScope.data.value.riskLevel = '';
|
|
expect(isolateScope.riskLevel()).toBe('');
|
|
});
|
|
|
|
it('should return true if mode is manual or riskLevel does not have any value', function() {
|
|
var directiveElem = getCompiledElement();
|
|
var isolateScope = directiveElem.isolateScope();
|
|
isolateScope.data.value.riskLevel = '';
|
|
expect(isolateScope.overrideRiskLevelTitleEnabled()).toBeTruthy();
|
|
isolateScope.data.value.riskLevel = 'Risk Level 1';
|
|
isolateScope.data.value.mode = 'manual';
|
|
expect(isolateScope.overrideRiskLevelTitleEnabled()).toBeTruthy();
|
|
isolateScope.data.value.riskLevel = 'Risk Level 1';
|
|
isolateScope.data.value.mode = 'auto';
|
|
expect(isolateScope.overrideRiskLevelTitleEnabled()).toBeFalsy();
|
|
});
|
|
|
|
it('should successfully watch data.setValueFlag model', function() {
|
|
var directiveElem = getCompiledElement();
|
|
var isolateScope = directiveElem.isolateScope();
|
|
spyOn(isolateScope, '$emit');
|
|
isolateScope.data.setValueFlag = { riskLevel: 'Risk Level 4' };
|
|
isolateScope.$digest();
|
|
expect(isolateScope.data.value.riskLevel).toBe('Risk Level 4');
|
|
expect(isolateScope.$emit).toHaveBeenCalledWith(events.WIDGET_VALUE_CHANGE, { fieldName: 'changeRisk', fieldValue: 'Risk Level 4' });
|
|
expect(isolateScope.data.setValueFlag).toBe('#$#');
|
|
|
|
isolateScope.data.setValueFlag = { mode: 'manual' };
|
|
isolateScope.$digest();
|
|
expect(isolateScope.data.value.mode).toBe('manual');
|
|
expect(isolateScope.data.setValueFlag).toBe('#$#');
|
|
});
|
|
|
|
it('should successfully call events.DISCARD_CHANGES event handler on click of cancel button and reset all the values', function() {
|
|
var directiveElem = getCompiledElement();
|
|
var isolateScope = directiveElem.isolateScope();
|
|
isolateScope.data.value.mode = 'auto';
|
|
isolateScope.state.pendingRiskLevelChange = true;
|
|
rootScope.$broadcast(events.DISCARD_CHANGES);
|
|
expect(isolateScope.data.value.mode).toBe('auto');
|
|
expect(isolateScope.state.pendingRiskLevelChange).toBeTruthy();
|
|
expect(isolateScope.data.value.riskLevel).toBe('Risk Level 3');
|
|
|
|
isolateScope.context.questionResponses = [];
|
|
rootScope.$broadcast(events.DISCARD_CHANGES);
|
|
expect(isolateScope.data.value.mode).toBe('auto');
|
|
expect(isolateScope.state.pendingRiskLevelChange).toBeTruthy();
|
|
|
|
});
|
|
}); |