2017-07-10 14:42:15 -07:00
|
|
|
# frozen_string_literal: true
|
2018-01-08 12:23:54 -08:00
|
|
|
|
2017-07-10 14:42:15 -07:00
|
|
|
module Capybara
|
|
|
|
module Queries
|
2018-03-05 14:57:33 -08:00
|
|
|
class AncestorQuery < Capybara::Queries::SelectorQuery
|
2017-07-10 14:42:15 -07:00
|
|
|
# @api private
|
|
|
|
def resolve_for(node, exact = nil)
|
2017-09-20 17:08:02 -07:00
|
|
|
@child_node = node
|
2017-07-10 14:42:15 -07:00
|
|
|
node.synchronize do
|
|
|
|
match_results = super(node.session.current_scope, exact)
|
2018-01-13 13:06:03 -08:00
|
|
|
node.all(:xpath, XPath.ancestor) { |el| match_results.include?(el) }
|
2017-07-10 14:42:15 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-12 12:32:41 -07:00
|
|
|
def description(applied = false)
|
2018-05-10 13:20:23 -07:00
|
|
|
child_query = @child_node&.instance_variable_get(:@query)
|
2017-07-10 14:42:15 -07:00
|
|
|
desc = super
|
2018-01-13 13:06:03 -08:00
|
|
|
desc += " that is an ancestor of #{child_query.description}" if child_query
|
2017-07-10 14:42:15 -07:00
|
|
|
desc
|
|
|
|
end
|
2018-03-05 14:57:33 -08:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def valid_keys
|
|
|
|
super - COUNT_KEYS
|
|
|
|
end
|
2017-07-10 14:42:15 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|