require File.dirname(__FILE__) + '/test_helper'
class SeleneseTest < Test::Unit::TestCase
def setup
@view = TestView.new
@sel = SeleniumOnRails::Selenese.new(@view)
end
def render_selenese(page_title, input)
create_sel_file_from(input, "html.sel")
@sel.render ActionView::Template.new(test_path_for("html.sel")), {'page_title' => page_title}
end
def create_sel_file_from(input, name)
File.open(test_path_for(name), 'w+') { |index_file| index_file << input }
end
def test_path_for(name)
"#{File.expand_path(File.dirname(__FILE__) + "/../test_data")}/#{name}"
end
def assert_selenese expected, name, input
assert_text_equal expected, render_selenese(name, input)
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|'
create_sel_file_from(partial, "_override.sel")
assert_selenese(expected, 'Partial support', input)
File.delete(test_path_for("_override.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
create_sel_file_from(partial, "_override.html")
assert_selenese(expected, 'Partial support with local assigns', input)
File.delete(test_path_for("_override.html"))
end
def test_raised_when_more_than_three_columns
assert_raise RuntimeError, 'There might only be a maximum of three cells!' do
render_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 = <