Added ability to close menu when a child element has closeMenu directive

This commit is contained in:
TheHollidayInn
2015-08-26 15:32:59 -05:00
parent 049f9280a2
commit 6fb29d8766
5 changed files with 54 additions and 31 deletions

View File

@@ -1,7 +1,7 @@
'use strict';
describe('closeMenu Directive', function() {
var menuElement, scope;
var menuElement, menuElementWithChild, menuElementChild, scope;
beforeEach(module('habitrpg'));
@@ -9,17 +9,33 @@ describe('closeMenu Directive', function() {
scope = $rootScope.$new();
var element = '<a data-close-menu menu="mobile">';
var elementWithChild = '<li></li>';
var elementChild = '<a data-close-menu></a>';
menuElement = $compile(element)(scope);
menuElementWithChild = $compile(elementWithChild)(scope);
menuElementChild = $compile(elementChild)(scope);
scope.$digest();
}));
it('closes a connected menu when element is clicked', function() {
scope._expandedMenu = 'mobile';
scope._expandedMenu = {};
scope._expandedMenu.menu = 'mobile';
menuElement.appendTo(document.body);
menuElement.triggerHandler('click');
expect(scope._expandedMenu).to.eql(null)
expect(scope._expandedMenu.menu).to.eql(null)
});
it('closes a connected menu when child element is clicked', function() {
scope._expandedMenu = {};
scope._expandedMenu.menu = 'mobile';
menuElementWithChild.appendTo(document.body);
menuElementChild.appendTo(menuElementWithChild);
menuElementChild.triggerHandler('click');
expect(scope._expandedMenu.menu).to.eql(null)
});
});

View File

@@ -20,15 +20,16 @@ describe('expandMenu Directive', function() {
menuElement.triggerHandler('click');
expect(scope._expandedMenu).to.eql('mobile')
expect(scope._expandedMenu.menu).to.eql('mobile')
});
it('closes a connected menu when it is already open', function() {
scope._expandedMenu = 'mobile';
scope._expandedMenu = {};
scope._expandedMenu.menu = 'mobile';
menuElement.appendTo(document.body);
menuElement.triggerHandler('click');
expect(scope._expandedMenu).to.eql(null)
expect(scope._expandedMenu.menu).to.eql(null)
});
});