lib/chop/form.rb in chop-0.11.0 vs lib/chop/form.rb in chop-0.12.0
- old
+ new
@@ -50,13 +50,41 @@
def fill_in!
session.select value, from: label
end
end
+ class MultipleCheckbox < Field
+ def matches?
+ field[:type] == "checkbox" && field[:name].to_s.end_with?("[]")
+ end
+
+ def fill_in!
+ checkboxes.each do |checkbox|
+ if checkbox_label_in_values? checkbox
+ session.check(checkbox[:id])
+ else
+ session.uncheck(checkbox[:id])
+ end
+ end
+ end
+
+ private
+
+ def checkboxes
+ session.all("[name='#{field[:name]}']")
+ end
+
+ def checkbox_label_in_values? checkbox
+ values = value.split(", ")
+ labels = session.all("label[for='#{checkbox[:id]}']").map(&:text)
+ (values & labels).any?
+ end
+ end
+
class Checkbox < Field
def matches?
- field[:type] == "checkbox"
+ field[:type] == "checkbox" && !field[:name].to_s.end_with?("[]")
end
def fill_in!
if value.present?
session.check label
@@ -70,10 +98,26 @@
def matches?
field[:type] == "radio"
end
def fill_in!
- session.choose label
+ if nonstandard_labelling?
+ session.choose value
+ else
+ session.choose label
+ end
+ end
+
+ private
+
+ def nonstandard_labelling?
+ value_field[:name] == field[:name]
+ end
+
+ def value_field
+ session.find_field(value)
+ rescue Capybara::ElementNotFound
+ {}
end
end
class File < Field
def matches?