1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.Metadata.UtilsTest do
6 use Pleroma.DataCase, async: false
8 alias Pleroma.Web.Metadata.Utils
10 describe "scrub_html_and_truncate/1" do
11 test "it returns content text without encode HTML if summary is nil" do
17 "actor" => user.ap_id,
18 "id" => "https://pleroma.gov/objects/whatever",
20 "content" => "Pleroma's really cool!"
24 assert Utils.scrub_html_and_truncate(note) == "Pleroma's really cool!"
27 test "it returns context text without encode HTML if summary is empty" do
33 "actor" => user.ap_id,
34 "id" => "https://pleroma.gov/objects/whatever",
36 "content" => "Pleroma's really cool!"
40 assert Utils.scrub_html_and_truncate(note) == "Pleroma's really cool!"
43 test "it returns summary text without encode HTML if summary is filled" do
49 "actor" => user.ap_id,
50 "id" => "https://pleroma.gov/objects/whatever",
51 "summary" => "Public service announcement on caffeine consumption",
56 assert Utils.scrub_html_and_truncate(note) ==
57 "Public service announcement on caffeine consumption"
60 test "it does not return old content after editing" do
63 {:ok, activity} = Pleroma.Web.CommonAPI.post(user, %{status: "mew mew #def"})
65 object = Pleroma.Object.normalize(activity)
66 assert Utils.scrub_html_and_truncate(object) == "mew mew #def"
68 {:ok, update} = Pleroma.Web.CommonAPI.update(user, activity, %{status: "mew mew #abc"})
69 update = Pleroma.Activity.normalize(update)
70 object = Pleroma.Object.normalize(update)
71 assert Utils.scrub_html_and_truncate(object) == "mew mew #abc"
75 describe "scrub_html_and_truncate/3" do
76 test "it returns text without encode HTML" do
77 assert Utils.scrub_html_and_truncate("Pleroma's really cool!") == "Pleroma's really cool!"