require "test_helper" require "govspeak_test_helper" class GovspeakImagesTest < Minitest::Test include GovspeakTestHelper test "Image:image-id syntax renders an image in options[:images]" do given_govspeak "[Image:image-id]", images: [build_image] do assert_html_output( "", ) end end test "Image:image-id syntax escapes alt text" do given_govspeak "[Image:image-id]", images: [build_image(alt_text: %(my alt '&"<>))] do assert_html_output( "", ) end end test "Image:image-id syntax renders nothing if not found" do doc = Govspeak::Document.new("[Image:another-id]") assert_equal %(\n), doc.to_html end test "Image:image-id syntax adds image caption if given" do given_govspeak "[Image:image-id]", images: [build_image(caption: "My Caption & so on")] do assert_html_output( "", ) end end test "Image:image-id syntax ignores a blank caption" do given_govspeak "[Image:image-id]", images: [build_image(caption: " ")] do assert_html_output( "", ) end end test "Image:image-id syntax adds image credit if given" do given_govspeak "[Image:image-id]", images: [build_image(credit: "My Credit & so on")] do assert_html_output( "", ) end end test "Image:image-id syntax ignores a blank credit" do given_govspeak "[Image:image-id]", images: [build_image(credit: " ")] do assert_html_output( "", ) end end test "Image:image-id syntax adds image caption and credit if given" do given_govspeak "[Image:image-id]", images: [build_image(caption: "My Caption & so on", credit: "My Credit & so on")] do assert_html_output( "", ) end end test "allows spaces and special characters in the identifier" do image = build_image(id: "This is the name of my &%$@€? image") given_govspeak "[Image: This is the name of my &%$@€? image]", images: [image] do assert_html_output( "", ) end end test "Image is not inserted when it does not start on a new line" do given_govspeak "some text [Image:image-id]", images: [build_image] do assert_html_output("
some text [Image:image-id]
") end given_govspeak "[Image:image-id]", images: [build_image] do assert_html_output( "", ) end given_govspeak "[Image:image-id] some text", images: [build_image] do assert_html_output( "\nsome text
", ) end given_govspeak "some text\n[Image:image-id]\nsome more text", images: [build_image] do assert_html_output <<~HTMLsome text
some more text
HTML end end end