2015-08-25 21:11:18 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
2015-09-01 01:31:03 +00:00
|
|
|
describe('focusElement Directive', function() {
|
2015-08-25 21:11:18 +00:00
|
|
|
var elementToFocus, scope;
|
|
|
|
|
|
|
|
|
|
beforeEach(module('habitrpg'));
|
|
|
|
|
|
|
|
|
|
beforeEach(inject(function($rootScope, $compile) {
|
|
|
|
|
scope = $rootScope.$new();
|
|
|
|
|
|
|
|
|
|
scope.focusThisLink = false;
|
2015-09-01 01:31:03 +00:00
|
|
|
var element = '<input data-focus-element="focusThisLink" />';
|
2015-08-25 21:11:18 +00:00
|
|
|
|
|
|
|
|
elementToFocus = $compile(element)(scope);
|
|
|
|
|
scope.$digest();
|
|
|
|
|
}));
|
|
|
|
|
|
2015-09-01 01:35:23 +00:00
|
|
|
it('places focus on the element it is applied to when the expression it binds to evaluates to true', inject(function($timeout) {
|
|
|
|
|
var focusSpy = sandbox.spy();
|
2015-08-31 21:49:34 +00:00
|
|
|
|
2015-09-01 01:35:23 +00:00
|
|
|
elementToFocus.appendTo(document.body);
|
|
|
|
|
elementToFocus.on('focus', focusSpy);
|
|
|
|
|
scope.focusThisLink = true;
|
|
|
|
|
scope.$digest();
|
2015-08-25 21:11:18 +00:00
|
|
|
|
2015-09-01 01:35:23 +00:00
|
|
|
$timeout.flush();
|
|
|
|
|
expect(document.activeElement.dataset.focusElement).to.eql("focusThisLink");
|
|
|
|
|
expect(focusSpy).to.have.been.called;
|
|
|
|
|
}));
|
2015-08-25 21:11:18 +00:00
|
|
|
});
|