1
0
Fork 0
mirror of https://github.com/thoughtbot/capybara-webkit synced 2023-03-27 23:22:28 -04:00

Fix for #26, select options with selected and trigger change

This commit is contained in:
Jeremy 2011-04-21 15:01:57 +12:00 committed by Joe Ferris
parent e703ac99b7
commit 7df0f230ae
2 changed files with 23 additions and 0 deletions

View file

@ -453,7 +453,17 @@ describe Capybara::Driver::Webkit do
<div id="change">Change me</div>
<div id="mouseup">Push me</div>
<div id="mousedown">Release me</div>
<form action="/" method="GET">
<select id="change_select" name="change_select">
<option value="1" id="option-1" selected="selected">one</option>
<option value="2" id="option-2">two</option>
</select>
</form>
<script type="text/javascript">
document.getElementById("change_select").
addEventListener("change", function () {
this.className = "triggered";
});
document.getElementById("change").
addEventListener("change", function () {
this.className = "triggered";
@ -491,6 +501,15 @@ describe Capybara::Driver::Webkit do
subject.find("//*[@class='triggered']").should_not be_empty
end
it "fires a change on select" do
select = subject.find("//select").first
select.value.should == "1"
option = subject.find("//option[@id='option-2']").first
option.select_option
select.value.should == "2"
subject.find("//select[@class='triggered']").should_not be_empty
end
it "fires drag events" do
draggable = subject.find("//*[@id='mousedown']").first
container = subject.find("//*[@id='mouseup']").first

View file

@ -87,11 +87,15 @@ Capybara = {
},
selectOption: function(index) {
this.nodes[index].selected = true;
this.nodes[index].setAttribute("selected", "selected");
this.trigger(index, "change");
},
unselectOption: function(index) {
this.nodes[index].selected = false;
this.nodes[index].removeAttribute("selected");
this.trigger(index, "change");
},
centerPostion: function(element) {