2005-03-26 14:03:55 +00:00
|
|
|
require File.dirname(__FILE__) + '/../abstract_unit'
|
|
|
|
|
2005-06-29 08:09:00 +00:00
|
|
|
class JavaScriptHelperTest < Test::Unit::TestCase
|
|
|
|
include ActionView::Helpers::JavaScriptHelper
|
2005-06-18 05:17:39 +00:00
|
|
|
|
|
|
|
include ActionView::Helpers::UrlHelper
|
|
|
|
include ActionView::Helpers::TagHelper
|
2005-07-02 18:20:13 +00:00
|
|
|
include ActionView::Helpers::TextHelper
|
|
|
|
include ActionView::Helpers::FormHelper
|
2005-07-04 04:57:15 +00:00
|
|
|
include ActionView::Helpers::CaptureHelper
|
2005-06-18 05:17:39 +00:00
|
|
|
|
2005-06-26 12:03:43 +00:00
|
|
|
def test_define_javascript_functions
|
|
|
|
# check if prototype.js is included first
|
2005-06-29 08:09:00 +00:00
|
|
|
assert_not_nil define_javascript_functions.split("\n")[1].match(/Prototype JavaScript framework/)
|
2005-09-28 08:20:47 +00: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 12:03:43 +00:00
|
|
|
end
|
2005-03-26 14:03:55 +00: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 17:39:14 +00:00
|
|
|
|
2005-06-18 05:17:39 +00:00
|
|
|
def test_link_to_function
|
2005-09-20 07:54:55 +00:00
|
|
|
assert_dom_equal %(<a href="#" onclick="alert('Hello world!'); return false;">Greeting</a>),
|
2005-06-18 05:17:39 +00:00
|
|
|
link_to_function("Greeting", "alert('Hello world!')")
|
|
|
|
end
|
|
|
|
|
2005-12-31 03:50:08 +00:00
|
|
|
def test_link_to_function_with_existing_onclick
|
2005-12-31 03:51:43 +00:00
|
|
|
assert_dom_equal %(<a href="#" onclick="confirm('Sanity!'); alert('Hello world!'); return false;">Greeting</a>),
|
2005-12-31 03:50:08 +00:00
|
|
|
link_to_function("Greeting", "alert('Hello world!')", :onclick => "confirm('Sanity!')")
|
|
|
|
end
|
2005-12-31 04:31:10 +00: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
|
2005-03-26 14:03:55 +00:00
|
|
|
end
|