SmartIT_Extensions/BMC/smart-it-full/test/app/custom-widgets/organization-field-directiv...

217 lines
7.9 KiB
JavaScript

describe('Test organization directive', function () {
var compile, scope, $httpBackend, originalTimeout, objectValueMapperService, events;
beforeEach(module('myitsmApp','templates'));
beforeEach(function(){
inject(function($compile, $rootScope, $injector, _objectValueMapperService_, _events_, searchModel){
$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_;
this.searchModel = searchModel;
events = _events_;
});
});
beforeEach(function() {
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
});
afterEach(function() {
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
});
beforeEach(inject(function ($q, $rootScope) {
var deferred = $q.defer(), success = {
items: [
{
"name": "Human Resources",
"attributeMap": {
"companyName": "Calbro Services",
"id": "POR000000000011"
},
"id": "AG00123F73CF5EDVYTSQN8FaAAZsUA",
"companyName": "Calbro Services"
},
{
"name": "Information Technology",
"attributeMap": {
"companyName": "Calbro Services",
"id": "POR000000000013"
},
"id": "AG00123F73CF5EDVYTSQZsFaAAaMUA",
"companyName": "Calbro Services"
}
],
exceedsChunkSize: true
};
spyOn(this.searchModel, 'getOrganizationsByTextAndCompany').and.callFake(function () {
deferred.resolve(success);
return deferred.promise;
});
}));
function getCompiledElement(){
var element = angular.element('<organization-field data="field" is-editable="true"></organization-field>');
var compiledElement = compile(element)(scope);
scope.$digest();
return compiledElement;
}
it('should compile', function(){
var field = {
"name": "organization",
"label": "Organization",
"arFieldName": "",
"type": "organization",
"dataType": "widget",
"valueField": null,
"members": [
{
"name": "organization",
"label": "",
"ootb": true,
"parentId": "AGGAA5V0HG8SIAOT55KTAAH06KU0I8"
}
],
"value": {
"organization": "Information Technology"
},
"setValueFlag": "#$#",
"id": "AGGAA5V0HG8SIAOT55KTAAH06KU0I8",
"ootb": true,
"$$hashKey": "object:1409",
"ootbValue": "Information Technology"
};
scope.field = new FieldVO().build(field);
var directiveElem = getCompiledElement();
var divElem = directiveElem[0];
expect(divElem).toBeDefined();
});
it('should invoke watch for setValueFlag', function(){
var field = {
"id": "AGGAA5V0HG8SIAOTIDJZAB1ZVENZN5",
"name": "Organization",
"type": "organization",
"dataType": "widget",
"value": {"customerEmail": "cneramani@petramco.com"},
"accessible": true
};
scope.field = new FieldVO().build(field);
scope.field.setValueFlag = "Some text";
scope.$digest();
spyOn(objectValueMapperService, 'getFieldByName').and.callFake(function () {
return { dataType: 'widget', value: {} };
});
getCompiledElement();
expect(scope.field.setValueFlag).toEqual('#$#');
});
it('should get organization list', function(){
var field = {
"name": "organization",
"label": "Organization",
"members": [
{
"name": "organization",
"label": ""
}
],
"value": {
"organization": "Information Technology"
},
"ootbValue": "Information Technology"
};
scope.field = new FieldVO().build(field);
spyOn(objectValueMapperService, 'getValueByFieldName').and.callFake(function () {
return {
"firstName": "Allen",
"lastName": "Allbrook",
"company": {
"name": "Calbro Services"
},
"site": {
"name": "Amsterdam Support Center",
"address": {
"street": "1114 Eighth Avenue, 31st Floor",
"city": "New York",
"state": "New York",
"country": "United States",
"zip": "10036",
"address": "1114 Eighth Avenue, 31st Floor\r\nNew York, New York 10036\r\nUnited States"
},
"region": "Europe",
"siteGroup": "Amsterdam"
},
"id": "Allen",
"fullName": "Allen Allbrook"
};
});
var directiveElem = getCompiledElement(), term = '%%%',
isolatedScope = directiveElem.isolateScope();
isolatedScope.getList(term);
scope.$apply();
expect(isolatedScope.dataLoading).toEqual(false);
});
it('should clear organization', function(){
var field = {
"name": "organization",
"label": "Organization",
"members": [
{
"name": "organization",
"label": ""
}
],
"value": {
"organization": "Information Technology"
},
"ootbValue": "Information Technology"
};
scope.field = new FieldVO().build(field);
spyOn(objectValueMapperService, 'getFieldByName').and.callFake(function () {
return { dataType: 'widget', value: {} };
});
var directiveElem = getCompiledElement(),
isolatedScope = directiveElem.isolateScope();
isolatedScope.clearValue();
});
it('should listen to DISCARD_CHANGES and assign data', inject(function ($rootScope) {
var field = {
"id": "AGGAA5V0HG8SIAOTIDJZAB1ZVENZN5",
"name": "customerEmail",
"type": "emailField",
"dataType": "widget",
"value": {"customerEmail": "cneramani@petramco.com", internetEmail: "Some Data"},
"accessible": true,
"members": [
{
"id": "AGGAA5V0HG8SIAOTI9NJAAA49ATLTQ",
"name": "internetEmail",
"itsmFieldId": 1000000048
}
]
};
scope.field = new FieldVO().build(field);
spyOn(objectValueMapperService, 'getFieldByName').and.callFake(function () {
return { dataType: 'widget', value: {ootbKey: 'Some Data'} };
});
scope.$digest();
var directiveElem = getCompiledElement();
var isoScope = directiveElem.isolateScope();
isoScope.$parent.$broadcast(events.DISCARD_CHANGES);
expect(scope.field.ootbValue).toEqual('Some Data');
}));
});