245 lines
8.9 KiB
JavaScript
245 lines
8.9 KiB
JavaScript
describe('Test change class directive', function () {
|
|
var compile, scope, $httpBackend, originalTimeout, objectValueMapperService, events, field, metadata, fieldValidationModel;
|
|
|
|
beforeEach(module('myitsmApp','templates'));
|
|
beforeEach(function(){
|
|
inject(function($compile, $rootScope, $injector, _objectValueMapperService_, _events_, _fieldValidationModel_){
|
|
$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);
|
|
compile = $compile;
|
|
scope = $rootScope.$new();
|
|
objectValueMapperService = _objectValueMapperService_;
|
|
events = _events_;
|
|
fieldValidationModel = _fieldValidationModel_;
|
|
field = {
|
|
"name": "changeClass",
|
|
"label": "Class",
|
|
"arFieldName": "",
|
|
"type": "ticketClass",
|
|
"value": {
|
|
"timing": {name: "Normal"},
|
|
"timingReason": ""
|
|
},
|
|
"setValueFlag": "#$#",
|
|
"id": "AGHAA5V0HGOWWAOUK7F8A77QL4AREV"
|
|
};
|
|
metadata = {
|
|
"timings": [
|
|
{
|
|
"index": 1000,
|
|
"name": "Emergency",
|
|
"label": "Emergency"
|
|
},
|
|
{
|
|
"timingReasons": [
|
|
{
|
|
"index": 1000,
|
|
"name": "Customer/business need",
|
|
"label": "Customer/business need"
|
|
},
|
|
{
|
|
"index": 2000,
|
|
"name": "Insufficient lead-time",
|
|
"label": "Insufficient lead-time"
|
|
},
|
|
{
|
|
"index": 3000,
|
|
"name": "Known error correction",
|
|
"label": "Known error correction"
|
|
},
|
|
{
|
|
"index": 4000,
|
|
"name": "Scheduling conflict",
|
|
"label": "Scheduling conflict"
|
|
}
|
|
],
|
|
"index": 2000,
|
|
"name": "Expedited",
|
|
"label": "Expedited"
|
|
},
|
|
{
|
|
"index": 3000,
|
|
"name": "Latent",
|
|
"label": "Latent"
|
|
},
|
|
{
|
|
"index": 4000,
|
|
"name": "Normal",
|
|
"label": "Normal"
|
|
},
|
|
{
|
|
"index": 5000,
|
|
"name": "No Impact",
|
|
"label": "No Impact"
|
|
},
|
|
{
|
|
"index": 6000,
|
|
"name": "Standard",
|
|
"label": "Standard"
|
|
}
|
|
],
|
|
"timingReasons": [
|
|
{
|
|
"index": 1000,
|
|
"name": "Customer/business need",
|
|
"label": "Customer/business need"
|
|
},
|
|
{
|
|
"index": 2000,
|
|
"name": "Insufficient lead-time",
|
|
"label": "Insufficient lead-time"
|
|
},
|
|
{
|
|
"index": 3000,
|
|
"name": "Known error correction",
|
|
"label": "Known error correction"
|
|
},
|
|
{
|
|
"index": 4000,
|
|
"name": "Scheduling conflict",
|
|
"label": "Scheduling conflict"
|
|
}
|
|
]
|
|
};
|
|
});
|
|
});
|
|
|
|
beforeEach(function() {
|
|
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
|
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
|
|
});
|
|
|
|
afterEach(function() {
|
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
|
|
});
|
|
|
|
function getCompiledElement(){
|
|
var element = angular.element('<change-class data="field" metadata="metadata" is-editable="true"></change-class>');
|
|
var compiledElement = compile(element)(scope);
|
|
scope.$digest();
|
|
return compiledElement;
|
|
}
|
|
|
|
it('should compile', function(){
|
|
scope.field = new FieldVO().build(field);
|
|
scope.metadata = new MetadataVO().build(metadata);
|
|
var directiveElem = getCompiledElement();
|
|
var divElem = directiveElem[0];
|
|
expect(divElem).toBeDefined();
|
|
});
|
|
|
|
it('should invoke watch for setValueFlag', function(){
|
|
scope.field = new FieldVO().build(field);
|
|
scope.metadata = new MetadataVO().build(metadata);
|
|
var directiveElem = getCompiledElement();
|
|
var isoScope = directiveElem.isolateScope();
|
|
isoScope.isNew = true;
|
|
isoScope.draftTicket = {
|
|
timing: {
|
|
name: 'abc'
|
|
},
|
|
timingReason: ""
|
|
};
|
|
scope.field.setValueFlag = {
|
|
timing: {
|
|
name: 'abc'
|
|
},
|
|
timingReason: ""
|
|
};
|
|
scope.$digest();
|
|
expect(scope.field.setValueFlag).toEqual('#$#');
|
|
});
|
|
|
|
it('should check if field is required', function(){
|
|
scope.field = new FieldVO().build(field);
|
|
scope.metadata = new MetadataVO().build(metadata);
|
|
spyOn(fieldValidationModel, 'isFieldRequired').and.callFake(function () {
|
|
return { dataType: 'widget', value: {ootbKey: 'Some Data'} };
|
|
});
|
|
scope.$digest();
|
|
var directiveElem = getCompiledElement();
|
|
var isoScope = directiveElem.isolateScope();
|
|
isoScope.draftTicket = {
|
|
timing: {
|
|
name: 'abc'
|
|
},
|
|
timingReason: ""
|
|
};
|
|
var reason = 'timingReason';
|
|
isoScope.isFieldRequired(reason);
|
|
expect(fieldValidationModel.isFieldRequired).toHaveBeenCalled();
|
|
});
|
|
|
|
it('should update timing reason', function(){
|
|
scope.field = new FieldVO().build(field);
|
|
scope.metadata = new MetadataVO().build(metadata);
|
|
var directiveElem = getCompiledElement();
|
|
var isoScope = directiveElem.isolateScope();
|
|
isoScope.draftTicket = {
|
|
timing: {
|
|
name: 'abc'
|
|
},
|
|
timingReason: {
|
|
name: 'some data'
|
|
}
|
|
};
|
|
isoScope.updateTimingReason();
|
|
expect(scope.field.value.timingReason).toBe("some data");
|
|
});
|
|
|
|
it('should listen to DISCARD_CHANGES and assign data', inject(function ($rootScope) {
|
|
scope.field = new FieldVO().build(field);
|
|
scope.metadata = new MetadataVO().build(metadata);
|
|
scope.$digest();
|
|
var directiveElem = getCompiledElement();
|
|
var isoScope = directiveElem.isolateScope();
|
|
isoScope.editMode = true;
|
|
isoScope.draftTicket = {
|
|
timing: {
|
|
name: 'abc'
|
|
},
|
|
timingReason: ""
|
|
};
|
|
isoScope.$parent.$broadcast(events.DISCARD_CHANGES);
|
|
expect(isoScope.editMode).toBeFalsy();
|
|
}));
|
|
|
|
it('should listen to TOGGLE_EDIT_MODE and assign data', inject(function ($rootScope) {
|
|
scope.field = new FieldVO().build(field);
|
|
scope.metadata = new MetadataVO().build(metadata);
|
|
scope.$digest();
|
|
var directiveElem = getCompiledElement();
|
|
var isoScope = directiveElem.isolateScope();
|
|
isoScope.editMode = false;
|
|
isoScope.draftTicket = {
|
|
timing: {
|
|
name: 'abc'
|
|
},
|
|
timingReason: ""
|
|
};
|
|
isoScope.$parent.$broadcast(events.TOGGLE_EDIT_MODE);
|
|
expect(isoScope.editMode).toBeTruthy();
|
|
}));
|
|
|
|
it('should listen to AFTER_SAVED_CHANGES and assign data', inject(function ($rootScope) {
|
|
scope.field = new FieldVO().build(field);
|
|
scope.metadata = new MetadataVO().build(metadata);
|
|
scope.$digest();
|
|
var directiveElem = getCompiledElement();
|
|
var isoScope = directiveElem.isolateScope();
|
|
isoScope.editMode = true;
|
|
isoScope.draftTicket = {
|
|
timing: {
|
|
name: 'abc'
|
|
},
|
|
timingReason: ""
|
|
};
|
|
isoScope.$parent.$broadcast(events.AFTER_SAVED_CHANGES);
|
|
expect(isoScope.editMode).toBeFalsy();
|
|
}));
|
|
}); |