When(/^I hide the Download Albums channel$/) do
  on(Workstation::AnalyticsOverviewPage) do |page|
    page.hide_channel("Download Albums")
  end
end

Then(/^the Download Albums channel should be hidden$/) do
  on(Workstation::AnalyticsOverviewPage) do |page|
    expect(page.download_albums_container_element.element.present?).to be false
    expect(page.hidden_channels_container).to include("Download Albums")
  end
end

Given(/^the Download Albums channel is not hidden$/) do
  on(Workstation::AnalyticsOverviewPage) do |page|
    page.wait_until { page.div_element(class: "other").present? }
    page.wait_until { page.div_elements(class: "graph").any? }
    page.wait_until do
      page.analytics_loader_elements.last.attribute_value("style").include? "display: none;"
    end
    page.unhide_channel("Download Albums") if page.hidden_channels_container.include? "Download Albums"
  end
end

Given(/^the Download Albums channel is hidden$/) do
  on(Workstation::AnalyticsOverviewPage) do |page|
    page.wait_until { page.div_element(class: "other").present? }
    page.wait_until { page.div_elements(class: "graph").any? }
    page.wait_until do
      page.analytics_loader_elements.last.attribute_value("style").include? "display: none;"
    end
    page.hide_channel("Download Albums") unless page.hidden_channels_container.include? "Download Albums"
  end
end

When(/^I unhide the Download Albums channel$/) do
  on(Workstation::AnalyticsOverviewPage) do |page|
    page.unhide_channel("Download Albums")
  end
end

Then(/^the Download Albums channel should reappear$/) do
  on(Workstation::AnalyticsOverviewPage) do |page|
    page.wait_for_ajax_scripts_to_finish
    expect(page.download_albums_container_element.element.present?).to be true
    expect(page.hidden_channels_container).not_to include("Download Albums")
  end
end
