forked from harvesthq/chosen
-
Notifications
You must be signed in to change notification settings - Fork 63
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 harvesthq#2704 from marcandre/bye_bye_simulate
Bye bye simulate
- Loading branch information
Showing
6 changed files
with
89 additions
and
8 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
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,30 @@ | ||
describe "Events", -> | ||
it "chosen should fire the right events", -> | ||
tmpl = " | ||
<select data-placeholder='Choose a Country...'> | ||
<option value=''></option> | ||
<option value='United States'>United States</option> | ||
<option value='United Kingdom'>United Kingdom</option> | ||
<option value='Afghanistan'>Afghanistan</option> | ||
</select> | ||
" | ||
div = $("<div>").html(tmpl) | ||
select = div.find("select") | ||
expect(select.size()).toBe(1) | ||
select.chosen() | ||
# very simple check that the necessary elements have been created | ||
["container", "container-single", "single", "default"].forEach (clazz)-> | ||
el = div.find(".chosen-#{clazz}") | ||
expect(el.size()).toBe(1) | ||
|
||
# test a few interactions | ||
event_sequence = [] | ||
div.on 'input change', (evt) -> event_sequence.push evt.type | ||
|
||
container = div.find(".chosen-container") | ||
container.trigger("mousedown") # open the drop | ||
expect(container.hasClass("chosen-container-active")).toBe true | ||
#select an item | ||
container.find(".active-result").last().trigger("mouseup") | ||
|
||
expect(event_sequence).toEqual ['input', 'change'] |
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,32 @@ | ||
describe "Events", -> | ||
it "chosen should fire the right events", -> | ||
tmpl = " | ||
<select data-placeholder='Choose a Country...'> | ||
<option value=''></option> | ||
<option value='United States'>United States</option> | ||
<option value='United Kingdom'>United Kingdom</option> | ||
<option value='Afghanistan'>Afghanistan</option> | ||
</select> | ||
" | ||
|
||
div = new Element("div") | ||
document.body.insert(div) | ||
|
||
div.update(tmpl) | ||
select = div.down("select") | ||
expect(select).toBeDefined() | ||
new Chosen(select) | ||
|
||
event_sequence = [] | ||
document.addEventListener 'input', -> event_sequence.push 'input' | ||
document.addEventListener 'change', -> event_sequence.push 'change' | ||
|
||
container = div.down(".chosen-container") | ||
container.simulate("mousedown") # open the drop | ||
expect(container.hasClassName("chosen-container-active")).toBe true | ||
|
||
#select an item | ||
container.select(".active-result").last().simulate("mouseup") | ||
|
||
expect(event_sequence).toEqual ['input', 'change'] | ||
div.remove() |