spec/html_helpers/charts_spec.rb
require File.expand_path(File.join(File.dirname(__FILE__), %w[.. spec_helper]))

describe Ziya::HtmlHelpers::Charts do   
  include Ziya::HtmlHelpers::Charts
  
  it "should generate a flash js header tag correctly" do
    ziya_javascript_include_tag.should == "      <script language=\"javascript\" type=\"text/javascript\">\n        AC_FL_RunContent = 0;\n        DetectFlashVer = 0;\n      </script>\n      <script src=\"/charts/AC_RunActiveContent.js\" language=\"javascript\"></script>\n      <script language=\"javascript\" type=\"text/javascript\">\n        var requiredMajorVersion = 9;\n        var requiredMinorVersion = 0;\n        var requiredRevision = 45;\n      </script>\n"
  end
  
  it "should generate the chart default options correctly" do
    default_chart_options[:swf_path].should  == "/charts"
    default_chart_options[:asset_url].should == "/charts"    
  end
  
  it "should generate the correct flash embed tag using js" do
    ziya_chart_js( "/test/test_me", :swf_path => "/test_me", :asset_url => "/test" ).should == "      <script language=\"javascript\" type=\"text/javascript\">\n      if (AC_FL_RunContent == 0 || DetectFlashVer == 0) {\n        alert( \"This page requires AC_RunActiveContent.js.\" );\n      } \n      else {\n        var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);\n        if( hasRightVersion ) { \n          AC_FL_RunContent(\n            'codebase'         , 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,45,2',\n            'width'            , '400',\n            'height'           , '300',\n            'scale'            , 'noscale',\n            'salign'           , 'tl',\n            'bgcolor'          , 'ffffff',\n            'wmode'            , 'opaque',\n            'movie'            , '/test_me/charts',\n            'src'              , '/test_me/charts',\n            'FlashVars'        , 'library_path=/test_me/charts_library&xml_source=%2Ftest%2Ftest_me&chart_id=ziya_chart', \n            'id'               , 'ziya_chart',\n            'name'             , 'ziya_chart',\n            'menu'             , 'true',\n            'allowFullScreen'  , 'true',\n            'allowScriptAccess','sameDomain',\n            'quality'          , 'high',\n            'align'            , 'l',\n            'pluginspage'      , 'http://www.macromedia.com/go/getflashplayer',\n            'play'             , 'true',\n            'devicefont'       , 'false'\n          ); \n        } \n        else { \n          var alternateContent = 'This content requires the Adobe Flash Player. '\n          + '<u><a href=http://www.macromedia.com/go/getflash/>Get Flash</a></u>.';\n          document.write(alternateContent); \n        }\n      }\n      </script>\n"
  end
  
  it "should generate the correct flash embed tag" do
    ziya_chart( "/test/test_me", :swf_path => '/blee' ).should == "    <object codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,45,2\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" id=\"ziya_chart\" height=\"300\" width=\"400\">\n      <param name=\"scale\"             value=\"noscale\"/>\n      <param name=\"salign\"            value=\"tl\"/>            \n      <param name=\"bgcolor\"           value=\"ffffff\"/>\n      <param name=\"wmode\"             value=\"opaque\"/>                                  \n      <param name=\"movie\"             value=\"/charts/charts.swf\"/>\n      <param name=\"Flashvars\"         value=\"library_path=/blee/charts_library&xml_source=%2Ftest%2Ftest_me&amp;chart_id=ziya_chart\"/>\n      <param name=\"menu\"              value=\"true\"/>\n      <param name=\"allowFullScreen\"   value=\"true\"/>\n      <param name=\"allowScriptAccess\" value=\"\"/>            \n      <param name=\"quality\"           value=\"high\"/>\n      <param name=\"play\"              value=\"true\"/>                        \n      <param name=\"devicefont\"        value=\"false\"/>\n        <embed scale=\"noscale\" \n          allowfullscreen   = \"true\" \n          allowscriptaccess = \"\" \n          bgcolor           = \"ffffff\" \n          devicefont        = \"false\" \n          flashvars         = \"library_path=/blee/charts_library&xml_source=%2Ftest%2Ftest_me&amp;chart_id=ziya_chart\" \n          menu              = \"true\" \n          name              = \"ziya_chart\" \n          play              = \"true\" \n          pluginspage       = \"http://www.macromedia.com/go/getflashplayer\" \n          quality           = \"high\" \n          salign            = \"tl\" \n          src               = \"/charts/charts.swf\" \n          type              = \"application/x-shockwave-flash\" \n          wmode             = \"opaque\" \n          align             = \"l\" \n          height            = \"300\" \n          width             = \"400\"/>            \n     </object>        \n" 
  end
end
  