44 lines
1.4 KiB
JavaScript
44 lines
1.4 KiB
JavaScript
describe('Test character limit message directive', function () {
|
|
var compile, scope, $httpBackend;
|
|
|
|
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());
|
|
compile = $compile;
|
|
scope = $rootScope.$new();
|
|
});
|
|
});
|
|
|
|
function getCompiledElement(field, limit){
|
|
var element;
|
|
if (limit) {
|
|
element = angular.element('<character-limit-message field="field" limit='+limit+'></character-limit-message>');
|
|
} else {
|
|
element = angular.element('<character-limit-message field="field"></character-limit-message>');
|
|
}
|
|
var compiledElement = compile(element)(scope);
|
|
scope.$digest();
|
|
return compiledElement;
|
|
}
|
|
|
|
it('should compile', function(){
|
|
var field = "abc";
|
|
var directiveElem = getCompiledElement(scope.field, 20);
|
|
var divElem = directiveElem[0];
|
|
expect(divElem).toBeDefined();
|
|
expect(directiveElem.find('.ticket-summary__character-limit').length).not.toBeLessThan(1);
|
|
});
|
|
|
|
it('should not show the message if no limit', function(){
|
|
var field = "abc";
|
|
var directiveElem = getCompiledElement(scope.field);
|
|
var divElem = directiveElem[0];
|
|
expect(directiveElem.find('.ticket-summary__character-limit').length).toBeLessThan(1);
|
|
});
|
|
|
|
}); |