require 'spec_helper'

feature "Viewing graphs" do
  before do
    Stratify::Collector.collector_classes.clear
    Stratify::Collector.collector_classes << Stratify::Bacon::Collector
  end

  scenario "Viewing the punch card graph" do
    activity = FactoryGirl.create(:bacon_activity, :created_at => Time.parse("Fri, 1 Jul 2011 19:27 EDT"))

    set_time_zone_cookie("America/New_York")
    visit "/graphs/punch_card"

    page.should have_content("Baconation Activity by Day and Hour")

    graph_image_tag = page.find("div.punch_card_graph.baconation img")
    graph_url = graph_image_tag[:src]

    graph_url.should =~ %r[^https://chart.googleapis.com/chart]

    params = CGI.parse(URI.parse(URI.encode(graph_url)).query)
    params["cht"].should  == ["s"]
    params["chxt"].should == ["x,y"]
    params["chds"].should == ["-1,24,-1,7,0,1"]
    params["chd"].should  == ["t:0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23|0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6|0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"]
    params["chs"].should_not be_nil
    params["chf"].should_not be_nil
    params["chm"].should_not be_nil
    params["chxl"].should_not be_nil
  end
end
