wip add checkbox
This commit is contained in:
parent
76d09d6802
commit
eba8ad6d6b
@ -10,7 +10,7 @@ WebMock.stub(:get, "html_example.com").to_return(body:
|
||||
<form action="post_path" method="post" name="sample_form">
|
||||
<input type="text" name="name">
|
||||
<input type="text" name="email">
|
||||
<input type="submit" value="">
|
||||
<input type="checkbox" id="ababa" name="ababa" checked>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
@ -22,6 +22,7 @@ describe "Mechanize Form test" do
|
||||
uri = "http://html_example.com/"
|
||||
page = agent.get(uri)
|
||||
form = page.forms.first
|
||||
|
||||
it "retrun form attribute" do
|
||||
form.action.should eq "post_path"
|
||||
form.method.should eq "POST"
|
||||
@ -29,14 +30,20 @@ describe "Mechanize Form test" do
|
||||
form.name.should eq "sample_form"
|
||||
end
|
||||
|
||||
it "includes fields" do
|
||||
form.fields.size.should eq 2
|
||||
end
|
||||
|
||||
context "Form Fields" do
|
||||
it "forms include fields" do
|
||||
form.fields.size.should eq 3
|
||||
end
|
||||
it "return field attribute" do
|
||||
it "returns field attribute" do
|
||||
field = form.fields.first
|
||||
field.type.should eq "text"
|
||||
field.name.should eq "name"
|
||||
end
|
||||
end
|
||||
|
||||
context "Form Fields CheckBox" do
|
||||
checkbox = form.checkboxes.first
|
||||
p checkbox.checked?
|
||||
end
|
||||
end
|
||||
|
@ -58,7 +58,13 @@ class MechanizeCr::Form
|
||||
@checkboxes = Array(MechanizeCr::FormContent::CheckBox).new
|
||||
@node.css("input").not_nil!.each do |html_node|
|
||||
html_node = html_node.as(Myhtml::Node)
|
||||
@fields << MechanizeCr::FormContent::Field.new(html_node)
|
||||
type = (html_node["type"] || "text").downcase
|
||||
case type
|
||||
when "checkbox"
|
||||
@checkboxes << MechanizeCr::FormContent::CheckBox.new(html_node)
|
||||
else
|
||||
@fields << MechanizeCr::FormContent::Field.new(html_node)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1,10 +1,8 @@
|
||||
class MechanizeCr::FormContent::CheckBox < MechanizeCr::FormContent::Field
|
||||
property :checked
|
||||
property :form
|
||||
|
||||
def initialize(node : Node | Myhtml::Node, value = "")
|
||||
@checked = !!node["checked"]
|
||||
@form = form
|
||||
super(node, value)
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user