diff options
author | Roman Chvanikov <chvanikoff@pm.me> | 2019-06-29 00:52:50 +0300 |
---|---|---|
committer | Roman Chvanikov <chvanikoff@pm.me> | 2019-06-29 00:52:50 +0300 |
commit | 657277ffc0d3d25be4376ed629057a2d2cefb2e1 (patch) | |
tree | 3fdd4ca236669df9b2afc5bfcd0e5d6002e23666 /test/html_test.exs | |
parent | c0fa0001476a8a45878a0c75125627164497eddf (diff) | |
parent | c6668c2e7b9908e479527914ca7eb2c838aaab06 (diff) | |
download | pleroma-657277ffc0d3d25be4376ed629057a2d2cefb2e1.tar.gz |
Resolve conflicts
Diffstat (limited to 'test/html_test.exs')
-rw-r--r-- | test/html_test.exs | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/test/html_test.exs b/test/html_test.exs index 08738276e..b8906c46a 100644 --- a/test/html_test.exs +++ b/test/html_test.exs @@ -4,8 +4,12 @@ defmodule Pleroma.HTMLTest do alias Pleroma.HTML + alias Pleroma.Object + alias Pleroma.Web.CommonAPI use Pleroma.DataCase + import Pleroma.Factory + @html_sample """ <b>this is in bold</b> <p>this is a paragraph</p> @@ -160,4 +164,69 @@ defmodule Pleroma.HTMLTest do ) end end + + describe "extract_first_external_url" do + test "extracts the url" do + user = insert(:user) + + {:ok, activity} = + CommonAPI.post(user, %{ + "status" => + "I think I just found the best github repo https://github.com/komeiji-satori/Dress" + }) + + object = Object.normalize(activity) + {:ok, url} = HTML.extract_first_external_url(object, object.data["content"]) + assert url == "https://github.com/komeiji-satori/Dress" + end + + test "skips mentions" do + user = insert(:user) + other_user = insert(:user) + + {:ok, activity} = + CommonAPI.post(user, %{ + "status" => + "@#{other_user.nickname} install misskey! https://github.com/syuilo/misskey/blob/develop/docs/setup.en.md" + }) + + object = Object.normalize(activity) + {:ok, url} = HTML.extract_first_external_url(object, object.data["content"]) + + assert url == "https://github.com/syuilo/misskey/blob/develop/docs/setup.en.md" + + refute url == other_user.ap_id + end + + test "skips hashtags" do + user = insert(:user) + + {:ok, activity} = + CommonAPI.post(user, %{ + "status" => + "#cofe https://www.pixiv.net/member_illust.php?mode=medium&illust_id=72255140" + }) + + object = Object.normalize(activity) + {:ok, url} = HTML.extract_first_external_url(object, object.data["content"]) + + assert url == "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=72255140" + end + + test "skips microformats hashtags" do + user = insert(:user) + + {:ok, activity} = + CommonAPI.post(user, %{ + "status" => + "<a href=\"https://pleroma.gov/tags/cofe\" rel=\"tag\">#cofe</a> https://www.pixiv.net/member_illust.php?mode=medium&illust_id=72255140", + "content_type" => "text/html" + }) + + object = Object.normalize(activity) + {:ok, url} = HTML.extract_first_external_url(object, object.data["content"]) + + assert url == "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=72255140" + end + end end |