~michaelforrest/use-case-mapper/trunk

« back to all changes in this revision

Viewing changes to vendor/rails/actionpack/test/template/scriptaculous_helper_test.rb

  • Committer: Richard Lee (Canonical)
  • Date: 2010-10-15 15:17:58 UTC
  • mfrom: (190.1.3 use-case-mapper)
  • Revision ID: richard.lee@canonical.com-20101015151758-wcvmfxrexsongf9d
Merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
require 'abstract_unit'
2
 
 
3
 
class ScriptaculousHelperTest < ActionView::TestCase
4
 
  tests ActionView::Helpers::ScriptaculousHelper
5
 
 
6
 
  def setup
7
 
    @controller = Class.new do
8
 
      def url_for(options)
9
 
        url =  "http://www.example.com/"
10
 
        url << options[:action].to_s if options and options[:action]
11
 
        url
12
 
      end
13
 
    end.new
14
 
  end
15
 
  
16
 
  def test_effect
17
 
    assert_equal "new Effect.Highlight(\"posts\",{});", visual_effect(:highlight, "posts")
18
 
    assert_equal "new Effect.Highlight(\"posts\",{});", visual_effect("highlight", :posts)
19
 
    assert_equal "new Effect.Highlight(\"posts\",{});", visual_effect(:highlight, :posts)    
20
 
    assert_equal "new Effect.Fade(\"fademe\",{duration:4.0});", visual_effect(:fade, "fademe", :duration => 4.0)
21
 
    assert_equal "new Effect.Shake(element,{});", visual_effect(:shake)
22
 
    assert_equal "new Effect.DropOut(\"dropme\",{queue:'end'});", visual_effect(:drop_out, 'dropme', :queue => :end)
23
 
    assert_equal "new Effect.Highlight(\"status\",{endcolor:'#EEEEEE'});", visual_effect(:highlight, 'status', :endcolor => '#EEEEEE')
24
 
    assert_equal "new Effect.Highlight(\"status\",{restorecolor:'#500000', startcolor:'#FEFEFE'});", visual_effect(:highlight, 'status', :restorecolor => '#500000', :startcolor => '#FEFEFE')
25
 
 
26
 
    # chop the queue params into a comma separated list
27
 
    beginning, ending = 'new Effect.DropOut("dropme",{queue:{', '}});'
28
 
    ve = [
29
 
      visual_effect(:drop_out, 'dropme', :queue => {:position => "end", :scope => "test", :limit => 2}),
30
 
      visual_effect(:drop_out, 'dropme', :queue => {:scope => :list, :limit => 2}),
31
 
      visual_effect(:drop_out, 'dropme', :queue => {:position => :end, :scope => :test, :limit => 2})
32
 
    ].collect { |v| v[beginning.length..-ending.length-1].split(',') }
33
 
 
34
 
    assert ve[0].include?("limit:2")
35
 
    assert ve[0].include?("scope:'test'")
36
 
    assert ve[0].include?("position:'end'")
37
 
 
38
 
    assert ve[1].include?("limit:2")
39
 
    assert ve[1].include?("scope:'list'")
40
 
 
41
 
    assert ve[2].include?("limit:2")
42
 
    assert ve[2].include?("scope:'test'")
43
 
    assert ve[2].include?("position:'end'")
44
 
  end
45
 
  
46
 
  def test_toggle_effects
47
 
    assert_equal "Effect.toggle(\"posts\",'appear',{});", visual_effect(:toggle_appear,  "posts")
48
 
    assert_equal "Effect.toggle(\"posts\",'slide',{});",  visual_effect(:toggle_slide,   "posts")
49
 
    assert_equal "Effect.toggle(\"posts\",'blind',{});",  visual_effect(:toggle_blind,   "posts")
50
 
    assert_equal "Effect.toggle(\"posts\",'appear',{});", visual_effect("toggle_appear", "posts")
51
 
    assert_equal "Effect.toggle(\"posts\",'slide',{});",  visual_effect("toggle_slide",  "posts")
52
 
    assert_equal "Effect.toggle(\"posts\",'blind',{});",  visual_effect("toggle_blind",  "posts")
53
 
  end
54
 
  
55
 
 
56
 
  def test_sortable_element
57
 
    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>), 
58
 
      sortable_element("mylist", :url => { :action => "order" })
59
 
    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>), 
60
 
      sortable_element("mylist", :tag => "div", :constraint => "horizontal", :url => { :action => "order" })
61
 
    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>|, 
62
 
      sortable_element("mylist", :containment => ['list1','list2'], :constraint => "horizontal", :url => { :action => "order" })
63
 
    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>), 
64
 
      sortable_element("mylist", :containment => 'list1', :constraint => "horizontal", :url => { :action => "order" })
65
 
  end
66
 
  
67
 
  def test_draggable_element
68
 
    assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Draggable(\"product_13\", {})\n//]]>\n</script>),
69
 
      draggable_element("product_13")
70
 
    assert_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Draggable(\"product_13\", {revert:true})\n//]]>\n</script>),
71
 
      draggable_element("product_13", :revert => true)
72
 
  end
73
 
  
74
 
  def test_drop_receiving_element
75
 
    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>),
76
 
      drop_receiving_element("droptarget1")
77
 
    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>),
78
 
      drop_receiving_element("droptarget1", :accept => 'products')
79
 
    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>),
80
 
      drop_receiving_element("droptarget1", :accept => 'products', :update => 'infobox')
81
 
    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>),
82
 
      drop_receiving_element("droptarget1", :accept => ['tshirts','mugs'], :update => 'infobox')
83
 
    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>),
84
 
    drop_receiving_element('droptarget1', :hoverclass=>'dropready', :url=>{:action=>'update_drop'}, :confirm => 'Are you sure?')
85
 
 
86
 
  end
87
 
  def protect_against_forgery?
88
 
    false
89
 
  end
90
 
end