defmodule MusicLibraryWeb.MarkdownTest do
use ExUnit.Case, async: true
alias MusicLibraryWeb.Markdown
doctest MusicLibraryWeb.Markdown
describe "streaming" do
test "new document renders empty string" do
doc = Markdown.new_streaming_doc()
assert Markdown.streaming_to_html(doc) == ""
end
test "incremental chunks produce valid HTML" do
doc = Markdown.new_streaming_doc()
doc = MDEx.Document.put_markdown(doc, "**bold")
html = Markdown.streaming_to_html(doc)
assert html =~ "bold"
doc = MDEx.Document.put_markdown(doc, " text**")
html = Markdown.streaming_to_html(doc)
assert html =~ "bold text"
end
test "handles incomplete code fences" do
doc = Markdown.new_streaming_doc()
doc = MDEx.Document.put_markdown(doc, "```elixir\nIO.puts")
html = Markdown.streaming_to_html(doc)
assert html =~ "IO"
assert html =~ "puts"
assert html =~ "alert(1)")
html = Markdown.streaming_to_html(doc)
refute html =~ "")
refute result =~ ""
end
test "strips event handlers from tags" do
result = Markdown.to_html("
")
refute result =~ "onerror"
refute result =~ "alert"
end
test "preserves normal markdown formatting" do
result = Markdown.to_html("**bold**")
assert result =~ "bold"
end
test "preserves links" do
result = Markdown.to_html("[link](http://example.com)")
assert result =~ ""
end
end
end