Given(/^I am on the Project::DigitalProductPublishingPage for a product with 1 track$/) do
  step "I am on the Project::DigitalProductTracksPage for a product with no tracks"
  step "I import a valid track via \"upload from computer\" dialog box"
  step "I can see the track in the tracklist table"
end

When(/^I specify (.*?) as the publishing obligation for the track$/) do |obligation|
  @obligation = obligation
  on(Project::DigitalProductBasePage).publishing_obligation_step
  on(Project::ProductPublishingPage) do |page|
    page.select_publishing_obligation @obligation
  end
end

When(/^I save my publishing obligations$/) do
  on(Project::DigitalProductPublishingPage).save
end

Then(/^a green checkmark should be shown next to the publishing obligation step$/) do
  on(Project::DigitalProductBasePage) do |page|
    eventually(timeout: 30, retries: 2) do
      expect(page.publishing_obligation_checkmark_element.present?)
        .to eq(true), "publishing_obligation_checkmark is not present on the page"
    end
  end
end

Then(/^I should see my publishing obligations on the overview page$/) do
  on(Project::DigitalProductOverviewPage) do |page|
    page.edit_publishing_element.when_present
    eventually(timeout: 5) do
      expect(page.publishing_obligation_elements.first.text).to eq @obligation
    end
  end
end
