2005-09-11 08:40:46 +00:00
|
|
|
require File.dirname(__FILE__) + '/../abstract_unit'
|
|
|
|
|
|
|
|
class JavaScriptMacrosHelperTest < Test::Unit::TestCase
|
|
|
|
include ActionView::Helpers::JavaScriptHelper
|
|
|
|
include ActionView::Helpers::JavaScriptMacrosHelper
|
|
|
|
|
|
|
|
include ActionView::Helpers::UrlHelper
|
|
|
|
include ActionView::Helpers::TagHelper
|
|
|
|
include ActionView::Helpers::TextHelper
|
|
|
|
include ActionView::Helpers::FormHelper
|
|
|
|
include ActionView::Helpers::CaptureHelper
|
|
|
|
|
|
|
|
def setup
|
|
|
|
@controller = Class.new do
|
|
|
|
def url_for(options, *parameters_for_method_reference)
|
|
|
|
url = "http://www.example.com/"
|
|
|
|
url << options[:action].to_s if options and options[:action]
|
|
|
|
url
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@controller = @controller.new
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def test_auto_complete_field
|
2005-10-12 22:47:39 +00:00
|
|
|
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {})\n//]]>\n</script>),
|
2005-09-11 08:40:46 +00:00
|
|
|
auto_complete_field("some_input", :url => { :action => "autocomplete" });
|
2005-10-12 22:47:39 +00:00
|
|
|
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {tokens:','})\n//]]>\n</script>),
|
2005-09-11 08:40:46 +00:00
|
|
|
auto_complete_field("some_input", :url => { :action => "autocomplete" }, :tokens => ',');
|
2005-10-12 22:47:39 +00:00
|
|
|
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {tokens:[',']})\n//]]>\n</script>),
|
2005-09-11 08:40:46 +00:00
|
|
|
auto_complete_field("some_input", :url => { :action => "autocomplete" }, :tokens => [',']);
|
2005-10-12 22:47:39 +00:00
|
|
|
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {min_chars:3})\n//]]>\n</script>),
|
2005-10-01 05:43:53 +00:00
|
|
|
auto_complete_field("some_input", :url => { :action => "autocomplete" }, :min_chars => 3);
|
2005-10-12 22:47:39 +00:00
|
|
|
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {onHide:function(element, update){Alert('me');}})\n//]]>\n</script>),
|
2005-10-01 05:43:53 +00:00
|
|
|
auto_complete_field("some_input", :url => { :action => "autocomplete" }, :on_hide => "function(element, update){Alert('me');}");
|
2005-09-11 08:40:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_auto_complete_result
|
|
|
|
result = [ { :title => 'test1' }, { :title => 'test2' } ]
|
|
|
|
assert_equal %(<ul><li>test1</li><li>test2</li></ul>),
|
|
|
|
auto_complete_result(result, :title)
|
|
|
|
assert_equal %(<ul><li>t<strong class=\"highlight\">est</strong>1</li><li>t<strong class=\"highlight\">est</strong>2</li></ul>),
|
|
|
|
auto_complete_result(result, :title, "est")
|
|
|
|
|
|
|
|
resultuniq = [ { :title => 'test1' }, { :title => 'test1' } ]
|
|
|
|
assert_equal %(<ul><li>t<strong class=\"highlight\">est</strong>1</li></ul>),
|
|
|
|
auto_complete_result(resultuniq, :title, "est")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_text_field_with_auto_complete
|
|
|
|
assert_match "<style>",
|
|
|
|
text_field_with_auto_complete(:message, :recipient)
|
2005-10-12 22:47:39 +00:00
|
|
|
assert_dom_equal %(<input id=\"message_recipient\" name=\"message[recipient]\" size=\"30\" type=\"text\" /><div class=\"auto_complete\" id=\"message_recipient_auto_complete\"></div><script type=\"text/javascript\">\n//<![CDATA[\nnew Ajax.Autocompleter('message_recipient', 'message_recipient_auto_complete', 'http://www.example.com/auto_complete_for_message_recipient', {})\n//]]>\n</script>),
|
2005-09-11 08:40:46 +00:00
|
|
|
text_field_with_auto_complete(:message, :recipient, {}, :skip_style => true)
|
|
|
|
end
|
|
|
|
end
|