185 lines
6.7 KiB
JavaScript
185 lines
6.7 KiB
JavaScript
describe('Test support group field directive', function () {
|
|
var compile, scope, $httpBackend, originalTimeout, objectValueMapperService, events;
|
|
|
|
beforeEach(module('myitsmApp','templates'));
|
|
beforeEach(function(){
|
|
inject(function($compile, $rootScope, $injector, _objectValueMapperService_, _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/serverstates').respond(200);
|
|
$httpBackend.whenGET('/smartit/rest/sessionstatus?getLicenseKey=true').respond(200);
|
|
compile = $compile;
|
|
scope = $rootScope.$new();
|
|
objectValueMapperService = _objectValueMapperService_;
|
|
events = _events_;
|
|
});
|
|
});
|
|
|
|
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('<support-group-field data="field" is-editable="true"></support-group-field>');
|
|
var compiledElement = compile(element)(scope);
|
|
scope.$digest();
|
|
return compiledElement;
|
|
}
|
|
|
|
it('should compile', function(){
|
|
var field = {
|
|
"name": "assigneeSupportGroups",
|
|
"label": "Support Group",
|
|
"arFieldName": "",
|
|
"type": "supportGroups",
|
|
"members": [
|
|
{
|
|
"name": "supportGroups",
|
|
"label": "Assigned Group",
|
|
"dependency": [
|
|
{
|
|
"name": "assignedSupportOrganization",
|
|
"label": "Assigned Support Organization",
|
|
"availability": 0,
|
|
"fieldUnavailableOn": []
|
|
}
|
|
]
|
|
}
|
|
],
|
|
"value": {
|
|
"name": "Service Desk",
|
|
"company": {
|
|
"name": "Calbro Services"
|
|
},
|
|
"organization": "IT Support",
|
|
"id": "SGP000000000011",
|
|
"supportGroups": "Service Desk"
|
|
},
|
|
"setValueFlag": "#$#",
|
|
"id": "AGGAA5V0HG8SIAOTBA0YABEWWDN4XH"
|
|
};
|
|
scope.field = new FieldVO().build(field);
|
|
var directiveElem = getCompiledElement();
|
|
var divElem = directiveElem[0];
|
|
expect(divElem).toBeDefined();
|
|
});
|
|
|
|
it('should invoke widget value change', function(){
|
|
var field = {
|
|
"name": "assigneeSupportGroups",
|
|
"label": "Support Group",
|
|
"arFieldName": "",
|
|
"type": "supportGroups",
|
|
"members": [
|
|
{
|
|
"name": "supportGroups",
|
|
"label": "Assigned Group",
|
|
"dependency": [
|
|
{
|
|
"name": "assignedSupportOrganization",
|
|
"label": "Assigned Support Organization",
|
|
"availability": 0,
|
|
"fieldUnavailableOn": []
|
|
}
|
|
]
|
|
}
|
|
],
|
|
"value": {
|
|
"name": "Service Desk",
|
|
"company": {
|
|
"name": "Calbro Services"
|
|
},
|
|
"organization": "IT Support",
|
|
"id": "SGP000000000011",
|
|
"supportGroups": "Service Desk"
|
|
},
|
|
"setValueFlag": "#$#",
|
|
"id": "AGGAA5V0HG8SIAOTBA0YABEWWDN4XH"
|
|
};
|
|
scope.field = new FieldVO().build(field);
|
|
|
|
var directiveElem = getCompiledElement(),
|
|
isolatedScope = directiveElem.isolateScope();
|
|
spyOn(isolatedScope, '$emit');
|
|
isolatedScope.$digest();
|
|
isolatedScope.onFieldValueChange();
|
|
expect(isolatedScope.$emit).toHaveBeenCalledWith(events.WIDGET_VALUE_CHANGE, jasmine.any(Object));
|
|
});
|
|
|
|
it('should open assign blade', function(){
|
|
var field = {
|
|
"name": "assigneeSupportGroups",
|
|
"label": "Support Group",
|
|
"arFieldName": "",
|
|
"type": "supportGroups",
|
|
"members": [
|
|
{
|
|
"name": "supportGroups",
|
|
"label": "Assigned Group",
|
|
"dependency": [
|
|
{
|
|
"name": "assignedSupportOrganization",
|
|
"label": "Assigned Support Organization",
|
|
"availability": 0,
|
|
"fieldUnavailableOn": []
|
|
}
|
|
]
|
|
}
|
|
],
|
|
"value": {
|
|
"name": "Service Desk",
|
|
"company": {
|
|
"name": "Calbro Services"
|
|
},
|
|
"organization": "IT Support",
|
|
"id": "SGP000000000011",
|
|
"supportGroups": "Service Desk"
|
|
},
|
|
"setValueFlag": "#$#",
|
|
"id": "AGGAA5V0HG8SIAOTBA0YABEWWDN4XH"
|
|
};
|
|
scope.field = new FieldVO().build(field);
|
|
|
|
var directiveElem = getCompiledElement(),
|
|
isolatedScope = directiveElem.isolateScope();
|
|
spyOn(isolatedScope, '$emit');
|
|
isolatedScope.$digest();
|
|
isolatedScope.openAssignBlade(events);
|
|
expect(isolatedScope.$emit).toHaveBeenCalledWith(events.SHOW_ASSIGN_TICKET_BLADE, jasmine.any(Object));
|
|
});
|
|
|
|
it('should invoke watch for setValueFlag', function(){
|
|
var field = {
|
|
"name": "assigneeSupportGroups",
|
|
"label": "Support Group",
|
|
"arFieldName": "",
|
|
"type": "supportGroups",
|
|
"members": [
|
|
{
|
|
"name": "supportGroups",
|
|
"label": "Assigned Group",
|
|
"dependency": [
|
|
{
|
|
"name": "assignedSupportOrganization",
|
|
"label": "Assigned Support Organization"
|
|
}
|
|
]
|
|
}
|
|
]
|
|
};
|
|
scope.field = new FieldVO().build(field);
|
|
scope.field.setValueFlag = {name: false, supportGroups: 'Service Desk'};
|
|
scope.$digest();
|
|
var directiveElem = getCompiledElement();
|
|
|
|
expect(scope.field.setValueFlag).toEqual('#$#');
|
|
});
|
|
}); |