Simulate browsers events more closely

This commit is contained in:
Matthew Mongeau 2012-01-27 18:03:38 -05:00
parent 16c16372c8
commit 51c4dfe141
2 changed files with 6 additions and 10 deletions

View File

@ -637,12 +637,12 @@ describe Capybara::Driver::Webkit do
it "triggers radio input events" do it "triggers radio input events" do
subject.find("//input[@type='radio']").first.set(true) subject.find("//input[@type='radio']").first.set(true)
subject.find("//li").map(&:text).should == %w(mousedown mouseup click change) subject.find("//li").map(&:text).should == %w(mousedown mouseup change click)
end end
it "triggers checkbox events" do it "triggers checkbox events" do
subject.find("//input[@type='checkbox']").first.set(true) subject.find("//input[@type='checkbox']").first.set(true)
subject.find("//li").map(&:text).should == %w(mousedown mouseup click change) subject.find("//li").map(&:text).should == %w(mousedown mouseup change click)
end end
end end

View File

@ -181,17 +181,13 @@ Capybara = {
this.trigger(index, "blur"); this.trigger(index, "blur");
} else if (type === "checkbox" || type === "radio") { } else if (type === "checkbox" || type === "radio") {
node.checked = (value === "true"); if (node.checked != (value === "true")) {
this.trigger(index, "mousedown"); this.click(index)
this.trigger(index, "mouseup"); }
this.trigger(index, "click");
this.trigger(index, "change");
} else if (type === "file") { } else if (type === "file") {
this.lastAttachedFile = value; this.lastAttachedFile = value;
this.trigger(index, "mousedown"); this.click(index)
this.trigger(index, "mouseup");
this.trigger(index, "click");
} else { } else {
node.value = value; node.value = value;