46 lines
1.4 KiB
JavaScript
46 lines
1.4 KiB
JavaScript
describe('Directive focus', () => {
|
|
let $scope;
|
|
let $element;
|
|
let compile;
|
|
|
|
beforeEach(ngModule('vnCore'));
|
|
|
|
compile = (_element, _childElement) => {
|
|
inject(($compile, $rootScope) => {
|
|
$scope = $rootScope.$new();
|
|
$element = angular.element(_element);
|
|
if (_childElement)
|
|
$element[0].firstChild.focus = jasmine.createSpy(focus);
|
|
|
|
$element[0].focus = jasmine.createSpy('focus');
|
|
$element[0].select = jasmine.createSpy('select');
|
|
$compile($element)($scope);
|
|
$scope.$digest();
|
|
});
|
|
};
|
|
|
|
it('should call the querySelector function upon the input to redefine it with the expected selector then call focus', () => {
|
|
let html = `<div vn-focus><input></input></div>`;
|
|
let childHtml = '<input></input>';
|
|
compile(html, childHtml);
|
|
|
|
expect($element[0].firstChild.focus).toHaveBeenCalledWith();
|
|
});
|
|
|
|
|
|
it('should call focus function on the element', () => {
|
|
let html = `<input vn-focus></input>`;
|
|
compile(html);
|
|
|
|
expect($element[0].focus).toHaveBeenCalledWith();
|
|
});
|
|
|
|
it('should call select function on the element', () => {
|
|
let html = `<input vn-focus></input>`;
|
|
compile(html);
|
|
$scope.$apply();
|
|
|
|
expect($element[0].select).toHaveBeenCalledWith();
|
|
});
|
|
});
|