require 'test_helper'
class FontAwesome5::Rails::IconHelperTest < ActionView::TestCase
test "#fa_solid_icon with no args should render a flag icon" do
assert_icon i("fas fa-camera-retro")
end
test "#fa_solid_icon should render different individual icons" do
assert_icon i("fas fa-flag"), "flag"
assert_icon i("fas fa-camera-retro"), "camera-retro"
assert_icon i("fas fa-cog"), "cog"
assert_icon i("fas fa-github"), "github"
end
test "#fa_solid_icon should render icons with multiple modifiers" do
assert_icon i("fas fa-pencil fa-fixed-width"), "pencil fixed-width"
assert_icon i("fas fa-flag fa-4x"), "flag 4x"
assert_icon i("fas fa-refresh fa-2x fa-spin"), "refresh 2x spin"
end
test "#fa_solid_icon should render icons with array modifiers" do
assert_icon i("fas fa-flag"), ["flag"]
assert_icon i("fas fa-check fa-li"), ["check", "li"]
assert_icon i("fas fa-flag fa-4x"), ["flag", "4x"]
assert_icon i("fas fa-refresh fa-2x fa-spin"), ["refresh", "2x", "spin"]
end
test "#fa_solid_icon should incorporate additional class styles" do
assert_icon i("fas fa-flag pull-right"), "flag", :class => "pull-right"
assert_icon i("fas fa-flag fa-2x pull-right"), ["flag", "2x"], :class => ["pull-right"]
assert_icon i("fas fa-check fa-li pull-right special"), "check li", :class => "pull-right special"
assert_icon i("fas fa-check pull-right special"), "check", :class => ["pull-right", "special"]
end
test "#fa_solid_icon should incorporate a text suffix" do
assert_icon "#{i("fas fa-camera-retro")} Take a photo", "camera-retro", :text => "Take a photo"
end
test "#fa_solid_icon should be able to put the icon on the right" do
assert_icon "Submit #{i("fas fa-chevron-right")}", "chevron-right", :text => "Submit", :right => true
end
test "#fa_solid_icon should html escape text" do
assert_icon "#{i("fas fa-camera-retro")} <script></script>", "camera-retro", :text => ""
end
test "#fa_solid_icon should not html escape safe text" do
assert_icon "#{i("fas fa-camera-retro")} ", "camera-retro", :text => "".html_safe
end
test "#fa_solid_icon should pull it all together" do
assert_icon "#{i("fas fa-camera-retro pull-right")} Take a photo", "camera-retro", :text => "Take a photo", :class => "pull-right"
end
test "#fa_solid_icon should pass all other options through" do
assert_icon %(), "user", :data => { :id => 123 }
end
test '#fa_solid_icon does not modify options' do
icon_options = { :class => 'foo', :data => { :id => 123 }, :text => 'bar' }
assert_icon %( bar), "user", icon_options
assert_includes icon_options, :class
assert_includes icon_options, :text
assert_includes icon_options, :data
end
test "#fa_stacked_icon with no args should render a flag icon" do
expected = %(#{i("fas fa-square-o fa-stack-2x")}#{i("fas fa-flag fa-stack-1x")})
assert_stacked_icon expected
end
test "#fa_stacked_icon should render a stacked icon" do
expected = %(#{i("fas fa-square-o fa-stack-2x")}#{i("fas fa-twitter fa-stack-1x")})
assert_stacked_icon expected, "twitter", :base => "square-o"
expected = %(#{i("fas fa-square fa-stack-2x")}#{i("fas fa-terminal fa-inverse fa-stack-1x")})
assert_stacked_icon expected, ["terminal", "inverse"], :base => ["square"]
end
test "#fa_stacked_icon should incorporate additional class styles" do
expected = %(#{i("fas fa-square-o fa-stack-2x")}#{i("fas fa-twitter fa-stack-1x")})
assert_stacked_icon expected, "twitter", :base => "square-o", :class => "pull-right"
end
test "#fa_stacked_icon should reverse the stack" do
expected = %(#{i("fas fa-facebook fa-stack-1x")}#{i("fas fa-ban fa-stack-2x")})
assert_stacked_icon expected, "facebook", :base => "ban", :reverse => "true"
end
test "#fa_stacked_icon should be able to put the icon on the right" do
expected = %(Go #{i("fas fa-square-o fa-stack-2x")}#{i("fas fa-exclamation fa-stack-1x")})
assert_stacked_icon expected, "exclamation", :text => "Go", :right => true
end
test "#fa_stacked_icon should html escape text" do
expected = %(#{i("fas fa-check-empty fa-stack-2x")}#{i("fas fa-twitter fa-stack-1x")} <script>)
assert_stacked_icon expected, "twitter", :base => "check-empty", :text => "