<commit_before>module Wist
  require 'selenium-webdriver'
  require 'cgi'
  require 'capybara'

  Capybara.register_driver :chrome do |app|
    Capybara::Selenium::Driver.new(app, browser: :chrome)
  end

  module Helpers
    module_function

    def blank?(obj)
      obj.respond_to?(:empty?) ? obj.empty? : !obj
    end
  end

  def wait_until(timeout: Capybara.default_wait_time)
    Selenium::WebDriver::Wait.new(timeout: timeout).until do
      begin
        yield
      rescue
        false
      end
    end
  end

  def click(selector)
    find(selector).click
  end

  def set_cookie(k, v)
    page.execute_script <<-eos
      (function (e,t,n){var r=new Date;r.setDate(r.getDate()+n);var i=escape(t)+(n==null?"":"; expires="+r.toUTCString());document.cookie=e+"="+i}
      (#{k.to_json}, #{v.to_json}));
    eos
  end

  def set_value_and_trigger_evts(selector, val)
    find(selector).set(val)
    page.execute_script("$('#{selector}').focusout().change().trigger('input')")
  end

  def verify_tweet_button(text)
    share_button_src = nil
    wait_until { share_button_src = find('.twitter-share-button')[:src] }
    assert_equal text, CGI.parse(URI.parse(share_button_src.gsub('#', '?')).query)['text'][0]
  end

  def driver
    page.driver.browser
  end

  def switch_to_window_and_execute
    wait_until { driver.window_handles.size == 2 }
    within_window(driver.window_handles.last) do
      yield
      driver.close
    end
  end

  def alert_accept(expected_msg = false)
    page.execute_script "window.alert = function(msg) { window.lastAlertMsg = msg; }"
    yield
    assert_equal(expected_msg, get_js('window.lastAlertMsg')) if expected_msg
  end

  def get_js(code)
    page.evaluate_script code
  end

  def jquery_selector(selector)
    "$('#{selector}')"
  end

  def get_val(selector)
    find(selector).value
  end

  def set_input_and_press_enter(selector, val)
    wait_til_element_visible(selector)
    page.execute_script("#{jquery_selector(selector)}.val('#{val}').trigger({type: 'keydown', which: 13})")
  end

  def has_class?(el, class_name)
    klass = el[:class]<commit_msg>trigger keypress too<commit_after>module Wist
  require 'selenium-webdriver'
  require 'cgi'
  require 'capybara'

  Capybara.register_driver :chrome do |app|
    Capybara::Selenium::Driver.new(app, browser: :chrome)
  end

  module Helpers
    module_function

    def blank?(obj)
      obj.respond_to?(:empty?) ? obj.empty? : !obj
    end
  end

  def wait_until(timeout: Capybara.default_wait_time)
    Selenium::WebDriver::Wait.new(timeout: timeout).until do
      begin
        yield
      rescue
        false
      end
    end
  end

  def click(selector)
    find(selector).click
  end

  def set_cookie(k, v)
    page.execute_script <<-eos
      (function (e,t,n){var r=new Date;r.setDate(r.getDate()+n);var i=escape(t)+(n==null?"":"; expires="+r.toUTCString());document.cookie=e+"="+i}
      (#{k.to_json}, #{v.to_json}));
    eos
  end

  def set_value_and_trigger_evts(selector, val)
    find(selector).set(val)
    page.execute_script("$('#{selector}').focusout().change().trigger('input')")
  end

  def verify_tweet_button(text)
    share_button_src = nil
    wait_until { share_button_src = find('.twitter-share-button')[:src] }
    assert_equal text, CGI.parse(URI.parse(share_button_src.gsub('#', '?')).query)['text'][0]
  end

  def driver
    page.driver.browser
  end

  def switch_to_window_and_execute
    wait_until { driver.window_handles.size == 2 }
    within_window(driver.window_handles.last) do
      yield
      driver.close
    end
  end

  def alert_accept(expected_msg = false)
    page.execute_script "window.alert = function(msg) { window.lastAlertMsg = msg; }"
    yield
    assert_equal(expected_msg, get_js('window.lastAlertMsg')) if expected_msg
  end

  def get_js(code)
    page.evaluate_script code
  end

  def jquery_selector(selector)
    "$('#{selector}')"
  end

  def get_val(selector)
    find(selector).value
  end

  def set_input_and_press_enter(selector, val)
    wait_til_element_visible(selector)
    page.execute_script("#{jquery_selector(selector)}.val('#{val}').trigger({type: 'keydown', which: 13}).trigger({ type: 'keypress', which: 13})")
  end

  def has_class?(el, class_name)
    klass = el[:class]
{'fraction_non_alphanumeric': 0.1378826828698294, 'fraction_numerical': 0.0023369946249123625, 'mean_word_length': 3.7874720357941833, 'pattern_counts': {'":': 2, '<': 7, '<?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': '285544', 'n_tokens_mistral': 1523, 'n_tokens_neox': 1490, 'n_words': 269}