add textarea test

This commit is contained in:
Kanezoh 2021-06-29 21:41:04 +09:00
parent 57bad568f7
commit 6144bb8a55
2 changed files with 33 additions and 1 deletions

View File

@ -0,0 +1,27 @@
require "../spec_helper"
WebMock.stub(:get, "example.com/form/textarea").to_return(body:
<<-BODY
<html>
<head>
<title>page_title</title>
</head>
<body>
<form action="post_path" method="post" name="sample_form">
<input type="textarea" name="input_textarea">
<textarea name="textarea_tag">
</form>
</body>
</html>
BODY
)
describe "Form Fields CheckBox" do
agent = Mechanize.new
page = agent.get("http://example.com/form/textarea")
form = page.forms[0]
it "returns textareas" do
form.textareas.size.should eq 2
end
end

View File

@ -52,6 +52,11 @@ class MechanizeCr::Form
elements_with "radiobutton"
elements_with "checkbox", "checkboxes"
# Returns all fields of type Textarea
def textareas
fields.select { |f| f.class == FormContent::Textarea }.map &.as(FormContent::Textarea)
end
private def parse
@node.css("input").not_nil!.each do |html_node|
html_node = html_node.as(Myhtml::Node)
@ -72,7 +77,7 @@ class MechanizeCr::Form
when "hidden"
fields << FormContent::Hidden.new(html_node)
when "textarea"
@fields << FormContent::Textarea.new(html_node)
fields << FormContent::Textarea.new(html_node)
else
fields << FormContent::Field.new(html_node)
end