Clean up directive tests

This commit is contained in:
Blade Barringer
2015-08-22 17:21:30 -05:00
parent b41b629e93
commit 9ddf5353d1
2 changed files with 22 additions and 27 deletions

View File

@@ -1,32 +1,25 @@
'use strict'; 'use strict';
describe('closeMenu Directive', function() { describe('closeMenu Directive', function() {
var element, menuElement, scope, ctrl; var menuElement, scope;
beforeEach(module('habitrpg')); beforeEach(module('habitrpg'));
beforeEach(inject(function($rootScope, $compile, $controller) { beforeEach(inject(function($rootScope, $compile) {
scope = $rootScope.$new(); scope = $rootScope.$new();
ctrl = $controller('MenuCtrl', {$scope: scope}); var element = '<a data-close-menu menu="mobile">';
element = '<a data-close-menu menu="mobile">';
element = $compile(element)(scope);
menuElement = $compile(element)(scope); menuElement = $compile(element)(scope);
scope.$digest(); scope.$digest();
})); }));
it('closes a connected menu when element is clicked', function() { it('closes a connected menu when element is clicked', function() {
inject(function($timeout) { scope._expandedMenu = 'mobile';
var clickSpy = sandbox.spy(); menuElement.appendTo(document.body);
element.appendTo(document.body); menuElement.triggerHandler('click');
element.on('click', clickSpy);
element.triggerHandler('click');
expect(scope._expandedMenu).to.equal(null) expect(scope._expandedMenu).to.eql(null)
expect(clickSpy).to.have.been.called;
});
}); });
}); });

View File

@@ -1,32 +1,34 @@
'use strict'; 'use strict';
describe('expandMenu Directive', function() { describe('expandMenu Directive', function() {
var element, menuElement, scope, ctrl, elm; var menuElement, scope;
beforeEach(module('habitrpg')); beforeEach(module('habitrpg'));
beforeEach(inject(function($rootScope, $compile, $controller) { beforeEach(inject(function($rootScope, $compile) {
scope = $rootScope.$new(); scope = $rootScope.$new();
ctrl = $controller('MenuCtrl', {$scope: scope}); var element = '<a data-expand-menu menu="mobile"></a>';
element = '<a data-expand-menu menu="mobile"></a>';
element = $compile(element)(scope);
menuElement = $compile(element)(scope); menuElement = $compile(element)(scope);
scope.$digest(); scope.$digest();
})); }));
it('expands a connected menu when element is clicked', function() { it('expands a connected menu when element is clicked', function() {
inject(function($timeout) { expect(scope._expandedMenu).to.not.exist;
var clickSpy = sandbox.spy(); menuElement.appendTo(document.body);
element.appendTo(document.body); menuElement.triggerHandler('click');
element.on('click', clickSpy); expect(scope._expandedMenu).to.eql('mobile')
element.triggerHandler('click'); });
expect(clickSpy).to.have.been.called; it('closes a connected menu when it is already open', function() {
}); scope._expandedMenu = 'mobile';
menuElement.appendTo(document.body);
menuElement.triggerHandler('click');
expect(scope._expandedMenu).to.eql(null)
}); });
}); });