Skip to content

Commit

Permalink
Added test for back method
Browse files Browse the repository at this point in the history
  • Loading branch information
ngiger committed Dec 22, 2015
1 parent 28deaa8 commit 8e5af87
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
27 changes: 22 additions & 5 deletions test/test_composite.rb
Expand Up @@ -31,6 +31,7 @@
require 'htmlgrid/composite'
require 'htmlgrid/inputtext'
require 'htmlgrid/form'
require 'htmlgrid/button'

class StubComposite < HtmlGrid::Composite
attr_writer :container
Expand Down Expand Up @@ -58,6 +59,9 @@ def baz(model, lookandfeel)
@barcount += 1
"Baz#{@barcount}"
end
def back
super
end
end
class StubCompositeComponent < HtmlGrid::Component
def to_html(context)
Expand All @@ -84,6 +88,9 @@ class StubCompositeNoLabel < HtmlGrid::Composite
class StubCompositeModel
end
class StubCompositeLookandfeel
def event_url(one)
return 'event_url'
end
def attributes(key)
{}
end
Expand Down Expand Up @@ -172,10 +179,10 @@ def test_labels1
def test_labels2
assert_equal(true, @composite.labels?)
end
def test_to_html
expected = '<TABLE cellspacing="0"><TR><TD>Baz1FooBaz2</TD></TR><TR><TD>Baz3Baz4</TD></TR></TABLE>'
assert_equal(expected, @composite.to_html(CGI.new))
end
def test_to_html
expected = '<TABLE cellspacing="0"><TR><TD>Baz1FooBaz2</TD></TR><TR><TD>Baz3Baz4</TD></TR></TABLE>'
assert_equal(expected, @composite.to_html(CGI.new))
end
def test_resolve_offset
matrix = [1,2,3,4]
assert_equal(matrix, @composite.resolve_offset(matrix))
Expand All @@ -197,5 +204,15 @@ def test_component_css_map
expected = '<TABLE cellspacing="0"><TR><TD><A class="standard">brafoo</A></TD></TR></TABLE>'
assert_equal(expected, composite.to_html(CGI.new))
composite = StubComposite4.new(StubCompositeModel.new, StubCompositeSession.new)
end
end
def test_to_back
if RUBY_VERSION.split(".").first.eql?('1')
expected = "<INPUT type=\"button\" name=\"back\" onClick=\"document.location.href='event_url';\">"
else
# It looks like Ruby 2.x escapes the ' which is not strictly necessary
expected = "<INPUT type=\"button\" name=\"back\" onClick=\"document.location.href=&#39;event_url&#39;;\">"
end
html = @composite.back().to_html(CGI.new)
assert_equal(expected, html)
end
end
1 change: 0 additions & 1 deletion test/test_interaction_list.rb
Expand Up @@ -253,7 +253,6 @@ def test_interaction_list_to_html
]
html = composite.to_html(CGI.new)
expected.each_with_index do |line, idx|
# puts "#{idx}: missing #{line}" unless html.index(line)
assert(html.index(line), "#{idx}: missing #{line} in #{html}")
end
end
Expand Down

0 comments on commit 8e5af87

Please sign in to comment.