<commit_before>module CapybaraExt
  def page!
    save_and_open_page
  end

  def click_icon(type)
    find(".icon-#{type}").click
  end

  def within_row(num, &block)
    within("table.index tbody tr:nth-child(#{num})", &block)
  end

  def column_text(num)
    find("td:nth-child(#{num})").text
  end

  def select2(within, value)
    # Forced narcolepsy, thanks to JavaScript
    sleep(1)
    page.execute_script "$('#{within} .select2-choice').mousedown();"
    sleep(1)
    page.execute_script "$('.select2-focused').val('foobar').trigger('keyup-change');"
    sleep(1)
    page.execute_script "$('.select2-highlighted').mouseup();"
  end
end

RSpec.configure do |c|
  c.include CapybaraExt
end<commit_msg>Improve select2 capybara_ext helper to work with select2 boxes that can contain multiple values<commit_after>module CapybaraExt
  def page!
    save_and_open_page
  end

  def click_icon(type)
    find(".icon-#{type}").click
  end

  def within_row(num, &block)
    within("table.index tbody tr:nth-child(#{num})", &block)
  end

  def column_text(num)
    find("td:nth-child(#{num})").text
  end

  def select2(within, value)
    # Forced narcolepsy, thanks to JavaScript
    sleep(1)
    page.execute_script "$('#{within} .select2-choice').mousedown();"
    page.execute_script "$('#{within} .select2-choices').mousedown();"
    sleep(1)
    page.execute_script "$('.select2-search-field input.select2-input').val('#{value}').trigger('keyup-change');"
    sleep(1)
    page.execute_script "$('.select2-highlighted').mouseup();"
  end
end

RSpec.configure do |c|
  c.include CapybaraExt
end
{'fraction_non_alphanumeric': 0.15917602996254682, 'fraction_numerical': 0.011235955056179775, 'mean_word_length': 4.121405750798722, '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': '6794231', 'n_tokens_mistral': 583, 'n_tokens_neox': 563, 'n_words': 112}