<commit_before># frozen_string_literal: true

module AutoCompleteHelper
  def select_an_org(autocomplete_id, org)
    # Set the Org Name
    find(autocomplete_id).set org.name
    sleep(0.3)

    # The controllers are expecting the org_id though, so lets
    # populate it
    hidden_id = autocomplete_id.gsub('_name', '_id').gsub('#', '')
    hash = { id: org.id, name: org.name }.to_json

    js = "document.getElementById('#{hidden_id}').value = '#{hash}'"
    page.execute_script(js) if hidden_id.present?
  end

  def choose_suggestion(suggestion_text)
    # matcher = '.ui-autocomplete .ui-menu-item'
    # matching_element = find(:css, matcher) do |element|
    #   element.text.strip == suggestion_text.strip
    # end
    matching_element = find(:css, ".ui-autocomplete .ui-menu-item:contains(\"#{suggestion_text.strip}\")")
    raise ArgumentError, "No such suggestion with text '#{suggestion_text}'" unless matching_element.present?

    matching_element.click
    # Wait for the JS to run
    sleep(0.3)
  end
end<commit_msg>another attempt to fix rspec tests with org autocompletes<commit_after># frozen_string_literal: true

module AutoCompleteHelper
  def select_an_org(autocomplete_id, org)
    # Set the Org Name
    find(autocomplete_id).set org.name
    sleep(0.3)

    # The controllers are expecting the org_id though, so lets
    # populate it
    hidden_id = autocomplete_id.gsub('_name', '_id').gsub('#', '')
    hash = { id: org.id, name: org.name }.to_json

    js = "document.getElementById('#{hidden_id}').value = '#{hash}'"
    page.execute_script(js) if hidden_id.present?
  end

  def choose_suggestion(suggestion_text)
    # matcher = '.ui-autocomplete .ui-menu-item'
    # matching_element = find(:css, matcher) do |element|
    #   element.text.strip == suggestion_text.strip
    # end
    matching_element = find(:xpath, "//div[@class='ui-menu-item-wrapper' and normalize-space()='#{suggestion_text}']")
    raise ArgumentError, "No such suggestion with text '#{suggestion_text}'" unless matching_element.present?

    matching_element.click
    # Wait for the JS to run
    sleep(0.3)
  end
end
{'fraction_non_alphanumeric': 0.1267605633802817, 'fraction_numerical': 0.003755868544600939, 'mean_word_length': 3.8876146788990824, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5385299', 'n_tokens_mistral': 716, 'n_tokens_neox': 686, 'n_words': 166}