Then(/^the statement for the current period should be visible$/) do
  puts "Label info: #{@label}"

  on(StatementsPage) do |page|
    puts "Latest Period on page: #{page.latest_period}"
    if @label["type"] == "monthly"
      expected = period_to_month_string(ENVied.PERIOD)
      puts "Expected Period based on PERIOD env var: #{expected}"
    elsif @label["type"] == "quarterly"
      expected = period_to_quarter_string(ENVied.PERIOD)
      puts "Expected Period based on PERIOD env var: #{expected}"
    else
      fail "Cannot determine payment interval type for label: #{@label}"
    end

    expect(page.latest_period).to eq(expected)
  end
end

When(/^I request the report for the current period$/) do
  on(StatementsPage) do |page|
    if page.latest_period_report_status == "Request Report"
      puts "Clicking the [ Request Report ] button"
      page.click_request_report
    elsif page.latest_period_report_status == "Report Queued"
      puts "Looks like the report was already requested..."
    else
      fail "Unknown export status: #{page.latest_period_report_status}"
    end
  end
end

When(/^the Revenue listed should match that of the BreakdownPage$/) do
  on(StatementsPage) do |page|
    @exp_revenue = page.latest_period_revenue
    puts "Revenue from Statements page: #{@exp_revenue}"
    page.click_view_breakdown
  end

  on(BreakdownPage) do |page|
    @actual_revenue = page.revenue_element.when_present.text
    puts "Revenue from Breakdown page: #{@actual_revenue}"
  end

  expect(currency_amount_from(@actual_revenue)).to eq(currency_amount_from(@exp_revenue))
end
