<commit_before>module Helpers

  def wait_for_ajax
    sleep 0.05
    Timeout.timeout(Capybara.default_wait_time) do
      loop until finished_all_ajax_requests?
    end
  end


  def finished_all_ajax_requests?
    page.evaluate_script('jQuery.active').zero?
  end


  def t(key)
    page.evaluate_script("i18n.#{key}")
  end


  def accept_dialog
    page.execute_script 'Voice.dialogController.accept()'
  end


  def cancel_dialog
    page.execute_script 'Voice.dialogController.cancel()'
  end


  def visit_home_url
    visit '/'
    resize_browser(1100, 900)
  end


  def use_client(num)
    all_sessions.add num
    Capybara.session_name = num
    sleep 0.1
  end


  def login_as(email, password='<PASSWORD>')
    fill_in 'user[email]',    with: email
    fill_in 'user[password]', with: password
    click_button 'Log in' # TODO translate this

    expect(page.evaluate_script('env.userId').to_i).to be > 0
  end


  def resize_browser(width, height)
    window = Capybara.current_session.driver.browser.manage.window
    window.resize_to(width, height)
  end


  def wipe_dbs
    system 'CONFIRM_DELETE=1 ./script/wipe-all-dbs'
  end


  def wait_for_puma
    while `lsof -i :#{SpecConfig['puma_port']} | grep LISTEN | wc -l`.to_i < 1
      sleep 1
    end<commit_msg>sleep longer after browser switch<commit_after>module Helpers

  def wait_for_ajax
    sleep 0.05
    Timeout.timeout(Capybara.default_wait_time) do
      loop until finished_all_ajax_requests?
    end
  end


  def finished_all_ajax_requests?
    page.evaluate_script('jQuery.active').zero?
  end


  def t(key)
    page.evaluate_script("i18n.#{key}")
  end


  def accept_dialog
    page.execute_script 'Voice.dialogController.accept()'
  end


  def cancel_dialog
    page.execute_script 'Voice.dialogController.cancel()'
  end


  def visit_home_url
    visit '/'
    resize_browser(1100, 900)
  end


  def use_client(num)
    all_sessions.add num
    Capybara.session_name = num
    sleep 0.5
  end


  def login_as(email, password='<PASSWORD>')
    fill_in 'user[email]',    with: email
    fill_in 'user[password]', with: password
    click_button 'Log in' # TODO translate this

    expect(page.evaluate_script('env.userId').to_i).to be > 0
  end


  def resize_browser(width, height)
    window = Capybara.current_session.driver.browser.manage.window
    window.resize_to(width, height)
  end


  def wipe_dbs
    system 'CONFIRM_DELETE=1 ./script/wipe-all-dbs'
  end


  def wait_for_puma
    while `lsof -i :#{SpecConfig['puma_port']} | grep LISTEN | wc -l`.to_i < 1
      sleep 1
    end
{'fraction_non_alphanumeric': 0.09767441860465116, 'fraction_numerical': 0.013953488372093023, 'mean_word_length': 3.2520593080724876, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6846456', 'n_tokens_mistral': 975, 'n_tokens_neox': 890, 'n_words': 193}