require 'test_helper.rb' class SlideRendererTest < Clean::Test::TestCase def setup @renderer = Trickster::SlideRenderer.new end NORMAL_TYPES = ["TITLE","SECTION","NORMAL"] NORMAL_TYPES.each do |slide_type| test_that "a #{slide_type} slide gets first three lines rendered in HTML" do Given { @content = [ any_string, any_string, any_string, any_string, ] } When { @renderer.render_slide(slide_type,@content) } Then { assert_content( slide_type, [ "
> #{@command1}",
"#{@result1}",
"% #{@command2}",
"#{@result2}",
"
",
],
@renderer.content)
}
end
test_that "COMMANDLINE groups commands and responses together" do
Given {
@command1 = any_string :max => 10
@result1a = any_string :max => 10
@result1b = any_string :max => 10
@command2 = any_string :max => 10
@result2 = any_string :max => 10
@command3 = any_string :max => 10
@content = [
">" + @command1,
@result1a,
@result1b,
"%" + @command2,
@result2,
">" + @command3,
]
}
When {
@renderer.render_slide("COMMANDLINE",@content)
}
Then {
assert_content(
"COMMANDLINE",
[
"> #{@command1}",
"#{@result1a}",
"#{@result1b}",
"% #{@command2}",
"#{@result2}",
"> #{@command3}",
"
",
],
@renderer.content)
}
end
test_that "CODE wraps the code in a pre/code block" do
Given {
@code = [
"#{any_string}",
" #{any_string}",
" #{any_string} #{any_string}",
"#{any_string}",
]
}
When {
@renderer.render_slide("CODE",@code)
}
Then {
assert_content(
"CODE",
[
"#{wrap_line(@code[0],1)}",
wrap_line(@code[1],2),
wrap_line(@code[2],3),
"#{wrap_line(@code[3],4)}
",
],
@renderer.content)
}
end
test_that "CODE uses the language specified in the options" do
Given {
@code = [
"#{any_string}",
" #{any_string}",
" #{any_string} #{any_string}",
"#{any_string}",
]
@language = any_string
}
When {
@renderer.render_slide("CODE: language=#{@language}",@code)
}
Then {
assert_content(
"CODE",
[
"#{wrap_line(@code[0],1)}",
wrap_line(@code[1],2),
wrap_line(@code[2],3),
"#{wrap_line(@code[3],4)}
",
],
@renderer.content)
}
end
test_that "CODE that has callouts, with strikouts, as those added to the proper data attributes" do
Given {
@code = [
"#{any_string}",
" #{any_string}",
" #{any_string} #{any_string}",
"#{any_string}",
]
}
When {
@renderer.render_slide("CODE: callout=1,-2,3",@code)
}
Then {
assert_content(
"CODE",
[
"#{wrap_line(@code[0],1,true)}",
wrap_line(@code[1],2,true),
wrap_line(@code[2],3,true),
"#{wrap_line(@code[3],4)}
",
],
@renderer.content)
}
end
test_that "CODE can be read from a file" do
Given {
@code = [
"#{any_string}",
" #{any_string}",
" #{any_string} #{any_string}",
"#{any_string}",
]
@filename = "/tmp/#{$$}.code"
File.open(@filename,'w') do |file|
@code.each do |line|
file.puts line
end
end
}
When {
@renderer.render_slide("CODE",["file://" + @filename])
}
Then {
assert_content(
"CODE",
[
"#{wrap_line(@code[0],1)}",
wrap_line(@code[1],2),
wrap_line(@code[2],3),
"#{wrap_line(@code[3],4)}
",
],
@renderer.content)
}
end
private
def assert_content(slide_type,lines,content,background_attribute=nil,transition_attribute=nil)
expected_content = [
" ",
"",
].flatten.join("\n")
assert_equal expected_content,content
end
def extra_attributes(background_attribute,transition_attribute)
background = background_attribute.nil? ? '' : " data-background='#{background_attribute}'"
transition = transition_attribute.nil? ? '' : " data-transition='#{transition_attribute}'"
return background + transition
end
def wrap_line(line,index,callout=false)
"#{line}"
end
end