From 04b5f19a1411b1e54ed67129a528b4c7b569e694 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Fri, 11 Jun 2021 16:04:06 -0500 Subject: [PATCH] More tests for filter_html_and_truncate/1 --- test/pleroma/web/metadata/utils_test.exs | 36 ++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/test/pleroma/web/metadata/utils_test.exs b/test/pleroma/web/metadata/utils_test.exs index 9d94bf9ca..1fe211d2f 100644 --- a/test/pleroma/web/metadata/utils_test.exs +++ b/test/pleroma/web/metadata/utils_test.exs @@ -8,7 +8,7 @@ defmodule Pleroma.Web.Metadata.UtilsTest do alias Pleroma.Web.Metadata.Utils describe "filter_html_and_truncate/1" do - test "it returns text without HTML" do + test "it returns text without encoded HTML entities" do user = insert(:user) note = @@ -38,10 +38,42 @@ defmodule Pleroma.Web.Metadata.UtilsTest do assert Utils.filter_html_and_truncate(note) == "First line Second line" end + + test "it strips emojis" do + user = insert(:user) + + note = + insert(:note, %{ + data: %{ + "actor" => user.ap_id, + "id" => "https://pleroma.gov/objects/whatever", + "content" => "Mozilla Firefox :firefox:" + } + }) + + assert Utils.filter_html_and_truncate(note) == + "Mozilla Firefox" + end + + test "it strips HTML tags and other entities" do + user = insert(:user) + + note = + insert(:note, %{ + data: %{ + "actor" => user.ap_id, + "id" => "https://pleroma.gov/objects/whatever", + "content" => "my title

and a paragraph!

" + } + }) + + assert Utils.filter_html_and_truncate(note) == + "my title and a paragraph!" + end end describe "scrub_html_and_truncate/2" do - test "it returns text without encode HTML" do + test "it returns text without encoded HTML entities" do assert Utils.scrub_html_and_truncate("Pleroma's really cool!") == "Pleroma's really cool!" end