# BACKGROUND -----

Given (/^A 404 page exists$/) do
  @context.create_404_page!
end

Then (/^I should see all the Content Downloads$/) do
  @context.expect_content_downloads_table
end

# GENERAL -----

Then(/^I should see the appropriate content download create error messages$/) do
    @context.expect_invalid_content_download_create_errors
end

# CREATE -----

Given(/^I submit info for a new content download$/) do
  find("h2", text: "Name").sibling("input").set("Test")
  find("h2", text: "Content Score").sibling("input").set("1")
  find(".admin-modal .orange-button").click
  @context.wait_for_ajax
end

Given(/^I enter (valid|invalid) content download data$/) do |validity|
  @context.enter_content_download_create_data(validity.to_sym)
end

Then (/^I should be on the latest Content Download's edit page$/) do
  @context.expect_latest_edit_page
end

# UPDATE -----

Given(/^I'm on the (.*) Content Download edit page$/) do |ordinal|
  @context.visit_content_download_edit_page(ordinal.to_sym)
end

When(/^I fill out the form with (valid|invalid) data for (?:a|an) (active|inactive) Content Download$/) do |validity, activity|
  @context.enter_content_download_update_data(activity.to_sym, validity.to_sym)
end

When(/^I update the Content Download$/) do
  @context.click_a_tag("Save")
  @context.wait_for_ajax
end

Then(/^I should see the appropriate (active|inactive) content download update error messages$/) do |activity|
  @context.expect_invalid_content_download_update_errors(activity.to_sym)
end

Then (/^the (active|inactive) Content Download changes should be saved$/) do |activity|
  @context.expect_updated_content_download(activity.to_sym)
end

Then (/^I should see the Content Download publicly$/) do
  @context.expect_content_download_landing_page
end

# DELETE -----

Then (/^I should be redirected to the Content Download index page$/) do
  @context.expect_content_download_index_page
end

Then (/^the (1st|2nd|3rd) content download should be deleted$/) do |ordinal|
  @context.expect_deleted_content_download(ordinal.to_i)
end

# PREVIEW -----

Then (/^I should see the Content Download's (.*)$/) do |preview_entity|
  case preview_entity
  when "landing page"
    @context.expect_content_download_landing_page_preview
  when "hero form"
    @context.expect_content_download_hero_form_preview
  when "preview card"
    @context.expect_content_download_preview_card_preview
  end
end
