add multi select box test
This commit is contained in:
parent
b4f4b6a021
commit
5bec2626a8
45
spec/form/multi_select_list_spec.cr
Normal file
45
spec/form/multi_select_list_spec.cr
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
require "../spec_helper"
|
||||||
|
|
||||||
|
WebMock.stub(:get, "example.com/form/multi_select_list").to_return(body:
|
||||||
|
<<-BODY
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>page_title</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<form action="post_path" method="post" name="sample_form">
|
||||||
|
<select name="pets" id="pet-select" multiple>
|
||||||
|
<option value="dog">Dog</option>
|
||||||
|
<option value="cat">Cat</option>
|
||||||
|
<option value="hamster">Hamster</option>
|
||||||
|
</select>
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
BODY
|
||||||
|
)
|
||||||
|
|
||||||
|
describe "Form Fields Multiple Select List" do
|
||||||
|
agent = Mechanize.new
|
||||||
|
page = agent.get("http://example.com/form/multi_select_list")
|
||||||
|
form = page.forms[0]
|
||||||
|
|
||||||
|
it "returns selectboxes size" do
|
||||||
|
form.selectboxes.size.should eq 1
|
||||||
|
end
|
||||||
|
|
||||||
|
selectbox = form.selectboxes[0]
|
||||||
|
|
||||||
|
it "returns selectbox options size" do
|
||||||
|
selectbox.options.size.should eq 3
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns selected values" do
|
||||||
|
selectbox.values.empty?.should eq true
|
||||||
|
selectbox.select_all
|
||||||
|
selectbox.values.size.should eq 3
|
||||||
|
selectbox.values.should eq ["dog", "cat", "hamster"]
|
||||||
|
selectbox.select_none
|
||||||
|
selectbox.values.empty?.should eq true
|
||||||
|
end
|
||||||
|
end
|
@ -163,6 +163,16 @@ class MechanizeCr::Form
|
|||||||
next if value[0] == ""
|
next if value[0] == ""
|
||||||
query.push(value)
|
query.push(value)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@selectboxes.each do |s|
|
||||||
|
value = s.query_value
|
||||||
|
if value
|
||||||
|
value.each do |v|
|
||||||
|
query.push(v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
query
|
query
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -48,6 +48,10 @@ class MechanizeCr::FormContent::MultiSelectList
|
|||||||
@values + selected_options.map &.value
|
@values + selected_options.map &.value
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def query_value
|
||||||
|
values ? values.map { |v| [name, v] } : nil
|
||||||
|
end
|
||||||
|
|
||||||
#def inspect # :nodoc:
|
#def inspect # :nodoc:
|
||||||
# "[%s:0x%x type: %s name: %s value: %s]" % [
|
# "[%s:0x%x type: %s name: %s value: %s]" % [
|
||||||
# self.class.name.sub(/MechanizeCr::FormContent::/, "").downcase,
|
# self.class.name.sub(/MechanizeCr::FormContent::/, "").downcase,
|
||||||
|
Loading…
Reference in New Issue
Block a user