2019-04-23 14:58:31 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
Capybara.add_selector(:fillable_field, locator_type: [String, Symbol]) do
|
|
|
|
label 'field'
|
|
|
|
xpath do |locator, allow_self: nil, **options|
|
|
|
|
xpath = XPath.axis(allow_self ? :"descendant-or-self" : :descendant, :input, :textarea)[
|
|
|
|
!XPath.attr(:type).one_of('submit', 'image', 'radio', 'checkbox', 'hidden', 'file')
|
|
|
|
]
|
2019-11-28 17:41:13 -05:00
|
|
|
locate_field(xpath, locator, **options)
|
2019-04-23 14:58:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
expression_filter(:type) do |expr, type|
|
|
|
|
type = type.to_s
|
|
|
|
if type == 'textarea'
|
|
|
|
expr.self(type.to_sym)
|
|
|
|
else
|
|
|
|
expr[XPath.attr(:type) == type]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-31 15:32:44 -04:00
|
|
|
filter_set(:_field, %i[disabled multiple name placeholder valid])
|
2019-04-23 14:58:31 -04:00
|
|
|
|
|
|
|
node_filter(:with) do |node, with|
|
|
|
|
val = node.value
|
|
|
|
(with.is_a?(Regexp) ? with.match?(val) : val == with.to_s).tap do |res|
|
|
|
|
add_error("Expected value to be #{with.inspect} but was #{val.inspect}") unless res
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe_node_filters do |**options|
|
|
|
|
" with value #{options[:with].to_s.inspect}" if options.key?(:with)
|
|
|
|
end
|
|
|
|
end
|