summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlex Gleason <alex@alexgleason.me>2022-01-15 19:13:56 +0000
committerAlex Gleason <alex@alexgleason.me>2022-01-15 19:13:56 +0000
commitecdc81b37a93903fd37bf3185f80c47a2da4f0d1 (patch)
tree05238c61ce0595634078139a9a49b5bfee7bfbbc /test
parent71baa713bc0ea3305ea69732a6f99a0e5537af3d (diff)
parent39c5ebb1f634b691d06d607d91cbfc6b0741d541 (diff)
downloadpleroma-ecdc81b37a93903fd37bf3185f80c47a2da4f0d1.tar.gz
pleroma-ecdc81b37a93903fd37bf3185f80c47a2da4f0d1.zip
Merge branch 'linkify-0.5.2' into 'develop'
Upgrade Linkify to v0.5.2 Closes #2376, #2386, and #2485 See merge request pleroma/pleroma!3605
Diffstat (limited to 'test')
-rw-r--r--test/pleroma/formatter_test.exs79
1 files changed, 79 insertions, 0 deletions
diff --git a/test/pleroma/formatter_test.exs b/test/pleroma/formatter_test.exs
index b0f9f41b1..6663fdbc6 100644
--- a/test/pleroma/formatter_test.exs
+++ b/test/pleroma/formatter_test.exs
@@ -270,6 +270,34 @@ defmodule Pleroma.FormatterTest do
assert {^expected_text, ^expected_mentions, []} = Formatter.linkify(text)
end
+
+ test "correctly parses mentions in html" do
+ text = "<p>@lain hello</p>"
+ lain = insert(:user, %{nickname: "lain"})
+
+ {text, mentions, []} = Formatter.linkify(text)
+
+ assert length(mentions) == 1
+
+ expected_text =
+ ~s(<p><span class="h-card"><a class="u-url mention" data-user="#{lain.id}" href="#{lain.ap_id}" rel="ugc">@<span>lain</span></a></span> hello</p>)
+
+ assert expected_text == text
+ end
+
+ test "correctly parses mentions on the last line of html" do
+ text = "<p>Hello</p><p>@lain</p>"
+ lain = insert(:user, %{nickname: "lain"})
+
+ {text, mentions, []} = Formatter.linkify(text)
+
+ assert length(mentions) == 1
+
+ expected_text =
+ ~s(<p>Hello</p><p><span class="h-card"><a class="u-url mention" data-user="#{lain.id}" href="#{lain.ap_id}" rel="ugc">@<span>lain</span></a></span></p>)
+
+ assert expected_text == text
+ end
end
describe ".parse_tags" do
@@ -285,6 +313,57 @@ defmodule Pleroma.FormatterTest do
assert {_text, [], ^expected_tags} = Formatter.linkify(text)
end
+
+ test "parses tags in html" do
+ text = "<p>This is a #test</p>"
+
+ expected_tags = [
+ {"#test", "test"}
+ ]
+
+ assert {_text, [], ^expected_tags} = Formatter.linkify(text)
+ end
+
+ test "parses mulitple tags in html" do
+ text = "<p>#tag1 #tag2 #tag3 #tag4</p>"
+
+ 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 = "<p>This is a</p><p>#test</p>"
+
+ expected_tags = [
+ {"#test", "test"}
+ ]
+
+ assert {_text, [], ^expected_tags} = Formatter.linkify(text)
+ end
+
+ test "parses mulitple tags on mulitple lines in html" do
+ text =
+ "<p>testing...</p><p>#tag1 #tag2 #tag3 #tag4</p><p>paragraph</p><p>#tag5 #tag6 #tag7 #tag8</p>"
+
+ 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