Permalink
Browse files

Fixed dropdown method bug and added tests

1 parent b675be1 commit 425cd4e9e92d160be3b0331409e83f18b00a96fe @acburst acburst committed Dec 26, 2016
View
@@ -36,6 +36,8 @@
<script src="tests/spec/collapsible/collapsibleSpec.js"></script>
+ <script src="tests/spec/dropdown/dropdownSpec.js"></script>
+
<script src="tests/spec/materialbox/materialboxSpec.js"></script>
<script src="tests/spec/scrollFire/scrollFireSpec.js"></script>
View
Oops, something went wrong.
View
@@ -174,6 +174,14 @@
}
})
.animate( {opacity: 1}, {queue: false, duration: curr_options.inDuration, easing: 'easeOutSine'});
+
+ // Add click close handler to document
+ $(document).bind('click.'+ activates.attr('id') + ' touchstart.' + activates.attr('id'), function (e) {
+ if (!activates.is(e.target) && !origin.is(e.target) && (!origin.find(e.target).length) ) {
+ hideDropdown();
+ $(document).unbind('click.'+ activates.attr('id') + ' touchstart.' + activates.attr('id'));
+ }
+ });
}
function hideDropdown() {
@@ -182,6 +190,7 @@
activates.fadeOut(curr_options.outDuration);
activates.removeClass('active');
origin.removeClass('active');
+ $(document).unbind('click.'+ activates.attr('id') + ' touchstart.' + activates.attr('id'));
setTimeout(function() { activates.css('max-height', ''); }, curr_options.outDuration);
}
@@ -235,15 +244,6 @@
hideDropdown();
$(document).unbind('click.'+ activates.attr('id') + ' touchstart.' + activates.attr('id'));
}
- // If menu open, add click close handler to document
- if (activates.hasClass('active')) {
- $(document).bind('click.'+ activates.attr('id') + ' touchstart.' + activates.attr('id'), function (e) {
- if (!activates.is(e.target) && !origin.is(e.target) && (!origin.find(e.target).length) ) {
- hideDropdown();
- $(document).unbind('click.'+ activates.attr('id') + ' touchstart.' + activates.attr('id'));
- }
- });
- }
}
});
@@ -338,7 +338,7 @@
<li><a href="http://myapp.dev/things">Index</a></li>
<li><a href="http://myapp.dev/place/logs">Logs</a></li>
<li><a href="http://myapp.dev/place/create">Create Thing</a></li>
- <li><a href="http://myapp.dev/things/manage">Very Long Menu Item That Should Overflow</a></li>
+ <li><a href="http://myapp.dev/things/manage">Very Long Menu Item That Is Very Long</a></li>
</ul>
<ul id="8" class="dropdown-content">
<li>
@@ -461,9 +461,6 @@
<li>
<a href="http://myapp.dev/admin/invitations/new">Invite User</a>
</li>
- <li>
- <a href="http://myapp.dev/things/manage">Very Long Menu Item That Should Overflow</a>
- </li>
</ul>
<br><br>
@@ -0,0 +1,14 @@
+<div class="row">
+ <div class="input-field col s12">
+ <!-- Dropdown Trigger -->
+ <a id="dropdownActivator" class='dropdown-button btn' href='#' data-activates='dropdown1'>Drop Me!</a>
+
+ <!-- Dropdown Structure -->
+ <ul id='dropdown1' class='dropdown-content'>
+ <li><a href="#!">one</a></li>
+ <li><a href="#!">two</a></li>
+ <li class="divider"></li>
+ <li><a href="#!">three</a></li>
+ </ul>
+ </div>
+</div>
@@ -0,0 +1,51 @@
+describe("Dropdown Plugin", function () {
+ beforeEach(function() {
+ loadFixtures('dropdown/dropdownFixture.html');
+ $('.dropdown-button').dropdown();
+ });
+
+ describe("Dropdown", function () {
+ var normalDropdown;
+
+ beforeEach(function() {
+ // browserSelect = $('select.normal');
+ });
+
+ it("should open and close programmatically", function (done) {
+ var dropdown1 = $('#dropdown1');
+ normalDropdown = $('#dropdownActivator');
+
+ expect(dropdown1).toBeHidden('Should be hidden before dropdown is opened.');
+
+ normalDropdown.dropdown('open');
+
+ setTimeout(function() {
+ expect(dropdown1).toBeVisible('Should be shown after dropdown is opened.');
+ normalDropdown.dropdown('close');
+
+ setTimeout(function() {
+ expect(dropdown1).toBeHidden('Should be hidden after dropdown is closed.');
+ done();
+ }, 400);
+ }, 400);
+ });
+
+ it("should close dropdown on document click if programmatically opened", function (done) {
+ normalDropdown = $('#dropdownActivator');
+
+ expect(dropdown1).toBeHidden('Should be hidden before dropdown is opened.');
+
+ normalDropdown.dropdown('open');
+
+ setTimeout(function() {
+ expect(dropdown1).toBeVisible('Should be shown after dropdown is opened.');
+ $(document).click();
+
+ setTimeout(function() {
+ expect(dropdown1).toBeHidden('Should be hidden after dropdown is closed.');
+ done();
+ }, 400);
+ }, 400);
+ });
+ });
+});

0 comments on commit 425cd4e

Please sign in to comment.