2019-04-23 14:58:31 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
Capybara.add_selector(:checkbox, locator_type: [String, Symbol]) do
|
|
|
|
xpath do |locator, allow_self: nil, **options|
|
|
|
|
xpath = XPath.axis(allow_self ? :"descendant-or-self" : :descendant, :input)[
|
|
|
|
XPath.attr(:type) == 'checkbox'
|
|
|
|
]
|
|
|
|
locate_field(xpath, locator, options)
|
|
|
|
end
|
|
|
|
|
|
|
|
filter_set(:_field, %i[checked unchecked disabled name])
|
|
|
|
|
2019-05-29 13:40:28 -04:00
|
|
|
node_filter(%i[option with]) do |node, value|
|
2019-04-23 14:58:31 -04:00
|
|
|
val = node.value
|
2019-05-29 13:40:28 -04:00
|
|
|
(value.is_a?(Regexp) ? value.match?(val) : val == value.to_s).tap do |res|
|
|
|
|
add_error("Expected value to be #{value.inspect} but it was #{val.inspect}") unless res
|
2019-04-23 14:58:31 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-05-29 13:40:28 -04:00
|
|
|
describe_node_filters do |option: nil, with: nil, **|
|
|
|
|
desc = +''
|
|
|
|
desc << " with value #{option.inspect}" if option
|
|
|
|
desc << " with value #{with.inspec}" if with
|
|
|
|
desc
|
2019-04-23 14:58:31 -04:00
|
|
|
end
|
|
|
|
end
|