# typed: false
module Domain::Fa::Parser::PageSpecHelper
  def assert_page_type(parser, expected_type)
    types = %i[probably_listings_page? probably_user_page? probably_submission?]
    outcomes = types.map { |type| [type, parser.send(type)] }.to_h

    num_types = outcomes.values.filter { |a| a }.to_a.length
    if num_types == 0
      fail "parser detected no page types: #{outcomes}"
    elsif num_types != 1
      fail "parser detected multiple page types: #{outcomes}"
    end
    assert outcomes[expected_type],
           "parser has wrong guessed page type, expected #{expected_type}, got #{outcomes}"
  end
end
