When(/^I search releases with the manufacturer UPC: (.*?)$/) do |manufacturer_upc|
  visit(OA::SearchReleasePage, using_params: { queries: { "upc" => manufacturer_upc } }) do |page|
    @manufacturer_upc = manufacturer_upc
    page.manufacturer_upc_field = @manufacturer_upc
    page.search
  end
end

Then(/^the searched release should be displayed on the release search results page$/) do
  on(OA::SearchReleaseResultsPage) do |page|
    release_on_page = page.results_element.any? { |x| x["UPC"].text == @manufacturer_upc }
    expect(release_on_page).to be true
  end
end

When(/^I export the release search results$/) do
  on(OA::SearchReleaseResultsPage) do
    download_link = DOMAINS[:oa] + "/search/exportreleasesearchresult?manufacturer_upc=#{@manufacturer_upc}"
    @downloaded_file = FileSystemHelpers::Downloader.download(download_link, with_timestamp: false).first
  end
end

Then(/^the searched release should be displayed in the exported spreadsheet$/) do
  expect(File.read(@downloaded_file)).to include(@manufacturer_upc)
end
