And(/^I am on the video content page$/) do
  visit(OA::VideoContentReportPage) do |page|
    page.wait_for_loading_spinner_to_disappear
  end
end

And(/^I fill out the form to generate a video content report$/) do
  on(OA::VideoContentReportPage) do |page|
    page.select_product_type "Movie"
    page.select_genre "Animation"
    page.date_from = "2014-07-01"
    page.date_to = "2014-07-31"
    page.run_report
  end
end

And(/^I fill out the form to generate a TV content report$/) do
  on(OA::VideoContentReportPage) do |page|
    page.select_product_type "TV Show"
    page.date_from = "2014-07-01"
    page.date_to = "2014-07-31"
    page.select_genre "Blues"
    page.run_report
  end
end

Then(/^I should be able to download a video content report$/) do
  on(OA::VideoContentReportPage) do |page|
    page.wait_for_loading_spinner_to_disappear
    page.confirm_report_element.element.wait_until(&:present?)
    message = page.confirm_report
    expect(message).to include("Report successfully generated. You can download the file here:")
  end
end

And(/^I enter an invalid date$/) do
  on(OA::VideoContentReportPage) do |page|
    page.date_from = "asdfasdfasdf"
    page.date_to = "asdfasdfasdf"
  end
end

Then(/^I should get an error that a content report cannot be made with an invalid date$/) do
  on(OA::VideoContentReportPage) do |page|
    page.run_report
    error = page.report_error_message
    expect(error).to include("Invalid Release Date. The date should be a valid date in format YYYY-MM-DD.")
  end
end
