<commit_before>require 'test_helper'

class EventTrackingTest < ActionDispatch::IntegrationTest

  setup do
  	browser_start
    @image = lentil_images(:one)
  end
  teardown do
  	browser_end
  end

  test "should trigger an event for clicking on an image" do
  	visit(lentil.images_path)
    find("#image_#{@image.id} a.fancybox").click
    assert_equal("_trackEvent,image,click,image_#{@image.id}", console_messages[-2])
    assert_equal("_trackPageview,/lentil/images/#{@image.id}", console_message)
  end

  test "should trigger an event for clicking on the share button" do
    visit(lentil.image_path(@image))
    find('.share').click
    assert_equal("_trackEvent,image_view,share,#{@image.id}", console_message)
  end

  test "should trigger an event for clicking on the facebook share link" do
    visit(lentil.image_path(@image))
    find('.share').click
    find('.facebook').click
    assert_equal("_trackEvent,image_view,facebook,#{@image.id}", console_message)
  end

  test "should trigger an event for clicking on the twitter share link" do
    visit(lentil.image_path(@image))
    find('.share').click
    find('.twitter').click
    assert_equal("_trackEvent,image_view,twitter,#{@image.id}", console_message)
  end

  # FIXME: This fails due to the mailto link.
  # test "should trigger an event for clicking on the email share link" do
  #   visit(lentil.image_path(@image))
  #   find('.share').click
  #   find('.email').click
  #   assert_equal("_trackEvent,image_view,email,#{@image.id}", console_message)
  # end

  test "should trigger an event for liking and unliking an image" do
    visit lentil.image_path(@image)
    find('.like-btn.initial-state', :visible => true).click
    assert_equal("_trackEvent,image_view,like,#{@image.id}", console_message)
    find('.like-btn.already-clicked', :visible => true).click
    assert_equal("_trackEvent,image_view,unlike,#{@image.id}", console_message)
  end

  # TODO: Not currently implemented<commit_msg>Wait for unlink event<commit_after>require 'test_helper'

class EventTrackingTest < ActionDispatch::IntegrationTest

  setup do
  	browser_start
    @image = lentil_images(:one)
  end
  teardown do
  	browser_end
  end

  test "should trigger an event for clicking on an image" do
  	visit(lentil.images_path)
    find("#image_#{@image.id} a.fancybox").click
    assert_equal("_trackEvent,image,click,image_#{@image.id}", console_messages[-2])
    assert_equal("_trackPageview,/lentil/images/#{@image.id}", console_message)
  end

  test "should trigger an event for clicking on the share button" do
    visit(lentil.image_path(@image))
    find('.share').click
    assert_equal("_trackEvent,image_view,share,#{@image.id}", console_message)
  end

  test "should trigger an event for clicking on the facebook share link" do
    visit(lentil.image_path(@image))
    find('.share').click
    find('.facebook').click
    assert_equal("_trackEvent,image_view,facebook,#{@image.id}", console_message)
  end

  test "should trigger an event for clicking on the twitter share link" do
    visit(lentil.image_path(@image))
    find('.share').click
    find('.twitter').click
    assert_equal("_trackEvent,image_view,twitter,#{@image.id}", console_message)
  end

  # FIXME: This fails due to the mailto link.
  # test "should trigger an event for clicking on the email share link" do
  #   visit(lentil.image_path(@image))
  #   find('.share').click
  #   find('.email').click
  #   assert_equal("_trackEvent,image_view,email,#{@image.id}", console_message)
  # end

  test "should trigger an event for liking and unliking an image" do
    visit lentil.image_path(@image)
    find('.like-btn.initial-state', :visible => true).click
    assert_equal("_trackEvent,image_view,like,#{@image.id}", console_message)
    find('.like-btn.already-clicked', :visible => true).click
    find('.like-btn.initial-state', :visible => true)
    assert_equal("_trackEvent,image_view,unlike,#{@image.id}", console_message)
  end

  # TODO: Not currently implemented
{'fraction_non_alphanumeric': 0.12991538078646092, 'fraction_numerical': 0.0004977600796416127, 'mean_word_length': 4.581944444444445, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, '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': '6269275', 'n_tokens_mistral': 1284, 'n_tokens_neox': 1261, 'n_words': 295}