2017-10-23 14:25:47 +00:00
|
|
|
describe('Directive focus', () => {
|
|
|
|
let $scope;
|
|
|
|
let $element;
|
|
|
|
let compile;
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('vnCore'));
|
2017-10-23 14:25:47 +00:00
|
|
|
|
|
|
|
compile = (_element, _childElement) => {
|
2020-04-01 14:05:43 +00:00
|
|
|
inject(($compile, $rootScope, $flushPendingTasks) => {
|
2017-10-23 14:25:47 +00:00
|
|
|
$scope = $rootScope.$new();
|
|
|
|
$element = angular.element(_element);
|
2018-12-22 10:59:26 +00:00
|
|
|
if (_childElement)
|
2017-10-23 14:25:47 +00:00
|
|
|
$element[0].firstChild.focus = jasmine.createSpy(focus);
|
2018-12-22 10:59:26 +00:00
|
|
|
|
2017-10-23 14:25:47 +00:00
|
|
|
$element[0].focus = jasmine.createSpy('focus');
|
|
|
|
$element[0].select = jasmine.createSpy('select');
|
|
|
|
$compile($element)($scope);
|
2020-04-01 14:05:43 +00:00
|
|
|
$flushPendingTasks();
|
2017-10-23 14:25:47 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2019-07-02 10:12:15 +00:00
|
|
|
expect($element[0].firstChild.focus).toHaveBeenCalledWith();
|
2017-10-23 14:25:47 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
2019-10-22 11:44:36 +00:00
|
|
|
$scope.$apply();
|
2017-10-23 14:25:47 +00:00
|
|
|
|
|
|
|
expect($element[0].select).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|