require File.dirname(__FILE__) + '/test_helper'
class SeleneseTest < Test::Unit::TestCase
def selenese name, input, partial = nil, type = nil
view = TestView.new
view.override_partial partial, type do
view.assigns['page_title'] = name
view.render_template 'sel', input
end
end
def assert_selenese expected, name, input, partial = nil, type = nil
assert_text_equal expected, selenese(name, input, partial, type)
end
def test_empty
expected = <
Empty |
END
input = ''
assert_selenese expected, 'Empty', ''
end
def test_one_line
expected = <
One line |
open | / | |
END
input = '|open|/|'
assert_selenese expected, 'One line', input
end
def test_comments_only
expected = <Comment 1
Comment 2
END
input = <
Only commands |
goBack | | |
open | /foo | |
fireEvent | textField | focus |
END
input = <
Commands and comments |
goBack | | |
fireEvent | textField | focus |
Comment 1
Comment 2
END
input = <Comment 1
Comment 2
Comments and commands |
goBack | | |
fireEvent | textField | focus |
END
input = <Comment 1
Comment 2
Comments, commands and comments |
goBack | | |
fireEvent | textField | focus |
Comment 3
END
input = <
HTML escaping |
type | nameField | <>& |
END
input = '|type|nameField|<>&|'
assert_selenese expected, 'HTML escaping', input
end
def test_partial_support
expected = <
Partial support |
type | partial | Selenese partial |
END
input = '|includePartial|override|'
partial = '|type|partial|Selenese partial|'
assert_selenese expected, 'Partial support', input, partial, 'sel'
end
def test_partial_support_with_local_assigns
expected = <
Partial support with local assigns |
type | assigns | a=hello,b=world!,c_123ABC= |
type | assigns | a=a b c d,b=,c_123ABC=hello |
END_EXPECTED
input = <whatever |
type | assigns |
a=<%= a if defined? a%>,
b=<%= b if defined? b%>,
c_123ABC=<%= c_123ABC if defined? c_123ABC%>
|
END_PARTIAL
assert_selenese expected, 'Partial support with local assigns', input, partial, 'rhtml'
end
def test_raised_when_more_than_three_columns
assert_raise RuntimeError, 'There might only be a maximum of three cells!' do
selenese 'name', '|col1|col2|col3|col4|'
end
end
def test_raised_when_more_than_one_set_of_commands
assert_raise RuntimeError, 'You cannot have comments in the middle of commands!' do
input = <