# frozen_string_literal: true

When(/^I activate the first hovercard$/) do
  first(".hovercardable").hover
end

Then(/^I should see a hovercard$/) do
  page.should have_css('#hovercard', visible: true)
end

Then(/^I should see "([^"]*)" hashtag in the hovercard$/) do |tag|
  element = find("#hovercard .hashtags a", text: tag)
  expect(element["href"]).to include("/tags/#{tag.slice(1, tag.length)}")
end

When(/^I deactivate the first hovercard$/) do
  find("input#q").click # Click something else instead to deactive it
end

Then(/^I should not see a hovercard$/) do
  page.should_not have_css('#hovercard', visible: true)
end

When (/^I hover "([^"]*)" within "([^"]*)"$/) do |name, selector|
  with_scope(selector) do
    find(".author-name", text: name).hover
  end
end

# frozen_string_literal: true

When(/^I activate the first hovercard$/) do
  page.execute_script("$('.hovercardable').first().trigger('mouseenter');")
end

Then(/^I should see a hovercard$/) do
  page.should have_css('#hovercard', visible: true)
end

Then(/^I should see "([^"]*)" hashtag in the hovercard$/) do |tag|
  element = find("#hovercard .hashtags a", text: tag)
  expect(element["href"]).to include("/tags/#{tag.slice(1, tag.length)}")
end

When(/^I deactivate the first hovercard$/) do
  page.execute_script("$('.hovercardable').first().trigger('mouseleave');")
end

Then(/^I should not see a hovercard$/) do
  page.should_not have_css('#hovercard', visible: true)
end

When (/^I hover "([^"]*)" within "([^"]*)"$/) do |name, selector|
  with_scope(selector) do
    find(".author-name", text: name).hover
  end
end

Revert "Replace "execute_script" for triggering hovercards"
Revert "Replace "execute_script" for triggering hovercards"

This reverts commit e7dc4eca9ecdb025c01b02890e8e075ebc1af9cc.
