2008-01-05 08:32:06 -05:00
|
|
|
require 'abstract_unit'
|
2005-11-14 17:28:47 -05:00
|
|
|
|
2008-04-19 14:06:57 -04:00
|
|
|
class ScriptaculousHelperTest < ActionView::TestCase
|
|
|
|
tests ActionView::Helpers::ScriptaculousHelper
|
|
|
|
|
2005-11-14 17:28:47 -05:00
|
|
|
def setup
|
2009-04-08 20:33:06 -04:00
|
|
|
super
|
2005-11-14 17:28:47 -05:00
|
|
|
@controller = Class.new do
|
2007-05-12 17:12:31 -04:00
|
|
|
def url_for(options)
|
2005-11-14 17:28:47 -05:00
|
|
|
url = "http://www.example.com/"
|
|
|
|
url << options[:action].to_s if options and options[:action]
|
|
|
|
url
|
|
|
|
end
|
|
|
|
end.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_effect
|
2006-03-05 01:42:58 -05:00
|
|
|
assert_equal "new Effect.Highlight(\"posts\",{});", visual_effect(:highlight, "posts")
|
|
|
|
assert_equal "new Effect.Highlight(\"posts\",{});", visual_effect("highlight", :posts)
|
|
|
|
assert_equal "new Effect.Highlight(\"posts\",{});", visual_effect(:highlight, :posts)
|
|
|
|
assert_equal "new Effect.Fade(\"fademe\",{duration:4.0});", visual_effect(:fade, "fademe", :duration => 4.0)
|
2005-11-14 17:28:47 -05:00
|
|
|
assert_equal "new Effect.Shake(element,{});", visual_effect(:shake)
|
2006-03-05 01:42:58 -05:00
|
|
|
assert_equal "new Effect.DropOut(\"dropme\",{queue:'end'});", visual_effect(:drop_out, 'dropme', :queue => :end)
|
2007-09-02 19:51:27 -04:00
|
|
|
assert_equal "new Effect.Highlight(\"status\",{endcolor:'#EEEEEE'});", visual_effect(:highlight, 'status', :endcolor => '#EEEEEE')
|
|
|
|
assert_equal "new Effect.Highlight(\"status\",{restorecolor:'#500000', startcolor:'#FEFEFE'});", visual_effect(:highlight, 'status', :restorecolor => '#500000', :startcolor => '#FEFEFE')
|
2006-03-05 11:35:27 -05:00
|
|
|
|
|
|
|
# chop the queue params into a comma separated list
|
|
|
|
beginning, ending = 'new Effect.DropOut("dropme",{queue:{', '}});'
|
|
|
|
ve = [
|
|
|
|
visual_effect(:drop_out, 'dropme', :queue => {:position => "end", :scope => "test", :limit => 2}),
|
|
|
|
visual_effect(:drop_out, 'dropme', :queue => {:scope => :list, :limit => 2}),
|
2006-02-27 05:37:59 -05:00
|
|
|
visual_effect(:drop_out, 'dropme', :queue => {:position => :end, :scope => :test, :limit => 2})
|
2006-03-05 11:35:27 -05:00
|
|
|
].collect { |v| v[beginning.length..-ending.length-1].split(',') }
|
|
|
|
|
|
|
|
assert ve[0].include?("limit:2")
|
|
|
|
assert ve[0].include?("scope:'test'")
|
|
|
|
assert ve[0].include?("position:'end'")
|
|
|
|
|
|
|
|
assert ve[1].include?("limit:2")
|
|
|
|
assert ve[1].include?("scope:'list'")
|
|
|
|
|
|
|
|
assert ve[2].include?("limit:2")
|
|
|
|
assert ve[2].include?("scope:'test'")
|
|
|
|
assert ve[2].include?("position:'end'")
|
2005-11-14 17:28:47 -05:00
|
|
|
end
|
2005-12-25 13:53:22 -05:00
|
|
|
|
|
|
|
def test_toggle_effects
|
2006-03-05 01:42:58 -05:00
|
|
|
assert_equal "Effect.toggle(\"posts\",'appear',{});", visual_effect(:toggle_appear, "posts")
|
|
|
|
assert_equal "Effect.toggle(\"posts\",'slide',{});", visual_effect(:toggle_slide, "posts")
|
|
|
|
assert_equal "Effect.toggle(\"posts\",'blind',{});", visual_effect(:toggle_blind, "posts")
|
|
|
|
assert_equal "Effect.toggle(\"posts\",'appear',{});", visual_effect("toggle_appear", "posts")
|
|
|
|
assert_equal "Effect.toggle(\"posts\",'slide',{});", visual_effect("toggle_slide", "posts")
|
|
|
|
assert_equal "Effect.toggle(\"posts\",'blind',{});", visual_effect("toggle_blind", "posts")
|
2005-12-25 13:53:22 -05:00
|
|
|
end
|
|
|
|
|
2005-12-23 19:52:14 -05:00
|
|
|
|
2005-11-14 17:28:47 -05:00
|
|
|
def test_sortable_element
|
2006-03-05 01:42:58 -05:00
|
|
|
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nSortable.create(\"mylist\", {onUpdate:function(){new Ajax.Request('http://www.example.com/order', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize(\"mylist\")})}})\n//]]>\n</script>),
|
2005-11-14 17:28:47 -05:00
|
|
|
sortable_element("mylist", :url => { :action => "order" })
|
2006-03-05 01:42:58 -05:00
|
|
|
assert_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nSortable.create(\"mylist\", {constraint:'horizontal', onUpdate:function(){new Ajax.Request('http://www.example.com/order', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize(\"mylist\")})}, tag:'div'})\n//]]>\n</script>),
|
2005-11-14 17:28:47 -05:00
|
|
|
sortable_element("mylist", :tag => "div", :constraint => "horizontal", :url => { :action => "order" })
|
2006-03-05 01:42:58 -05:00
|
|
|
assert_dom_equal %|<script type=\"text/javascript\">\n//<![CDATA[\nSortable.create(\"mylist\", {constraint:'horizontal', containment:['list1','list2'], onUpdate:function(){new Ajax.Request('http://www.example.com/order', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize(\"mylist\")})}})\n//]]>\n</script>|,
|
2005-11-14 17:28:47 -05:00
|
|
|
sortable_element("mylist", :containment => ['list1','list2'], :constraint => "horizontal", :url => { :action => "order" })
|
2006-03-05 01:42:58 -05:00
|
|
|
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nSortable.create(\"mylist\", {constraint:'horizontal', containment:'list1', onUpdate:function(){new Ajax.Request('http://www.example.com/order', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize(\"mylist\")})}})\n//]]>\n</script>),
|
2005-11-14 17:28:47 -05:00
|
|
|
sortable_element("mylist", :containment => 'list1', :constraint => "horizontal", :url => { :action => "order" })
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_draggable_element
|
2006-03-05 01:42:58 -05:00
|
|
|
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Draggable(\"product_13\", {})\n//]]>\n</script>),
|
|
|
|
draggable_element("product_13")
|
|
|
|
assert_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Draggable(\"product_13\", {revert:true})\n//]]>\n</script>),
|
|
|
|
draggable_element("product_13", :revert => true)
|
2005-11-14 17:28:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_drop_receiving_element
|
2006-03-05 01:42:58 -05:00
|
|
|
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nDroppables.add(\"droptarget1\", {onDrop:function(element){new Ajax.Request('http://www.example.com/', {asynchronous:true, evalScripts:true, parameters:'id=' + encodeURIComponent(element.id)})}})\n//]]>\n</script>),
|
|
|
|
drop_receiving_element("droptarget1")
|
|
|
|
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nDroppables.add(\"droptarget1\", {accept:'products', onDrop:function(element){new Ajax.Request('http://www.example.com/', {asynchronous:true, evalScripts:true, parameters:'id=' + encodeURIComponent(element.id)})}})\n//]]>\n</script>),
|
|
|
|
drop_receiving_element("droptarget1", :accept => 'products')
|
|
|
|
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nDroppables.add(\"droptarget1\", {accept:'products', onDrop:function(element){new Ajax.Updater('infobox', 'http://www.example.com/', {asynchronous:true, evalScripts:true, parameters:'id=' + encodeURIComponent(element.id)})}})\n//]]>\n</script>),
|
|
|
|
drop_receiving_element("droptarget1", :accept => 'products', :update => 'infobox')
|
|
|
|
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nDroppables.add(\"droptarget1\", {accept:['tshirts','mugs'], onDrop:function(element){new Ajax.Updater('infobox', 'http://www.example.com/', {asynchronous:true, evalScripts:true, parameters:'id=' + encodeURIComponent(element.id)})}})\n//]]>\n</script>),
|
|
|
|
drop_receiving_element("droptarget1", :accept => ['tshirts','mugs'], :update => 'infobox')
|
2008-02-15 19:07:52 -05:00
|
|
|
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nDroppables.add("droptarget1", {hoverclass:'dropready', onDrop:function(element){if (confirm('Are you sure?')) { new Ajax.Request('http://www.example.com/update_drop', {asynchronous:true, evalScripts:true, parameters:'id=' + encodeURIComponent(element.id)}); }}})\n//]]>\n</script>),
|
|
|
|
drop_receiving_element('droptarget1', :hoverclass=>'dropready', :url=>{:action=>'update_drop'}, :confirm => 'Are you sure?')
|
2007-09-28 11:55:45 -04:00
|
|
|
|
2008-02-15 19:07:52 -05:00
|
|
|
end
|
2007-09-28 11:55:45 -04:00
|
|
|
def protect_against_forgery?
|
|
|
|
false
|
2007-09-22 22:32:55 -04:00
|
|
|
end
|
2007-01-28 02:16:55 -05:00
|
|
|
end
|