Then(/^I should see some (.*?) data sources for (.*?)$/) do |sales_type, top_chart|
  on(Workstation::AnalyticsTopChartsPage) do |page|
    dom_value = page.get_data_sources(sales_type, top_chart)
    puts "#{top_chart} #{sales_type} data sources: #{dom_value}"
    expect(dom_value).not_to eq "" # should not be an empty string
  end
end

And(/^I go to the Workstation::AnalyticsTopChartsPage from the overview page$/) do
  if @browser.url.include? "overview"
    # If the user is on the overview page, click the browser's back button to get back to
    # the analytics index page so the page loads quickly from cache.
    # The "visit() unless" part ensures that the user is actually on the analytics index page
    # in case of a fresh login or was elsewhere prior to the overview page.
    step "I use my browser's back button"
    visit(Workstation::AnalyticsTopChartsPage) unless @browser.url.include? "analytics/index"
  else
    visit(Workstation::AnalyticsTopChartsPage)
  end
end

Given(/^I select the "([^"]*)" channel$/) do |channel|
  on(Workstation::AnalyticsTopChartsPage) do |page|
    page.select_channel(channel)
  end
end

When(/^I view the overview for a top artist$/) do
  artist_data = on(Workstation::AnalyticsTopChartsPage).click_first_artist
  @artist = artist_data[0]
  @downloads = artist_data[1].delete(",").to_i
  puts "Artist: #{@artist}"
  puts "Downloads: #{@downloads}"
end

# Delete for project_manager teardown
When(/^I view the overview for a top release$/) do
  release_data = on(Workstation::AnalyticsTopChartsPage).click_first_release
  @release = release_data[0]
  @artist = release_data[1]
  @downloads = release_data[2].delete(",").to_i

  puts "Artist: #{@artist}"
  puts "Release: #{@release}"
  puts "Downloads: #{@downloads}"
end

When(/^I view the overview for a top project$/) do
  project_data = on(Workstation::AnalyticsTopChartsPage).click_first_project
  @project = project_data[0]
  @artist = project_data[1]
  @downloads = project_data[2].delete(",").to_i

  puts "Artist: #{@artist}"
  puts "project: #{@project}"
  puts "Downloads: #{@downloads}"
end

When(/^I view the overview for a top track$/) do
  track_data = on(Workstation::AnalyticsTopChartsPage).click_first_track
  @track = track_data[0]
  @artist = track_data[1]
  @downloads = track_data[2].delete(",").to_i

  puts "Artist: #{@artist}"
  puts "Track: #{@track}"
  puts "Downloads: #{@downloads}"
end
