From 590a10af332650a8a1eb61db7db7457dc63f229a Mon Sep 17 00:00:00 2001 From: Mary Kate Date: Thu, 24 Dec 2020 16:40:08 -0600 Subject: [PATCH] Adds tests for breaking tag and mention links after text is converted from markdown to html --- test/pleroma/formatter_test.exs | 78 +++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/test/pleroma/formatter_test.exs b/test/pleroma/formatter_test.exs index 5781a3f01..f47331bc3 100644 --- a/test/pleroma/formatter_test.exs +++ b/test/pleroma/formatter_test.exs @@ -284,6 +284,34 @@ test "it correctly parses angry face D:< with mention" do assert {^expected_text, ^expected_mentions, []} = Formatter.linkify(text) end + + test "correctly parses mentions in html" do + text = "

@lain hello

" + lain = insert(:user, %{nickname: "lain"}) + + {text, mentions, []} = Formatter.linkify(text) + + assert length(mentions) == 1 + + expected_text = + ~s(

@lain hello

) + + assert expected_text == text + end + + test "correctly parses mentions on the last line of html" do + text = "

Hello

@lain

" + lain = insert(:user, %{nickname: "lain"}) + + {text, mentions, []} = Formatter.linkify(text) + + assert length(mentions) == 1 + + expected_text = + ~s(

Hello

@lain

) + + assert expected_text == text + end end describe ".parse_tags" do @@ -299,6 +327,56 @@ test "parses tags in the text" do assert {_text, [], ^expected_tags} = Formatter.linkify(text) end + + test "parses tags in html" do + text = "

This is a #test

" + + expected_tags = [ + {"#test", "test"}, + ] + + assert {_text, [], ^expected_tags} = Formatter.linkify(text) + end + + test "parses mulitple tags in html" do + text = "

#tag1 #tag2 #tag3 #tag4

" + + expected_tags = [ + {"#tag1", "tag1"}, + {"#tag2", "tag2"}, + {"#tag3", "tag3"}, + {"#tag4", "tag4"}, + ] + + assert {_text, [], ^expected_tags} = Formatter.linkify(text) + end + + test "parses tags on the last line of html" do + text = "

This is a

#test

" + + expected_tags = [ + {"#test", "test"}, + ] + + assert {_text, [], ^expected_tags} = Formatter.linkify(text) + end + + test "parses mulitple tags on mulitple lines in html" do + text = "

testing...

#tag1 #tag2 #tag3 #tag4

paragraph

#tag5 #tag6 #tag7 #tag8

" + + expected_tags = [ + {"#tag1", "tag1"}, + {"#tag2", "tag2"}, + {"#tag3", "tag3"}, + {"#tag4", "tag4"}, + {"#tag5", "tag5"}, + {"#tag6", "tag6"}, + {"#tag7", "tag7"}, + {"#tag8", "tag8"}, + ] + + assert {_text, [], ^expected_tags} = Formatter.linkify(text) + end end test "it escapes HTML in plain text" do