-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #493 from CartoDB/491-fix-unbind-dropdown-events
Unbind dropdown bound events on clean
- Loading branch information
Showing
3 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
describe('common.ui.Dropdown', function() { | ||
beforeEach(function() { | ||
this.$el = $('<div><button id="btn"></button></div>'); | ||
this.view = new cdb.ui.common.Dropdown({ | ||
el: $('<div>'), | ||
target: this.$el.find('#btn') | ||
}); | ||
}); | ||
|
||
describe('.clean', function() { | ||
it('should unbind click handler on target', function() { | ||
this.targetClickSpy = jasmine.createSpy('click'); | ||
this.$el.on('click', this.targetClickSpy); | ||
|
||
// Event should not bubble up since there is a handler that prevents it | ||
this.$el.find('#btn').click(); | ||
expect(this.targetClickSpy).not.toHaveBeenCalled(); | ||
|
||
// Verify click bubbles up as expected again | ||
this.view.clean(); | ||
this.$el.find('#btn').click(); | ||
expect(this.targetClickSpy).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should unbind event handlers on document', function() { | ||
// spy on internal call, since spying on _keydown fn do not work for some reason | ||
spyOn(this.view, 'hide'); | ||
var keyEsc = function() { | ||
var e = $.Event('keydown'); | ||
e.keyCode = 27; // ESC | ||
$(document).trigger(e); | ||
}; | ||
|
||
// Should hide on ESC | ||
keyEsc(); | ||
expect(this.view.hide).toHaveBeenCalled(); | ||
|
||
// Callback should not be triggered again | ||
this.view.clean(); | ||
keyEsc(); | ||
expect(this.view.hide.calls.count()).toEqual(1); | ||
}); | ||
}); | ||
}); |