2005-03-26 09:03:55 -05:00
|
|
|
require File.dirname(__FILE__) + '/../abstract_unit'
|
|
|
|
|
2005-06-29 04:09:00 -04:00
|
|
|
class JavaScriptHelperTest < Test::Unit::TestCase
|
|
|
|
include ActionView::Helpers::JavaScriptHelper
|
2005-06-18 01:17:39 -04:00
|
|
|
|
|
|
|
include ActionView::Helpers::UrlHelper
|
|
|
|
include ActionView::Helpers::TagHelper
|
2005-07-02 14:20:13 -04:00
|
|
|
include ActionView::Helpers::TextHelper
|
|
|
|
include ActionView::Helpers::FormHelper
|
2005-07-04 00:57:15 -04:00
|
|
|
include ActionView::Helpers::CaptureHelper
|
2005-06-18 01:17:39 -04:00
|
|
|
|
2005-06-26 08:03:43 -04:00
|
|
|
def test_define_javascript_functions
|
|
|
|
# check if prototype.js is included first
|
2005-06-29 04:09:00 -04:00
|
|
|
assert_not_nil define_javascript_functions.split("\n")[1].match(/Prototype JavaScript framework/)
|
2005-09-28 04:20:47 -04:00
|
|
|
|
|
|
|
# check that scriptaculous.js is not in here, only needed if loaded remotely
|
|
|
|
assert_nil define_javascript_functions.split("\n")[1].match(/var Scriptaculous = \{/)
|
2005-06-26 08:03:43 -04:00
|
|
|
end
|
2005-03-26 09:03:55 -05:00
|
|
|
|
|
|
|
def test_escape_javascript
|
|
|
|
assert_equal %(This \\"thing\\" is really\\n netos\\'), escape_javascript(%(This "thing" is really\n netos'))
|
|
|
|
end
|
2005-10-13 13:39:14 -04:00
|
|
|
|
2005-06-18 01:17:39 -04:00
|
|
|
def test_link_to_function
|
2005-09-20 03:54:55 -04:00
|
|
|
assert_dom_equal %(<a href="#" onclick="alert('Hello world!'); return false;">Greeting</a>),
|
2005-06-18 01:17:39 -04:00
|
|
|
link_to_function("Greeting", "alert('Hello world!')")
|
|
|
|
end
|
|
|
|
|
2005-12-30 22:50:08 -05:00
|
|
|
def test_link_to_function_with_existing_onclick
|
2005-12-30 22:51:43 -05:00
|
|
|
assert_dom_equal %(<a href="#" onclick="confirm('Sanity!'); alert('Hello world!'); return false;">Greeting</a>),
|
2005-12-30 22:50:08 -05:00
|
|
|
link_to_function("Greeting", "alert('Hello world!')", :onclick => "confirm('Sanity!')")
|
|
|
|
end
|
2005-12-30 23:31:10 -05:00
|
|
|
|
2006-04-19 14:08:15 -04:00
|
|
|
def test_link_to_function_with_rjs_block
|
|
|
|
html = link_to_function( "Greet me!" ) do |page|
|
|
|
|
page.replace_html 'header', "<h1>Greetings</h1>"
|
|
|
|
end
|
|
|
|
assert_dom_equal %(<a href="#" onclick="Element.update("header", "<h1>Greetings</h1>");; return false;">Greet me!</a>), html
|
|
|
|
end
|
|
|
|
|
2006-09-05 21:31:04 -04:00
|
|
|
def test_link_to_function_with_rjs_block_and_options
|
|
|
|
html = link_to_function( "Greet me!", :class => "updater" ) do |page|
|
|
|
|
page.replace_html 'header', "<h1>Greetings</h1>"
|
|
|
|
end
|
|
|
|
assert_dom_equal %(<a href="#" class="updater" onclick="Element.update("header", "<h1>Greetings</h1>");; return false;">Greet me!</a>), html
|
|
|
|
end
|
2006-04-19 14:08:15 -04:00
|
|
|
|
2005-12-30 23:31:10 -05:00
|
|
|
def test_button_to_function
|
|
|
|
assert_dom_equal %(<input type="button" onclick="alert('Hello world!');" value="Greeting" />),
|
|
|
|
button_to_function("Greeting", "alert('Hello world!')")
|
|
|
|
end
|
2006-04-19 14:08:15 -04:00
|
|
|
|
|
|
|
def test_button_to_function_with_rjs_block
|
|
|
|
html = button_to_function( "Greet me!" ) do |page|
|
|
|
|
page.replace_html 'header', "<h1>Greetings</h1>"
|
|
|
|
end
|
|
|
|
assert_dom_equal %(<input type="button" onclick="Element.update("header", "<h1>Greetings</h1>");;" value="Greet me!" />), html
|
|
|
|
end
|
2006-09-05 21:31:04 -04:00
|
|
|
|
|
|
|
def test_button_to_function_with_rjs_block_and_options
|
|
|
|
html = button_to_function( "Greet me!", :class => "greeter" ) do |page|
|
|
|
|
page.replace_html 'header', "<h1>Greetings</h1>"
|
|
|
|
end
|
|
|
|
assert_dom_equal %(<input type="button" class="greeter" onclick="Element.update("header", "<h1>Greetings</h1>");;" value="Greet me!" />), html
|
|
|
|
end
|
2005-03-26 09:03:55 -05:00
|
|
|
end
|