101 lines
4.3 KiB
JavaScript
101 lines
4.3 KiB
JavaScript
describe('Test expressionBuilder directive', function () {
|
|
'use strict';
|
|
|
|
var compile, scope, $httpBackend, elementScope, element, expressionStart, textFieldActionURL;
|
|
|
|
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('/ux/rest/v2/metadata?type=global').respond(200);
|
|
$httpBackend.whenGET('/ux/rest/v2/metadata?type=change').respond(200);
|
|
$httpBackend.whenGET('/ux/restapi/person/supportgroupperson').respond(200);
|
|
compile = $compile;
|
|
scope = $rootScope.$new();
|
|
});
|
|
});
|
|
|
|
function getCompiledElement(){
|
|
element = angular.element('<expression-builder></expression-builder>');
|
|
var compiledElement = compile(element)(scope);
|
|
scope.$digest();
|
|
$('body').append(element);
|
|
return compiledElement;
|
|
}
|
|
|
|
it('should compile', function(){
|
|
var directiveElem = getCompiledElement();
|
|
var divElem = directiveElem[0];
|
|
expect(divElem).toBeDefined();
|
|
});
|
|
|
|
it('should run handleBodyKeyDown method',function(){
|
|
elementScope = element.isolateScope();
|
|
elementScope.expression = '$status == "Assigned"';
|
|
expressionStart = 0;
|
|
elementScope.handleBodyKeyDown({target:{value:'[1234'},key: '$'});
|
|
expect(elementScope.accelerators.showAcceleratorsList).toBeTruthy();
|
|
});
|
|
|
|
it('should run handleBodyChange method',function(){
|
|
elementScope.acceleratorsList = [];
|
|
var actionObj = new ActionVO();
|
|
elementScope.accelerators.showAcceleratorsList = false;
|
|
actionObj.url = 'http://www.bmc.com';
|
|
elementScope.openActionItem = actionObj;
|
|
|
|
elementScope.handleBodyChange({target:{value:'[1234',selectionEnd:0}});
|
|
|
|
elementScope.handleBodyChange({target:{value:'[1234',selectionEnd:0}, ctrlKey:true});
|
|
|
|
elementScope.handleBodyChange({target:{value:'[1234',selectionEnd:0}, keyCode :38});
|
|
|
|
elementScope.handleBodyChange({target:{value:'[1234',selectionEnd:0}, keyCode :40});
|
|
elementScope.acceleratorsList[{name:'dummy',value:'dummy'}];
|
|
elementScope.handleBodyChange({target:{value:'[1234',selectionEnd:0}, keyCode :27});
|
|
elementScope.accelerators.showAcceleratorsList = true;
|
|
|
|
elementScope.handleBodyChange({target:{value:'1234',selectionEnd:0}, keyCode :9});
|
|
expect(elementScope.accelerators.showAcceleratorsList).toBeTruthy();
|
|
});
|
|
|
|
it('should run handleBodyClick method',function(){
|
|
elementScope.accelerators.showAcceleratorsList = true;
|
|
elementScope.handleBodyClick({target:{value:'[1234', selectionEnd:0}});
|
|
expect(elementScope.accelerators.showAcceleratorsList).toBeTruthy();
|
|
});
|
|
|
|
it('should run acceleratorMouseover method',function(){
|
|
elementScope.acceleratorMouseover({index:123});
|
|
expect(elementScope.typeAheadListPos).toEqual({index:123});
|
|
});
|
|
|
|
it('should run insertAcceleratorText method',function(){
|
|
var actionObj = new ActionVO();
|
|
elementScope.accelerators.showAcceleratorsList = false;
|
|
actionObj.url = 'http://www.bmc.com';
|
|
elementScope.openActionItem = actionObj;
|
|
elementScope.handleBodyChange({target:{value:'[1234',selectionEnd:0}});
|
|
textFieldActionURL = {value:'[1234'};
|
|
elementScope.accelerators.expression = true;
|
|
elementScope.insertAcceleratorText({name:'TestAccelerator'});
|
|
expect(!!elementScope.accelerators.expression).toBeFalsy();
|
|
elementScope.accelerators.expression = true;
|
|
elementScope.insertAcceleratorText({name:'TestAccelerator'});
|
|
expect(elementScope.accelerators.expression).toEqual('');
|
|
});
|
|
|
|
it('should run hideTypeAheadPopup method',function(){
|
|
elementScope.hideTypeAheadPopup();
|
|
expect(elementScope.accelerators.showAcceleratorsList).toBeFalsy();
|
|
});
|
|
|
|
it('should run acceleratorsHelp method',function(){
|
|
elementScope.acceleratorsHelp();
|
|
expect(elementScope.accelerators.showAcceleratorsList).toBeTruthy();
|
|
});
|
|
}); |