require 'minitest_helper'
require 'webmock/minitest'
module SlideHero
describe Slide do
describe "initialization" do
it "is initialized with a title" do
slide = Slide.new("Badgers learn knitting")
slide.headline.must_equal "Badgers learn knitting"
end
it "can be initialized with no title" do
slide = Slide.new
slide.headline.must_equal nil
end
it "can take an optional side directive" do
slide = Slide.new("Badgers learn knitting", headline_size: :large)
slide.headline_size.must_equal :large
slide = Slide.new("Snacks lead to revolution in food care", headline_size: :medium)
slide.headline_size.must_equal :medium
end
it "can take a background color" do
slide = Slide.new("Badgers learn knitting", background_color: 'blue')
slide.background_color.must_equal 'blue'
end
end
describe "compilation" do
it "outputs object to html" do
slide = Slide.new("To Markup!")
assert_dom_match slide.compile, "" +
"
To Markup!
" +
""
end
it "respects headline size" do
slide = Slide.new("To Markup!", headline_size: :medium)
assert_dom_match slide.compile, "" +
"
To Markup!
" +
""
end
it "takes transitions" do
slide = Slide.new("transitions", transition: :zoom) do
end
assert_dom_match slide.compile, '' +
'
transitions
' +
''
end
it "takes a background_color" do
slide = Slide.new("background_color", background_color: 'blue') do
end
assert_dom_match slide.compile, '' +
'
background_color
' +
''
end
end
describe "#point syntax" do
it "embeds text in p tags by default" do
slide = Slide.new "Embedding" do
point "I'm embedded!"
end
assert_dom_match slide.compile, "" +
"
Embedding
" +
"
I'm embedded!
" +
""
end
it "embeds raw html" do
slide = Slide.new "Embedding" do
point "I'm embedded!"
end
assert_dom_match slide.compile, "" +
"
Embedding
" +
"
I'm embedded!
" +
""
end
it "embeds multiple points" do
slide = Slide.new "Embedding" do
point "I'm embedded!"
point "Me too!"
end
assert_dom_match slide.compile, "" +
"
Embedding
" +
"
I'm embedded!
" +
"
Me too!
" +
""
end
it "animates points" do
slide = Slide.new "Animation" do
point "I'm animated!", animation: true
end
assert_dom_match slide.compile, ""+
"
Animation
" +
"
I'm animated!
" +
""
end
end
describe "#list" do
it "creates bullets from a block" do
slide = Slide.new "Lists" do
list do
point "Bullet Points"
point "Another Point"
end
end
assert_dom_match slide.compile, "" +
"
Lists
" +
"
" +
"
Bullet Points
" +
"
Another Point
" +
"
" +
""
end
it "creates ordered lists from a block" do
slide = Slide.new "Lists" do
list(:ordered) do
point "Ordered!"
point "Also ordered!"
end
end
assert_dom_match slide.compile, "" +
"
Lists
" +
"" +
"
Ordered!
" +
"
Also ordered!
" +
"" +
""
end
end
describe "#code" do
it "embeds code in a slide" do
slide = Slide.new "Code" do
code(:ruby, File.join(Dir.pwd,"test","fixtures")) do
"testclass.rb"
end
end
assert_dom_match slide.compile, "" +
"
Code
" +
"
class Working
def some_method
\"woot!\"
end
end
"
end
end
describe "#note" do
it "returns a formatted note" do
slide = Slide.new "Note" do
note "Don't forget to bring a towel"
end
assert_dom_match slide.compile, "" +
"
Note
" +
"" +
""
end
end
describe "#image" do
it "returns a formatted Image" do
slide = Slide.new "Image" do
image("cornify.gif", "Unicorn", width: 280, height: 326)
end
slide.compile.must_include %{}
end
end
describe "#remote_image" do
after do
image = File.join(Dir.pwd,"test","tmp","images", "le_troll.png")
File.delete(image)
end
it "returns a formatted Image from a remote source" do
stub_request(:get, "http://example.com/troll.png").
to_return(body: File.open(File.join(Dir.pwd,"test","fixtures","images", "image.png")))
destination_folder = File.join(Dir.pwd,"test","tmp","images")
slide = Slide.new "Image" do
remote_image("http://example.com/troll.png", "Troll", width: 280, height: 326, as: "le_troll", destination: destination_folder)
end
slide.compile.must_include %{}
end
end
describe "#media" do
it "returns a formatted media element" do
slide = Slide.new "Video" do
media "video.mp4", type: :video
end
slide.compile.must_include %{}
end
end
end
end