javascript_helper_test.rb 1.4 KB
Newer Older
1 2
require File.dirname(__FILE__) + '/../abstract_unit'

3 4
class JavaScriptHelperTest < Test::Unit::TestCase
  include ActionView::Helpers::JavaScriptHelper
5 6 7
  
  include ActionView::Helpers::UrlHelper
  include ActionView::Helpers::TagHelper
8 9
  include ActionView::Helpers::TextHelper
  include ActionView::Helpers::FormHelper
10
  include ActionView::Helpers::CaptureHelper
11
  
12 13
  def test_define_javascript_functions
    # check if prototype.js is included first
14
    assert_not_nil define_javascript_functions.split("\n")[1].match(/Prototype JavaScript framework/)
15 16 17
    
    # check that scriptaculous.js is not in here, only needed if loaded remotely
    assert_nil define_javascript_functions.split("\n")[1].match(/var Scriptaculous = \{/)
18
  end
19 20 21 22

  def test_escape_javascript
    assert_equal %(This \\"thing\\" is really\\n netos\\'), escape_javascript(%(This "thing" is really\n netos'))
  end
23
                                      
24
  def test_link_to_function
25
    assert_dom_equal %(<a href="#" onclick="alert('Hello world!'); return false;">Greeting</a>), 
26 27 28
      link_to_function("Greeting", "alert('Hello world!')")
  end
  
29
  def test_link_to_function_with_existing_onclick
30
    assert_dom_equal %(<a href="#" onclick="confirm('Sanity!'); alert('Hello world!'); return false;">Greeting</a>), 
31 32
      link_to_function("Greeting", "alert('Hello world!')", :onclick => "confirm('Sanity!')")
  end
33
end