mirror of
https://github.com/thoughtbot/capybara-webkit
synced 2023-03-27 23:22:28 -04:00
Trigger text input events with HTML5 text-like fields: email, number, search, tel, text, and url.
This commit is contained in:
parent
352823dc06
commit
7e5e99b01f
2 changed files with 29 additions and 26 deletions
|
@ -536,9 +536,13 @@ describe Capybara::Driver::Webkit do
|
||||||
body = <<-HTML
|
body = <<-HTML
|
||||||
<html><body>
|
<html><body>
|
||||||
<form action="/" method="GET">
|
<form action="/" method="GET">
|
||||||
<input class="watch" type="text"/>
|
|
||||||
<input class="watch" type="password"/>
|
|
||||||
<input class="watch" type="email"/>
|
<input class="watch" type="email"/>
|
||||||
|
<input class="watch" type="number"/>
|
||||||
|
<input class="watch" type="password"/>
|
||||||
|
<input class="watch" type="search"/>
|
||||||
|
<input class="watch" type="tel"/>
|
||||||
|
<input class="watch" type="text"/>
|
||||||
|
<input class="watch" type="url"/>
|
||||||
<textarea class="watch"></textarea>
|
<textarea class="watch"></textarea>
|
||||||
<input class="watch" type="checkbox"/>
|
<input class="watch" type="checkbox"/>
|
||||||
<input class="watch" type="radio"/>
|
<input class="watch" type="radio"/>
|
||||||
|
@ -580,9 +584,11 @@ describe Capybara::Driver::Webkit do
|
||||||
%w{change blur}).flatten
|
%w{change blur}).flatten
|
||||||
end
|
end
|
||||||
|
|
||||||
it "triggers text input events" do
|
%w(email number password search tel text url).each do | field_type |
|
||||||
subject.find("//input[@type='text']").first.set(newtext)
|
it "triggers text input events on inputs of type #{field_type}" do
|
||||||
subject.find("//li").map(&:text).should == keyevents
|
subject.find("//input[@type='#{field_type}']").first.set(newtext)
|
||||||
|
subject.find("//li").map(&:text).should == keyevents
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "triggers textarea input events" do
|
it "triggers textarea input events" do
|
||||||
|
@ -590,16 +596,6 @@ describe Capybara::Driver::Webkit do
|
||||||
subject.find("//li").map(&:text).should == keyevents
|
subject.find("//li").map(&:text).should == keyevents
|
||||||
end
|
end
|
||||||
|
|
||||||
it "triggers password input events" do
|
|
||||||
subject.find("//input[@type='password']").first.set(newtext)
|
|
||||||
subject.find("//li").map(&:text).should == keyevents
|
|
||||||
end
|
|
||||||
|
|
||||||
it "triggers email input events" do
|
|
||||||
subject.find("//input[@type='email']").first.set(newtext)
|
|
||||||
subject.find("//li").map(&:text).should == keyevents
|
|
||||||
end
|
|
||||||
|
|
||||||
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(click change)
|
subject.find("//li").map(&:text).should == %w(click change)
|
||||||
|
|
|
@ -139,21 +139,25 @@ Capybara = {
|
||||||
return this.nodes[index].value;
|
return this.nodes[index].value;
|
||||||
},
|
},
|
||||||
|
|
||||||
set: function(index, value) {
|
set: function (index, value) {
|
||||||
var node = this.nodes[index];
|
var length, maxLength, node, strindex, textTypes, type;
|
||||||
var type = (node.type || node.tagName).toLowerCase();
|
|
||||||
if (type == "text" || type == "textarea" || type == "password" || type == "email") {
|
node = this.nodes[index];
|
||||||
|
type = (node.type || node.tagName).toLowerCase();
|
||||||
|
textTypes = ["email", "number", "password", "search", "tel", "text", "textarea", "url"];
|
||||||
|
|
||||||
|
if (textTypes.indexOf(type) != -1) {
|
||||||
this.trigger(index, "focus");
|
this.trigger(index, "focus");
|
||||||
node.value = "";
|
|
||||||
var maxLength = this.attribute(index, "maxlength"),
|
maxLength = this.attribute(index, "maxlength");
|
||||||
length;
|
|
||||||
if (maxLength && value.length > maxLength) {
|
if (maxLength && value.length > maxLength) {
|
||||||
length = maxLength;
|
length = maxLength;
|
||||||
} else {
|
} else {
|
||||||
length = value.length;
|
length = value.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(var strindex = 0; strindex < length; strindex++) {
|
node.value = "";
|
||||||
|
for (strindex = 0; strindex < length; strindex++) {
|
||||||
node.value += value[strindex];
|
node.value += value[strindex];
|
||||||
this.trigger(index, "keydown");
|
this.trigger(index, "keydown");
|
||||||
this.keypress(index, false, false, false, false, 0, value[strindex]);
|
this.keypress(index, false, false, false, false, 0, value[strindex]);
|
||||||
|
@ -161,13 +165,16 @@ Capybara = {
|
||||||
}
|
}
|
||||||
this.trigger(index, "change");
|
this.trigger(index, "change");
|
||||||
this.trigger(index, "blur");
|
this.trigger(index, "blur");
|
||||||
} else if(type == "checkbox" || type == "radio") {
|
|
||||||
node.checked = (value == "true");
|
} else if (type === "checkbox" || type === "radio") {
|
||||||
|
node.checked = (value === "true");
|
||||||
this.trigger(index, "click");
|
this.trigger(index, "click");
|
||||||
this.trigger(index, "change");
|
this.trigger(index, "change");
|
||||||
} else if(type == "file") {
|
|
||||||
|
} else if (type === "file") {
|
||||||
this.lastAttachedFile = value;
|
this.lastAttachedFile = value;
|
||||||
this.trigger(index, "click");
|
this.trigger(index, "click");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
node.value = value;
|
node.value = value;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue