1348 lines
51 KiB
JavaScript
1348 lines
51 KiB
JavaScript
describe('Test group custom field directive', function () {
|
|
var compile, scope, rootScope, $httpBackend, getWidgetData, field, ticket, isNew, metadataModel, $q, objectValueMapperService;
|
|
|
|
beforeEach(module('myitsmApp', 'templates'));
|
|
beforeEach(function () {
|
|
inject(function ($compile, $rootScope, $injector, events, _metadataModel_, _$q_, _objectValueMapperService_) {
|
|
|
|
this.events = events;
|
|
$httpBackend = $injector.get('$httpBackend');
|
|
var getLocale = function () {
|
|
return readJSON('scripts/app/i18n/resources-locale_en.json');
|
|
};
|
|
getWidgetData = function () {
|
|
return readJSON('mocks/widget-data.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/v3/action/search?resourceType=change').respond(200);
|
|
$httpBackend.whenGET('/smartit/rest/serverstates').respond(200);
|
|
$httpBackend.whenGET('/smartit/rest/sessionstatus?getLicenseKey=true').respond(200);
|
|
$httpBackend.whenGET('/smartit/restapi/person/supportgroupperson').respond(200);
|
|
compile = $compile;
|
|
rootScope = $rootScope;
|
|
scope = $rootScope.$new();
|
|
metadataModel = _metadataModel_;
|
|
$q = _$q_;
|
|
objectValueMapperService = _objectValueMapperService_;
|
|
})
|
|
});
|
|
|
|
beforeEach(function () {
|
|
ticket = {
|
|
"type": "change",
|
|
"accessMappings": {
|
|
"fieldMappings": {
|
|
"impactedService": "write",
|
|
"summary": "write"
|
|
},
|
|
"company": {
|
|
"name": "Petramco"
|
|
}
|
|
}
|
|
};
|
|
field = new FieldVO().build(getWidgetData().groupFieldData);
|
|
isNew = false;
|
|
});
|
|
|
|
function getCompiledElement() {
|
|
scope.field = field;
|
|
scope.ticket = ticket;
|
|
scope.isNew = isNew;
|
|
var element = angular.element('<group-custom-field data="field" context="ticket" is-new="isNew" is-hide-label="true"></group-custom-field>'),
|
|
compiledElement = compile(element)(scope);
|
|
scope.$digest();
|
|
return compiledElement;
|
|
}
|
|
|
|
it('should compile', function () {
|
|
var directiveElem = getCompiledElement(),
|
|
divElem = directiveElem[0];
|
|
expect(divElem).toBeDefined();
|
|
});
|
|
|
|
it('should clear dependant fields', function () {
|
|
var directiveElem = getCompiledElement(),
|
|
isolatedScope = directiveElem.isolateScope();
|
|
spyOn(isolatedScope, 'onFieldValueChange');
|
|
field.members[0] = new FieldVO().build(field.members[0]);
|
|
field.members[1] = new FieldVO().build(field.members[1]);
|
|
field.members[2] = new FieldVO().build(field.members[2]);
|
|
rootScope.$broadcast(this.events.CLEAR_DEPENDANT_FIELDS, 'operationCategoryTier1');
|
|
scope.$apply();
|
|
expect(isolatedScope.onFieldValueChange).toHaveBeenCalled();
|
|
});
|
|
|
|
it('should set groupEditable to true if no dependency is defined', function () {
|
|
var directiveElem = getCompiledElement(),
|
|
isolatedScope = directiveElem.isolateScope();
|
|
delete field.members[0].dependency;
|
|
delete field.members[1].dependency;
|
|
delete field.members[2].dependency;
|
|
rootScope.$broadcast(this.events.CLEAR_DEPENDANT_FIELDS, 'operationCategoryTier1');
|
|
scope.$apply();
|
|
expect(isolatedScope.data.members[0].groupEditable).toBeTruthy();
|
|
});
|
|
|
|
it('should show tooltip as per label text', function () {
|
|
var directiveElem, isolateScope;
|
|
field.label = 'Work Order ID';
|
|
directiveElem = getCompiledElement();
|
|
isolateScope = directiveElem.isolateScope();
|
|
expect(isolateScope.tooltipToShow).toBe('Work Order ID');
|
|
});
|
|
|
|
it('should clear dependant fields and set groupEditable to false if dependant fields are present', function () {
|
|
var directiveElem, isolateScope;
|
|
|
|
directiveElem = getCompiledElement();
|
|
isolateScope = directiveElem.isolateScope();
|
|
|
|
field.members[0] = new FieldVO().build(field.members[0]);
|
|
field.members[1] = new FieldVO().build(field.members[1]);
|
|
field.members[2] = new FieldVO().build(field.members[2]);
|
|
|
|
spyOn(metadataModel, 'getMetadataByType').and.callFake(function () {
|
|
let defer = $q.defer();
|
|
defer.resolve({configurationParameters: {}});
|
|
return defer.promise;
|
|
});
|
|
spyOn(isolateScope, 'onFieldValueChange');
|
|
|
|
isolateScope.getFieldValue = angular.noop;
|
|
rootScope.$broadcast(this.events.REFRESH_FIELD_VALUES);
|
|
isolateScope.$apply();
|
|
|
|
expect(isolateScope.data.members[0].groupEditable).toBeFalsy();
|
|
expect(isolateScope.onFieldValueChange).toHaveBeenCalled();
|
|
});
|
|
|
|
it('should set groupEditable to true if dependant fields are not present', function () {
|
|
var directiveElem, isolateScope;
|
|
|
|
directiveElem = getCompiledElement();
|
|
isolateScope = directiveElem.isolateScope();
|
|
|
|
delete field.members[0].dependency;
|
|
delete field.members[1].dependency;
|
|
delete field.members[2].dependency;
|
|
|
|
spyOn(metadataModel, 'getMetadataByType').and.callFake(function () {
|
|
let defer = $q.defer();
|
|
defer.resolve({configurationParameters: {}});
|
|
return defer.promise;
|
|
});
|
|
|
|
rootScope.$broadcast(this.events.REFRESH_FIELD_VALUES);
|
|
isolateScope.$apply();
|
|
|
|
expect(isolateScope.data.members[0].groupEditable).toBeTruthy();
|
|
});
|
|
|
|
it('should set groupEditable to true if dependant fields and field value are present', function () {
|
|
var directiveElem, isolateScope;
|
|
|
|
directiveElem = getCompiledElement();
|
|
isolateScope = directiveElem.isolateScope();
|
|
|
|
spyOn(metadataModel, 'getMetadataByType').and.callFake(function () {
|
|
let defer = $q.defer();
|
|
defer.resolve({configurationParameters: {}});
|
|
return defer.promise;
|
|
});
|
|
|
|
spyOn(objectValueMapperService, 'getExactValueByFieldName').and.returnValue(true);
|
|
isolateScope.getFieldValue = angular.noop;
|
|
|
|
rootScope.$broadcast(this.events.REFRESH_FIELD_VALUES);
|
|
isolateScope.$apply();
|
|
|
|
expect(isolateScope.data.members[0].groupEditable).toBeTruthy();
|
|
});
|
|
});
|
|
|
|
describe('Test static selection custom field directive', function () {
|
|
var compile, scope, rootScope, $httpBackend, getWidgetData, screenConfigurationModel, field, events;
|
|
|
|
beforeEach(module('myitsmApp', 'templates'));
|
|
beforeEach(function () {
|
|
inject(function ($compile, $rootScope, $injector, _screenConfigurationModel_, _events_) {
|
|
|
|
$httpBackend = $injector.get('$httpBackend');
|
|
var getLocale = function () {
|
|
return readJSON('scripts/app/i18n/resources-locale_en.json');
|
|
};
|
|
getWidgetData = function () {
|
|
return readJSON('mocks/widget-data.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/v3/action/search?resourceType=change').respond(200);
|
|
$httpBackend.whenGET('/smartit/rest/serverstates').respond(200);
|
|
$httpBackend.whenGET('/smartit/rest/sessionstatus?getLicenseKey=true').respond(200);
|
|
compile = $compile;
|
|
rootScope = $rootScope;
|
|
scope = $rootScope.$new();
|
|
screenConfigurationModel = _screenConfigurationModel_;
|
|
events = _events_;
|
|
|
|
field = new FieldVO().build(getWidgetData().staticSelectionData);
|
|
})
|
|
});
|
|
|
|
function getCompiledElement(field, ticket, directiveName) {
|
|
scope.field = field;
|
|
scope.ticket = ticket;
|
|
var element = angular.element('<' + directiveName + ' data="field" context="ticket" is-new="isNew" is-hide-label="true"></' + directiveName + 'static-selection-custom-field>'),
|
|
compiledElement = compile(element)(scope);
|
|
scope.$digest();
|
|
return compiledElement;
|
|
}
|
|
|
|
it('should compile', function () {
|
|
var ticket = {
|
|
type: 'change'
|
|
},
|
|
directiveElem, divElem, isolatedScope;
|
|
field.hasValue = true;
|
|
directiveElem = getCompiledElement(field, ticket, 'static-selection-custom-field');
|
|
divElem = directiveElem[0];
|
|
isolatedScope = directiveElem.isolateScope();
|
|
expect(divElem).toBeDefined();
|
|
expect(isolatedScope.selectedOption.name).toEqual(field.value.name);
|
|
});
|
|
|
|
it('should set dropdown labels for asset', function () {
|
|
var ticket = {
|
|
ticketType: 'asset'
|
|
},
|
|
directiveElem, isolatedScope;
|
|
|
|
field.name = 'Asset';
|
|
field.type = 'selectionField';
|
|
screenConfigurationModel.fieldLabels = [
|
|
{
|
|
name: 'Asset',
|
|
classIds: ['ITSM AssetBase']
|
|
}
|
|
];
|
|
|
|
directiveElem = getCompiledElement(field, ticket, 'static-selection-custom-field');
|
|
isolatedScope = directiveElem.isolateScope();
|
|
expect(isolatedScope.options[0].value).toBe(0);
|
|
});
|
|
|
|
it('should update the user selection if user has selected any value', function () {
|
|
var ticket = {
|
|
type: 'change'
|
|
},
|
|
directiveElem, isolatedScope, selectedOption;
|
|
|
|
directiveElem = getCompiledElement(field, ticket, 'static-selection-custom-field');
|
|
isolatedScope = directiveElem.isolateScope();
|
|
|
|
selectedOption = {
|
|
"index": 4000,
|
|
"name": "Upgrade",
|
|
"label": "Upgrade",
|
|
};
|
|
isolatedScope.selectItem(selectedOption);
|
|
expect(isolatedScope.selectedOption.name).toEqual(selectedOption.name);
|
|
});
|
|
|
|
it('should update the user selection if user has selected empty value', function () {
|
|
var ticket = {
|
|
type: 'change'
|
|
},
|
|
directiveElem, isolatedScope;
|
|
|
|
directiveElem = getCompiledElement(field, ticket, 'static-selection-custom-field');
|
|
isolatedScope = directiveElem.isolateScope();
|
|
|
|
isolatedScope.selectItem();
|
|
expect(isolatedScope.selectedOption).toBeUndefined();
|
|
});
|
|
|
|
it('should update the user selection in case of radio option field', function () {
|
|
var ticket = {
|
|
type: 'change'
|
|
},
|
|
directiveElem, isolatedScope,
|
|
selectedOption = {
|
|
"index": 4000,
|
|
"name": "Upgrade",
|
|
"label": "Upgrade",
|
|
};
|
|
field.dataType = 'radio';
|
|
field.hasValue = true;
|
|
field.value = 4000;
|
|
directiveElem = getCompiledElement(field, ticket, 'static-selection-custom-field');
|
|
isolatedScope = directiveElem.isolateScope();
|
|
|
|
isolatedScope.selectItem(selectedOption);
|
|
expect(isolatedScope.selectedOption).toBe(null);
|
|
expect(isolatedScope.data.radioFieldVal).toBe(null);
|
|
});
|
|
|
|
it('should successfully watch data.setValueFlag', function () {
|
|
var ticket = {
|
|
type: 'change'
|
|
},
|
|
directiveElem, isolatedScope;
|
|
|
|
directiveElem = getCompiledElement(field, ticket, 'static-selection-custom-field');
|
|
isolatedScope = directiveElem.isolateScope();
|
|
|
|
isolatedScope.data.setValueFlag = 'test';
|
|
isolatedScope.$apply();
|
|
|
|
expect(field.setValueFlag).toBe('#$#');
|
|
});
|
|
|
|
it('should successfully handle refreshValue events', function () {
|
|
var ticket = {
|
|
type: 'change'
|
|
},
|
|
directiveElem, isolatedScope;
|
|
|
|
field.hasValue = true;
|
|
field.value = 1000;
|
|
|
|
directiveElem = getCompiledElement(field, ticket, 'static-selection-custom-field');
|
|
isolatedScope = directiveElem.isolateScope();
|
|
|
|
isolatedScope.data.ootb = false;
|
|
rootScope.$broadcast(events.REFRESH_FIELD_VALUES);
|
|
isolatedScope.$apply();
|
|
|
|
expect(isolatedScope.selectedOption.index).toBe(1000);
|
|
});
|
|
});
|
|
|
|
describe('Test menu custom field directive', function () {
|
|
var compile, scope, $httpBackend, getWidgetData, deferred, field, ticket, events;
|
|
|
|
beforeEach(module('myitsmApp', 'templates'));
|
|
beforeEach(function () {
|
|
inject(function ($compile, $rootScope, $injector, $q, _metadataModel_, _objectValueMapperService_, _events_, _screenConfigurationModel_, _screenConfigurationService_) {
|
|
|
|
deferred = $q.defer();
|
|
$httpBackend = $injector.get('$httpBackend');
|
|
var getLocale = function () {
|
|
return readJSON('scripts/app/i18n/resources-locale_en.json');
|
|
};
|
|
getWidgetData = function () {
|
|
return readJSON('mocks/widget-data.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/v3/action/search?resourceType=change').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_;
|
|
|
|
this.metadataModel = _metadataModel_;
|
|
this.objectValueMapperService = _objectValueMapperService_;
|
|
this.screenConfigurationModel = _screenConfigurationModel_;
|
|
this.screenConfigurationService = _screenConfigurationService_;
|
|
})
|
|
});
|
|
|
|
beforeEach(function () {
|
|
ticket = {
|
|
type: 'workorder',
|
|
locationCompany: 'Calbro Services'
|
|
};
|
|
field = new FieldVO().build(getWidgetData().staticSelectionData);
|
|
});
|
|
|
|
function getCompiledElement() {
|
|
scope.field = field;
|
|
scope.ticket = ticket;
|
|
var element = angular.element('<menu-custom-field data="field" context="ticket" is-new="isNew" is-Hide-label="true"></menu-custom-field>'),
|
|
compiledElement = compile(element)(scope);
|
|
scope.$digest();
|
|
return compiledElement;
|
|
}
|
|
|
|
it('should compile and not check for members dataType if members not present', function () {
|
|
var directiveElem, divElem, isolatedScope,
|
|
metadata = {
|
|
configurationParameters: {}
|
|
};
|
|
field.hasValue = true;
|
|
field.dependency = [{
|
|
'name': 'locationCompany',
|
|
'label': 'Company',
|
|
'availability': 0,
|
|
'fieldUnavailableOn': []
|
|
}, {
|
|
'name': 'operationCategoryTier1',
|
|
'label': 'Categorization Tier 1',
|
|
'availability': 0,
|
|
'fieldUnavailableOn': []
|
|
}, {
|
|
'name': 'serviceType',
|
|
'label': 'Service Type',
|
|
'availability': 0,
|
|
'fieldUnavailableOn': []
|
|
}];
|
|
|
|
spyOn(this.metadataModel, 'getMetadataByType').and.callFake(function () {
|
|
deferred.resolve(metadata);
|
|
return deferred.promise;
|
|
});
|
|
|
|
spyOn(this.objectValueMapperService, 'getFieldByName').and.callFake(function () {
|
|
return { dataType: 'widget', members: [] };
|
|
});
|
|
|
|
directiveElem = getCompiledElement();
|
|
divElem = directiveElem[0];
|
|
expect(divElem).toBeDefined();
|
|
isolatedScope = directiveElem.isolateScope();
|
|
expect(function () {
|
|
isolatedScope.loadDynamicSelectionValues('%%%');
|
|
isolatedScope.$apply();
|
|
}).not.toThrow();
|
|
});
|
|
|
|
it('should show tooltip as per label text and set the typeaheadMinLength value from configurationParameter', function () {
|
|
var directiveElem, isolatedScope,
|
|
metadata = {
|
|
configurationParameters: {
|
|
CustomizationTypeaheadLength: '5'
|
|
}
|
|
};
|
|
spyOn(this.metadataModel, 'getMetadataByType').and.callFake(function () {
|
|
deferred.resolve(metadata);
|
|
return deferred.promise;
|
|
});
|
|
|
|
directiveElem = getCompiledElement();
|
|
isolatedScope = directiveElem.isolateScope();
|
|
expect(isolatedScope.typeaheadMinLength).toBe(5);
|
|
expect(isolatedScope.tooltipToShow).toBe('Class');
|
|
});
|
|
|
|
it('should successfully watch data.setValueFlag if value is not empty', function () {
|
|
var directiveElem, isolatedScope;
|
|
spyOn(scope.$parent, '$emit');
|
|
directiveElem = getCompiledElement();
|
|
isolatedScope = directiveElem.isolateScope();
|
|
|
|
isolatedScope.data.setValueFlag = {
|
|
"index": 5000,
|
|
"name": "test",
|
|
"label": "test"
|
|
};
|
|
isolatedScope.$apply();
|
|
|
|
expect(isolatedScope.data.setValueFlag).toBe('#$#');
|
|
expect(isolatedScope.data.value.name).toBe('test');
|
|
expect(isolatedScope.$parent.$emit).toHaveBeenCalledWith(events.FIELD_VALUE_CHANGE, isolatedScope.data);
|
|
});
|
|
|
|
it('should successfully watch data.setValueFlag if value is empty', function () {
|
|
var directiveElem, isolatedScope;
|
|
spyOn(scope.$parent, '$emit');
|
|
directiveElem = getCompiledElement();
|
|
isolatedScope = directiveElem.isolateScope();
|
|
|
|
isolatedScope.data.setValueFlag = '';
|
|
isolatedScope.$apply();
|
|
|
|
expect(isolatedScope.data.setValueFlag).toBe('#$#');
|
|
expect(isolatedScope.data.value).toBe(null);
|
|
expect(isolatedScope.$parent.$emit).toHaveBeenCalledWith(events.FIELD_VALUE_CHANGE, isolatedScope.data);
|
|
});
|
|
|
|
it('should load populate list in case of workorder if user changes value in input box', function () {
|
|
var directiveElem, isolatedScope,
|
|
metadata = {
|
|
configurationParameters: {
|
|
CustomizationTypeaheadLength: '5'
|
|
}
|
|
};
|
|
field.dependency = [{
|
|
'name': 'locationCompany',
|
|
'label': 'Company',
|
|
'availability': 0,
|
|
'fieldUnavailableOn': []
|
|
}];
|
|
spyOn(this.metadataModel, 'getMetadataByType').and.callFake(function () {
|
|
deferred.resolve(metadata);
|
|
return deferred.promise;
|
|
});
|
|
spyOn(this.screenConfigurationModel, 'loadDynamicSelectionFieldLabels').and.callFake(function () {
|
|
deferred.resolve(metadata);
|
|
return deferred.promise;
|
|
});
|
|
directiveElem = getCompiledElement();
|
|
isolatedScope = directiveElem.isolateScope();
|
|
|
|
expect(function () {
|
|
isolatedScope.loadDynamicSelectionValues('%%%');
|
|
isolatedScope.$apply();
|
|
}).not.toThrow();
|
|
expect(this.screenConfigurationModel.loadDynamicSelectionFieldLabels).toHaveBeenCalledWith(ticket.type, field.menu, '%%%', {"locationCompany": "Calbro Services"}, null, field.name, scope.isNew);
|
|
});
|
|
|
|
describe('should load populate if user changes value in input box', function() {
|
|
var directiveElem, isolatedScope, metadata, fieldObj;
|
|
beforeEach(function () {
|
|
metadata = {
|
|
configurationParameters: {}
|
|
};
|
|
spyOn(this.metadataModel, 'getMetadataByType').and.callFake(function () {
|
|
deferred.resolve(metadata);
|
|
return deferred.promise;
|
|
});
|
|
spyOn(this.screenConfigurationModel, 'loadDynamicSelectionFieldLabels').and.callFake(function () {
|
|
deferred.resolve(metadata);
|
|
return deferred.promise;
|
|
});
|
|
spyOn(this.objectValueMapperService, 'getFieldByName').and.callFake(function () {
|
|
return fieldObj;
|
|
});
|
|
});
|
|
|
|
it('in case of locationCompany', function () {
|
|
field.dependency = [{
|
|
'name': 'locationCompany',
|
|
'label': 'Company'
|
|
}];
|
|
directiveElem = getCompiledElement();
|
|
isolatedScope = directiveElem.isolateScope();
|
|
|
|
expect(function () {
|
|
isolatedScope.loadDynamicSelectionValues('%%%');
|
|
isolatedScope.$apply();
|
|
}).not.toThrow();
|
|
expect(this.screenConfigurationModel.loadDynamicSelectionFieldLabels).toHaveBeenCalledWith(ticket.type, field.menu, '%%%', {"locationCompany": "Calbro Services"}, null, field.name, scope.isNew);
|
|
});
|
|
|
|
it('in case of dropdown data type', function () {
|
|
spyOn(this.objectValueMapperService, 'getExactValueByFieldName').and.returnValue('dropdownOption');
|
|
field.dependency = [{
|
|
'name': 'dropdown',
|
|
'label': 'Company'
|
|
}];
|
|
|
|
fieldObj = {
|
|
dataType: 'dropdown',
|
|
options: [
|
|
{
|
|
name: 'dropdownOption',
|
|
index: 1000
|
|
}
|
|
]
|
|
};
|
|
directiveElem = getCompiledElement();
|
|
isolatedScope = directiveElem.isolateScope();
|
|
|
|
expect(function () {
|
|
isolatedScope.loadDynamicSelectionValues('%%%');
|
|
isolatedScope.$apply();
|
|
}).not.toThrow();
|
|
expect(this.screenConfigurationModel.loadDynamicSelectionFieldLabels).toHaveBeenCalledWith(ticket.type, field.menu, '%%%', {dropdown: 1000}, null, field.name, scope.isNew);
|
|
});
|
|
|
|
it('in case of widget data type', function () {
|
|
spyOn(this.objectValueMapperService, 'getExactValueByFieldName').and.returnValue('dropdownOption');
|
|
field.dependency = [{
|
|
'name': 'widget',
|
|
'label': 'Company'
|
|
}];
|
|
|
|
fieldObj = {
|
|
dataType: 'widget',
|
|
members: [
|
|
{
|
|
dataType: 'dropdown',
|
|
options: [
|
|
{
|
|
name: 'dropdownOption',
|
|
index: 1000
|
|
}
|
|
]
|
|
}
|
|
]
|
|
};
|
|
directiveElem = getCompiledElement();
|
|
isolatedScope = directiveElem.isolateScope();
|
|
|
|
expect(function () {
|
|
isolatedScope.loadDynamicSelectionValues('%%%');
|
|
isolatedScope.$apply();
|
|
}).not.toThrow();
|
|
expect(this.screenConfigurationModel.loadDynamicSelectionFieldLabels).toHaveBeenCalledWith(ticket.type, field.menu, '%%%', {widget: 1000}, null, field.name, scope.isNew);
|
|
});
|
|
|
|
it('in case of asset type', function () {
|
|
spyOn(this.screenConfigurationService, 'getContextPropertyByMetadataMapping').and.returnValue('assetOption');
|
|
ticket.type = 'asset';
|
|
field.dependency = [{
|
|
'name': 'locationCompany',
|
|
'label': 'Company'
|
|
}];
|
|
|
|
directiveElem = getCompiledElement();
|
|
isolatedScope = directiveElem.isolateScope();
|
|
isolatedScope.getCustomFieldFieldValue = angular.noop;
|
|
|
|
expect(function () {
|
|
isolatedScope.loadDynamicSelectionValues('%%%');
|
|
isolatedScope.$apply();
|
|
}).not.toThrow();
|
|
expect(this.screenConfigurationModel.loadDynamicSelectionFieldLabels).toHaveBeenCalledWith(ticket.type, field.menu, '%%%', {locationCompany: 'assetOption'}, null, field.name, scope.isNew);
|
|
});
|
|
});
|
|
|
|
it('should select item if user click on any option in case of locationCompany', function () {
|
|
var directiveElem, isolatedScope, option;
|
|
|
|
directiveElem = getCompiledElement();
|
|
isolatedScope = directiveElem.isolateScope();
|
|
isolatedScope.onSelectCb = angular.noop;
|
|
option = {
|
|
"label": "Phylum",
|
|
"value": "Phylum"
|
|
};
|
|
|
|
spyOn(isolatedScope, '$emit');
|
|
|
|
isolatedScope.selectItem(option);
|
|
isolatedScope.$apply();
|
|
|
|
expect(isolatedScope.$emit).toHaveBeenCalledWith(events.CLEAR_DEPENDANT_FIELDS, field.name);
|
|
expect(isolatedScope.$emit).toHaveBeenCalledWith(events.CUSTOM_FIELD_VALUE_CHANGE);
|
|
expect(isolatedScope.data.value).toBe(option.value);
|
|
});
|
|
|
|
it('should select item if user click on any option in case of assigneeName', function () {
|
|
var directiveElem, isolatedScope, option;
|
|
|
|
field.name = 'assigneeName';
|
|
directiveElem = getCompiledElement();
|
|
isolatedScope = directiveElem.isolateScope();
|
|
isolatedScope.onSelectCb = angular.noop;
|
|
option = {
|
|
"label": "Phylum",
|
|
"value": "Phylum"
|
|
};
|
|
|
|
spyOn(isolatedScope, '$emit');
|
|
|
|
isolatedScope.selectItem(option);
|
|
isolatedScope.$apply();
|
|
|
|
expect(isolatedScope.$emit).toHaveBeenCalledWith(events.CLEAR_DEPENDANT_FIELDS, field.name);
|
|
expect(isolatedScope.$emit).toHaveBeenCalledWith(events.CUSTOM_FIELD_VALUE_CHANGE);
|
|
expect(isolatedScope.data.assigneeLoginId).toBe('Phylum');
|
|
});
|
|
|
|
it('should select item if user choose empty option in case of assigneeName', function () {
|
|
var directiveElem, isolatedScope;
|
|
|
|
directiveElem = getCompiledElement();
|
|
isolatedScope = directiveElem.isolateScope();
|
|
isolatedScope.onSelectCb = angular.noop;
|
|
|
|
spyOn(isolatedScope, '$emit');
|
|
|
|
isolatedScope.selectItem('');
|
|
isolatedScope.$apply();
|
|
|
|
expect(isolatedScope.$emit).toHaveBeenCalledWith(events.CUSTOM_FIELD_VALUE_CHANGE);
|
|
expect(isolatedScope.value).toBeUndefined();
|
|
});
|
|
});
|
|
|
|
describe('Test character custom field directive', function () {
|
|
var compile, scope, $httpBackend, events;
|
|
|
|
beforeEach(module('myitsmApp', 'templates'));
|
|
beforeEach(function () {
|
|
inject(function ($compile, $rootScope, $injector, _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/serverstates').respond(200);
|
|
$httpBackend.whenGET('/smartit/rest/sessionstatus?getLicenseKey=true').respond(200);
|
|
compile = $compile;
|
|
scope = $rootScope.$new();
|
|
events = _events_;
|
|
})
|
|
});
|
|
|
|
beforeEach(function () {
|
|
scope.field = {
|
|
type: 'characterField',
|
|
label: 'Work Order ID'
|
|
}
|
|
});
|
|
|
|
function getCompiledElement() {
|
|
var element = angular.element('<character-custom-field data="field" is-editable="false" char-limit="15" is-hide-label="true"></character-custom-field>'),
|
|
compiledElement = compile(element)(scope);
|
|
scope.$digest();
|
|
return compiledElement;
|
|
}
|
|
|
|
it('should compile', function () {
|
|
var directiveElem = getCompiledElement(),
|
|
divElem = directiveElem[0];
|
|
expect(divElem).toBeDefined();
|
|
});
|
|
|
|
it('should set max length to 15 if label is Task ID and show tooltip as per label text', function () {
|
|
var directiveElem, isolateScope;
|
|
scope.field.label = 'Task ID';
|
|
directiveElem = getCompiledElement();
|
|
isolateScope = directiveElem.isolateScope();
|
|
expect(isolateScope.status.isCollapsed).toBeTruthy();
|
|
expect(isolateScope.data.maxLength).toBe(15);
|
|
expect(isolateScope.tooltipToShow).toBe('Task ID');
|
|
});
|
|
|
|
it('should successfully watch data.setValueFlag', function () {
|
|
var directiveElem, isolateScope;
|
|
spyOn(scope.$parent, '$emit');
|
|
directiveElem = getCompiledElement();
|
|
isolateScope = directiveElem.isolateScope();
|
|
isolateScope.data.setValueFlag = 'test';
|
|
isolateScope.$apply();
|
|
expect(isolateScope.data.setValueFlag).toBe('#$#');
|
|
expect(isolateScope.$parent.$emit).toHaveBeenCalledWith(events.FIELD_VALUE_CHANGE, isolateScope.data);
|
|
});
|
|
});
|
|
|
|
describe('Test text area custom field directive', function () {
|
|
var compile, scope, $httpBackend, events;
|
|
|
|
beforeEach(module('myitsmApp', 'templates'));
|
|
beforeEach(function () {
|
|
inject(function ($compile, $rootScope, $injector, _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/serverstates').respond(200);
|
|
$httpBackend.whenGET('/smartit/rest/sessionstatus?getLicenseKey=true').respond(200);
|
|
compile = $compile;
|
|
scope = $rootScope.$new();
|
|
events = _events_;
|
|
})
|
|
});
|
|
|
|
beforeEach(function () {
|
|
scope.field = {
|
|
type: 'textAreaField',
|
|
label: 'Work Order ID',
|
|
maxLength: 15
|
|
}
|
|
});
|
|
|
|
function getCompiledElement() {
|
|
var element = angular.element('<textarea-custom-field data="field" is-editable="false" char-limit="15" is-hide-label="true"></textarea-custom-field>'),
|
|
compiledElement = compile(element)(scope);
|
|
scope.$digest();
|
|
return compiledElement;
|
|
}
|
|
|
|
it('should compile', function () {
|
|
var directiveElem = getCompiledElement(),
|
|
divElem = directiveElem[0];
|
|
expect(divElem).toBeDefined();
|
|
});
|
|
|
|
it('should show tooltip as per label text', function () {
|
|
var directiveElem, isolateScope;
|
|
directiveElem = getCompiledElement();
|
|
isolateScope = directiveElem.isolateScope();
|
|
expect(isolateScope.status.isCollapsed).toBeTruthy();
|
|
expect(isolateScope.tooltipToShow).toBe('Work Order ID');
|
|
});
|
|
|
|
it('should successfully watch data.setValueFlag', function () {
|
|
var directiveElem, isolateScope;
|
|
spyOn(scope.$parent, '$emit');
|
|
directiveElem = getCompiledElement();
|
|
isolateScope = directiveElem.isolateScope();
|
|
isolateScope.data.setValueFlag = 'test';
|
|
isolateScope.$apply();
|
|
expect(isolateScope.data.setValueFlag).toBe('#$#');
|
|
expect(isolateScope.$parent.$emit).toHaveBeenCalledWith(events.FIELD_VALUE_CHANGE, isolateScope.data);
|
|
});
|
|
});
|
|
|
|
describe('Test number custom field directive', function () {
|
|
var compile, scope, $httpBackend, events;
|
|
|
|
beforeEach(module('myitsmApp', 'templates'));
|
|
beforeEach(function () {
|
|
inject(function ($compile, $rootScope, $injector, _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/serverstates').respond(200);
|
|
$httpBackend.whenGET('/smartit/rest/sessionstatus?getLicenseKey=true').respond(200);
|
|
compile = $compile;
|
|
scope = $rootScope.$new();
|
|
events = _events_;
|
|
})
|
|
});
|
|
|
|
beforeEach(function () {
|
|
scope.field = {
|
|
type: 'numberField',
|
|
label: 'Work Order ID',
|
|
precision: 1
|
|
}
|
|
});
|
|
|
|
function getCompiledElement() {
|
|
var element = angular.element('<number-custom-field data="field" is-editable="false" is-hide-label="true"></number-custom-field>'),
|
|
compiledElement = compile(element)(scope);
|
|
scope.$digest();
|
|
return compiledElement;
|
|
}
|
|
|
|
it('should compile', function () {
|
|
var directiveElem = getCompiledElement(),
|
|
divElem = directiveElem[0];
|
|
expect(divElem).toBeDefined();
|
|
});
|
|
|
|
it('should set the step and show tooltip as per label text', function () {
|
|
var directiveElem, isolateScope;
|
|
directiveElem = getCompiledElement();
|
|
isolateScope = directiveElem.isolateScope();
|
|
expect(isolateScope.data.step).toBe(0.1);
|
|
expect(isolateScope.tooltipToShow).toBe('Work Order ID');
|
|
});
|
|
|
|
it('should successfully watch data.setValueFlag', function () {
|
|
var directiveElem, isolateScope;
|
|
spyOn(scope.$parent, '$emit');
|
|
directiveElem = getCompiledElement();
|
|
isolateScope = directiveElem.isolateScope();
|
|
isolateScope.data.setValueFlag = 'test';
|
|
isolateScope.$apply();
|
|
expect(isolateScope.data.setValueFlag).toBe('#$#');
|
|
expect(isolateScope.$parent.$emit).toHaveBeenCalledWith(events.FIELD_VALUE_CHANGE, isolateScope.data);
|
|
});
|
|
});
|
|
|
|
describe('Test date time custom field directive', function () {
|
|
var compile, scope, $httpBackend, events;
|
|
|
|
beforeEach(module('myitsmApp', 'templates'));
|
|
beforeEach(function () {
|
|
inject(function ($compile, $rootScope, $injector, _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/serverstates').respond(200);
|
|
$httpBackend.whenGET('/smartit/rest/sessionstatus?getLicenseKey=true').respond(200);
|
|
compile = $compile;
|
|
scope = $rootScope.$new();
|
|
events = _events_;
|
|
})
|
|
});
|
|
|
|
beforeEach(function () {
|
|
scope.field = {
|
|
type: 'dateTimeField',
|
|
label: 'Work Order ID',
|
|
precision: 1
|
|
}
|
|
});
|
|
|
|
function getCompiledElement() {
|
|
var element = angular.element('<date-time-custom-field data="field" is-editable="false" is-hide-label="true"></date-time-custom-field>'),
|
|
compiledElement = compile(element)(scope);
|
|
scope.$digest();
|
|
return compiledElement;
|
|
}
|
|
|
|
it('should compile', function () {
|
|
var directiveElem = getCompiledElement(),
|
|
divElem = directiveElem[0];
|
|
expect(divElem).toBeDefined();
|
|
});
|
|
|
|
it('should show tooltip as per label text', function () {
|
|
var directiveElem, isolateScope;
|
|
directiveElem = getCompiledElement();
|
|
isolateScope = directiveElem.isolateScope();
|
|
expect(isolateScope.tooltipToShow).toBe('Work Order ID');
|
|
});
|
|
|
|
it('should change the status on click of input box', function () {
|
|
var directiveElem, isolateScope;
|
|
directiveElem = getCompiledElement();
|
|
isolateScope = directiveElem.isolateScope();
|
|
expect(isolateScope.status.opened).toBeFalsy();
|
|
isolateScope.open(new Event('click'));
|
|
expect(isolateScope.status.opened).toBeTruthy();
|
|
});
|
|
|
|
it('should successfully watch data.setValueFlag', function () {
|
|
var directiveElem, isolateScope;
|
|
spyOn(scope.$parent, '$emit');
|
|
directiveElem = getCompiledElement();
|
|
isolateScope = directiveElem.isolateScope();
|
|
isolateScope.data.setValueFlag = 'test';
|
|
isolateScope.$apply();
|
|
expect(isolateScope.data.setValueFlag).toBe('#$#');
|
|
expect(isolateScope.$parent.$emit).toHaveBeenCalledWith(events.FIELD_VALUE_CHANGE, isolateScope.data);
|
|
});
|
|
});
|
|
|
|
describe('Test date custom field directive', function () {
|
|
var compile, scope, $httpBackend, events;
|
|
|
|
beforeEach(module('myitsmApp', 'templates'));
|
|
beforeEach(function () {
|
|
inject(function ($compile, $rootScope, $injector, _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/serverstates').respond(200);
|
|
$httpBackend.whenGET('/smartit/rest/sessionstatus?getLicenseKey=true').respond(200);
|
|
compile = $compile;
|
|
scope = $rootScope.$new();
|
|
events = _events_;
|
|
})
|
|
});
|
|
|
|
beforeEach(function () {
|
|
scope.field = {
|
|
type: 'dateField',
|
|
label: 'Work Order ID',
|
|
precision: 1
|
|
}
|
|
});
|
|
|
|
function getCompiledElement() {
|
|
var element = angular.element('<date-custom-field data="field" is-editable="false" is-hide-label="true"></date-custom-field>'),
|
|
compiledElement = compile(element)(scope);
|
|
scope.$digest();
|
|
return compiledElement;
|
|
}
|
|
|
|
it('should compile', function () {
|
|
var directiveElem = getCompiledElement(),
|
|
divElem = directiveElem[0];
|
|
expect(divElem).toBeDefined();
|
|
});
|
|
|
|
it('should show tooltip as per label text', function () {
|
|
var directiveElem, isolateScope;
|
|
directiveElem = getCompiledElement();
|
|
isolateScope = directiveElem.isolateScope();
|
|
expect(isolateScope.tooltipToShow).toBe('Work Order ID');
|
|
});
|
|
|
|
it('should change the status on click of input box', function () {
|
|
var directiveElem, isolateScope;
|
|
directiveElem = getCompiledElement();
|
|
isolateScope = directiveElem.isolateScope();
|
|
expect(isolateScope.status.opened).toBeFalsy();
|
|
isolateScope.open(new Event('click'));
|
|
expect(isolateScope.status.opened).toBeTruthy();
|
|
});
|
|
|
|
it('should successfully watch data.setValueFlag', function () {
|
|
var directiveElem, isolateScope;
|
|
spyOn(scope.$parent, '$emit');
|
|
directiveElem = getCompiledElement();
|
|
isolateScope = directiveElem.isolateScope();
|
|
isolateScope.data.setValueFlag = 'test';
|
|
isolateScope.$apply();
|
|
expect(isolateScope.data.setValueFlag).toBe('#$#');
|
|
expect(isolateScope.$parent.$emit).toHaveBeenCalledWith(events.FIELD_VALUE_CHANGE, isolateScope.data);
|
|
});
|
|
});
|
|
|
|
describe('Test time custom field directive', function () {
|
|
var compile, scope, $httpBackend, events;
|
|
|
|
beforeEach(module('myitsmApp', 'templates'));
|
|
beforeEach(function () {
|
|
inject(function ($compile, $rootScope, $injector, _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/serverstates').respond(200);
|
|
$httpBackend.whenGET('/smartit/rest/sessionstatus?getLicenseKey=true').respond(200);
|
|
compile = $compile;
|
|
scope = $rootScope.$new();
|
|
events = _events_;
|
|
})
|
|
});
|
|
|
|
beforeEach(function () {
|
|
scope.field = {
|
|
type: 'timeField',
|
|
label: 'Work Order ID',
|
|
precision: 1
|
|
}
|
|
});
|
|
|
|
function getCompiledElement() {
|
|
var element = angular.element('<time-custom-field data="field" is-editable="false" is-hide-label="true"></time-custom-field>'),
|
|
compiledElement = compile(element)(scope);
|
|
scope.$digest();
|
|
return compiledElement;
|
|
}
|
|
|
|
it('should compile', function () {
|
|
var directiveElem = getCompiledElement(),
|
|
divElem = directiveElem[0];
|
|
expect(divElem).toBeDefined();
|
|
});
|
|
|
|
it('should show tooltip as per label text', function () {
|
|
var directiveElem, isolateScope;
|
|
directiveElem = getCompiledElement();
|
|
isolateScope = directiveElem.isolateScope();
|
|
expect(isolateScope.tooltipToShow).toBe('Work Order ID');
|
|
});
|
|
|
|
it('should successfully watch data.setValueFlag', function () {
|
|
var directiveElem, isolateScope;
|
|
spyOn(scope.$parent, '$emit');
|
|
directiveElem = getCompiledElement();
|
|
isolateScope = directiveElem.isolateScope();
|
|
isolateScope.data.setValueFlag = 'test';
|
|
isolateScope.$apply();
|
|
expect(isolateScope.data.setValueFlag).toBe('#$#');
|
|
expect(isolateScope.$parent.$emit).toHaveBeenCalledWith(events.FIELD_VALUE_CHANGE, isolateScope.data);
|
|
});
|
|
});
|
|
|
|
describe('Test checkbox custom field directive', function () {
|
|
var compile, scope, $httpBackend, events, field, screenConfigurationModel;
|
|
|
|
beforeEach(module('myitsmApp', 'templates'));
|
|
beforeEach(function () {
|
|
inject(function ($compile, $rootScope, $injector, _events_, _screenConfigurationModel_) {
|
|
$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/serverstates').respond(200);
|
|
$httpBackend.whenGET('/smartit/rest/sessionstatus?getLicenseKey=true').respond(200);
|
|
compile = $compile;
|
|
scope = $rootScope.$new();
|
|
events = _events_;
|
|
screenConfigurationModel = _screenConfigurationModel_;
|
|
})
|
|
});
|
|
|
|
beforeEach(function () {
|
|
field = {
|
|
type: 'selectionField',
|
|
label: 'Work Order ID',
|
|
value: null,
|
|
name: 'company'
|
|
};
|
|
screenConfigurationModel.fieldLabels = [
|
|
{
|
|
name: 'company',
|
|
options: [{
|
|
"index": 1000,
|
|
"name": "Emergency",
|
|
"label": "Emergency"
|
|
}, {
|
|
"index": 2000,
|
|
"name": "Expedited",
|
|
"label": "Expedited"
|
|
}]
|
|
}
|
|
];
|
|
});
|
|
|
|
function getCompiledElement() {
|
|
scope.field = new FieldVO().build(field);
|
|
var element = angular.element('<checkbox-custom-field data="field" is-editable="false" is-hide-label="true"></checkbox-custom-field>'),
|
|
compiledElement = compile(element)(scope);
|
|
scope.$digest();
|
|
return compiledElement;
|
|
}
|
|
|
|
it('should compile', function () {
|
|
var directiveElem = getCompiledElement(),
|
|
divElem = directiveElem[0];
|
|
expect(divElem).toBeDefined();
|
|
});
|
|
|
|
it('should set the default checkbox options and show tooltip as per label text', function () {
|
|
var directiveElem, isolateScope;
|
|
directiveElem = getCompiledElement();
|
|
isolateScope = directiveElem.isolateScope();
|
|
expect(isolateScope.tooltipToShow).toBe('Work Order ID');
|
|
expect(isolateScope.cbOption.index).toBe(0);
|
|
});
|
|
|
|
it('should set the checkbox options to empty if it is not a selection field', function () {
|
|
var directiveElem, isolateScope;
|
|
field.type = 'testField';
|
|
directiveElem = getCompiledElement();
|
|
isolateScope = directiveElem.isolateScope();
|
|
expect(isolateScope.cbOption.index).toBe(-1);
|
|
expect(isolateScope.data.value).toBe(-1);
|
|
});
|
|
|
|
it('should successfully watch data.setValueFlag and set the item value according to checkbox index if setValueFlag has some value', function () {
|
|
var directiveElem, isolateScope;
|
|
spyOn(scope.$parent, '$emit');
|
|
field.value = 1;
|
|
directiveElem = getCompiledElement();
|
|
isolateScope = directiveElem.isolateScope();
|
|
isolateScope.data.setValueFlag = 'test';
|
|
isolateScope.$apply();
|
|
expect(isolateScope.data.setValueFlag).toBe('#$#');
|
|
expect(isolateScope.data.value).toBe(0);
|
|
expect(isolateScope.$parent.$emit).toHaveBeenCalledWith(events.FIELD_VALUE_CHANGE, isolateScope.data);
|
|
});
|
|
|
|
it('should successfully watch data.setValueFlag and clear the item value if setValueFlag is empty', function () {
|
|
var directiveElem, isolateScope;
|
|
spyOn(scope.$parent, '$emit');
|
|
field.value = 1;
|
|
directiveElem = getCompiledElement();
|
|
isolateScope = directiveElem.isolateScope();
|
|
isolateScope.data.setValueFlag = '';
|
|
isolateScope.$apply();
|
|
expect(isolateScope.data.setValueFlag).toBe('#$#');
|
|
expect(isolateScope.data.value).toBe(null);
|
|
expect(isolateScope.$parent.$emit).toHaveBeenCalledWith(events.FIELD_VALUE_CHANGE, isolateScope.data);
|
|
});
|
|
|
|
it('should successfully watch data.setValueFlag and set the item value according to checkbox index if setValueFlag has some value and type is not selectionField', function () {
|
|
var directiveElem, isolateScope;
|
|
spyOn(scope.$parent, '$emit');
|
|
field.value = 1;
|
|
field.type = 'testField';
|
|
directiveElem = getCompiledElement();
|
|
isolateScope = directiveElem.isolateScope();
|
|
isolateScope.data.setValueFlag = 'test';
|
|
isolateScope.$apply();
|
|
expect(isolateScope.data.setValueFlag).toBe('#$#');
|
|
expect(isolateScope.data.value).toBe(1000);
|
|
expect(isolateScope.$parent.$emit).toHaveBeenCalledWith(events.FIELD_VALUE_CHANGE, isolateScope.data);
|
|
});
|
|
|
|
it('should successfully watch data.setValueFlag and clear the item value if setValueFlag is set to -1 and type is not selectionField', function () {
|
|
var directiveElem, isolateScope;
|
|
spyOn(scope.$parent, '$emit');
|
|
field.value = -1;
|
|
field.type = 'testField';
|
|
directiveElem = getCompiledElement();
|
|
isolateScope = directiveElem.isolateScope();
|
|
isolateScope.data.setValueFlag = -1;
|
|
isolateScope.$apply();
|
|
expect(isolateScope.data.setValueFlag).toBe('#$#');
|
|
expect(isolateScope.data.value).toBe(-1);
|
|
expect(isolateScope.$parent.$emit).toHaveBeenCalledWith(events.FIELD_VALUE_CHANGE, isolateScope.data);
|
|
});
|
|
});
|
|
|
|
describe('Test valid number directive', function () {
|
|
var compile, scope, $httpBackend, ngModelCtrl, data, $timeout;
|
|
|
|
beforeEach(module('myitsmApp', 'templates'));
|
|
beforeEach(function () {
|
|
inject(function ($compile, $rootScope, $injector, _$timeout_) {
|
|
$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/serverstates').respond(200);
|
|
$httpBackend.whenGET('/smartit/rest/sessionstatus?getLicenseKey=true').respond(200);
|
|
compile = $compile;
|
|
scope = $rootScope.$new();
|
|
$timeout = _$timeout_;
|
|
})
|
|
});
|
|
|
|
beforeEach(function () {
|
|
data = {
|
|
precision: 1,
|
|
step: 5,
|
|
dataType: 'float',
|
|
isRequired: true
|
|
};
|
|
scope.value = 123.5;
|
|
});
|
|
|
|
function getCompiledElement() {
|
|
var element = angular.element('<input type="number" valid-number precision="' + data.precision + '" step="' + data.step + '" number-type="' + data.dataType + '" number-required="' + data.isRequired + '" ng-model="scope.value"/>'),
|
|
compiledElement = compile(element)(scope);
|
|
ngModelCtrl = element.controller('ngModel');
|
|
scope.$digest();
|
|
return compiledElement;
|
|
}
|
|
|
|
it('should compile', function () {
|
|
var directiveElem = getCompiledElement(),
|
|
divElem = directiveElem[0];
|
|
expect(divElem).toBeDefined();
|
|
});
|
|
|
|
it('should set the value if value does not have precision', function () {
|
|
var directiveElem = getCompiledElement(),
|
|
directiveScope = directiveElem.scope();
|
|
ngModelCtrl.$setViewValue(123);
|
|
|
|
expect(directiveScope.scope.value).toBe(123);
|
|
expect(ngModelCtrl.$valid).toBeTruthy();
|
|
});
|
|
|
|
it('should set the proper value if precision is 0 and but set value with different precision', function () {
|
|
var directiveElem, directiveScope;
|
|
data.precision = 0;
|
|
scope.value = 123;
|
|
directiveElem = getCompiledElement();
|
|
directiveScope = directiveElem.scope();
|
|
ngModelCtrl.$setViewValue(12.3);
|
|
|
|
$timeout.flush();
|
|
directiveScope.$apply();
|
|
|
|
expect(directiveScope.scope.value).toBe(12);
|
|
expect(ngModelCtrl.$valid).toBeTruthy();
|
|
});
|
|
|
|
it('should not set the value if precision is 2 and but set value with different precision', function () {
|
|
var directiveElem, directiveScope;
|
|
data.precision = 2;
|
|
scope.value = 123.50;
|
|
directiveElem = getCompiledElement();
|
|
directiveScope = directiveElem.scope();
|
|
ngModelCtrl.$setViewValue(12.345);
|
|
|
|
$timeout.flush();
|
|
directiveScope.$apply();
|
|
|
|
expect(directiveScope.scope.value).toBe(12.34);
|
|
expect(ngModelCtrl.$valid).toBeTruthy();
|
|
});
|
|
|
|
it('should set the new value if value is valid', function () {
|
|
var directiveElem, directiveScope;
|
|
data.precision = 2;
|
|
scope.value = 123.50;
|
|
directiveElem = getCompiledElement();
|
|
directiveScope = directiveElem.scope();
|
|
ngModelCtrl.$setViewValue(12.34);
|
|
|
|
expect(directiveScope.scope.value).toBe(12.34);
|
|
expect(ngModelCtrl.$valid).toBeTruthy();
|
|
});
|
|
|
|
it('should set the validity to false if there is no value', function () {
|
|
ngModelCtrl.$setViewValue('');
|
|
|
|
expect(ngModelCtrl.$valid).toBeFalsy();
|
|
});
|
|
|
|
it('should set the validity to true in case of required false', function () {
|
|
data.isRequired = false;
|
|
ngModelCtrl.$setViewValue(123);
|
|
|
|
expect(ngModelCtrl.$valid).toBeTruthy();
|
|
});
|
|
});
|
|
|
|
describe('Test number Input directive', function () {
|
|
var compile, scope, $httpBackend, data;
|
|
|
|
beforeEach(module('myitsmApp', 'templates'));
|
|
beforeEach(function () {
|
|
inject(function ($compile, $rootScope, $injector) {
|
|
$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/serverstates').respond(200);
|
|
$httpBackend.whenGET('/smartit/rest/sessionstatus?getLicenseKey=true').respond(200);
|
|
compile = $compile;
|
|
scope = $rootScope.$new();
|
|
})
|
|
});
|
|
|
|
beforeEach(function () {
|
|
data = {
|
|
precision: 1,
|
|
min: 5,
|
|
max: 100,
|
|
numberType: 'decimal'
|
|
};
|
|
scope.value = 123.5;
|
|
});
|
|
|
|
function getCompiledElement() {
|
|
var element = angular.element('<input type="number" number-input precision="' + data.precision + '" min="' + data.min + '" max="' + data.max + '" number-type="' + data.numberType + '" value="' + scope.value + '" ng-model="scope.value"/>'),
|
|
compiledElement = compile(element)(scope);
|
|
scope.$digest();
|
|
return compiledElement;
|
|
}
|
|
|
|
it('should compile', function () {
|
|
var directiveElem = getCompiledElement(),
|
|
divElem = directiveElem[0];
|
|
expect(divElem).toBeDefined();
|
|
});
|
|
|
|
it('should initialize the ui spinner and input mask for integer', function () {
|
|
var directiveElem;
|
|
data.precision = 'not a numer';
|
|
data.numberType = 'integer';
|
|
directiveElem = getCompiledElement();
|
|
expect(directiveElem.attr('role')).toBe('spinbutton');
|
|
});
|
|
|
|
it('should initialize the ui spinner and input mask for real', function () {
|
|
var directiveElem;
|
|
data.precision = 'not a numer';
|
|
data.numberType = 'real';
|
|
directiveElem = getCompiledElement();
|
|
expect(directiveElem.attr('role')).toBe('spinbutton');
|
|
});
|
|
}); |