Merge branch 'TheHollidayInn-directives-test-task-focus' into develop

This commit is contained in:
Blade Barringer
2015-08-31 20:36:07 -05:00
8 changed files with 39 additions and 63 deletions
@@ -0,0 +1,30 @@
'use strict';
describe('focusElement Directive', function() {
var elementToFocus, scope;
beforeEach(module('habitrpg'));
beforeEach(inject(function($rootScope, $compile) {
scope = $rootScope.$new();
scope.focusThisLink = false;
var element = '<input data-focus-element="focusThisLink" />';
elementToFocus = $compile(element)(scope);
scope.$digest();
}));
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();
elementToFocus.appendTo(document.body);
elementToFocus.on('focus', focusSpy);
scope.focusThisLink = true;
scope.$digest();
$timeout.flush();
expect(document.activeElement.dataset.focusElement).to.eql("focusThisLink");
expect(focusSpy).to.have.been.called;
}));
});
@@ -1,28 +0,0 @@
'use strict';
describe('focusMe Directive', function() {
var element, scope;
beforeEach(module('habitrpg'));
beforeEach(inject(function($rootScope, $compile) {
scope = $rootScope.$new();
element = "<input focus-me></input>";
element = $compile(element)(scope);
scope.$digest();
}));
it('focuses the element when appended to the DOM', function() {
inject(function($timeout) {
var focusSpy = sandbox.spy();
element.appendTo(document.body);
element.on('focus', focusSpy);
$timeout.flush();
expect(focusSpy).to.have.been.called;
});
});
});