1 defmodule Pleroma.FormatterTest do
2 alias Pleroma.Formatter
8 test "turning urls into links" do
9 text = "Hey, check out https://www.youtube.com/watch?v=8Zg1-TufF%20zY?x=1&y=2#blabla."
10 expected = "Hey, check out <a href='https://www.youtube.com/watch?v=8Zg1-TufF%20zY?x=1&y=2#blabla'>https://www.youtube.com/watch?v=8Zg1-TufF%20zY?x=1&y=2#blabla</a>."
12 assert Formatter.linkify(text) == expected
14 text = "https://mastodon.social/@lambadalambda"
15 expected = "<a href='https://mastodon.social/@lambadalambda'>https://mastodon.social/@lambadalambda</a>"
17 assert Formatter.linkify(text) == expected
19 text = "@lambadalambda"
20 expected = "@lambadalambda"
22 assert Formatter.linkify(text) == expected
24 text = "http://www.cs.vu.nl/~ast/intel/"
25 expected = "<a href='http://www.cs.vu.nl/~ast/intel/'>http://www.cs.vu.nl/~ast/intel/</a>"
27 assert Formatter.linkify(text) == expected
31 describe ".parse_tags" do
32 test "parses tags in the text" do
33 text = "Here's a #Test. Maybe these are #working or not. What about #漢字? And #は。"
36 {"#working", "working"},
41 assert Formatter.parse_tags(text) == expected
45 test "it can parse mentions and return the relevant users" do
46 text = "@gsimg According to @archaeme, that is @daggsy. Also hello @archaeme@archae.me"
48 gsimg = insert(:user, %{nickname: "gsimg"})
49 archaeme = insert(:user, %{nickname: "archaeme"})
50 archaeme_remote = insert(:user, %{nickname: "archaeme@archae.me"})
54 {"@archaeme", archaeme},
55 {"@archaeme@archae.me", archaeme_remote},
58 assert Formatter.parse_mentions(text) == expected_result
61 test "it adds cool emoji" do
62 text = "I love :moominmamma:"
64 expected_result = "I love <img height='32px' width='32px' alt='moominmamma' title='moominmamma' src='/finmoji/128px/moominmamma-128.png' />"
66 assert Formatter.emojify(text) == expected_result
69 test "it returns the emoji used in the text" do
70 text = "I love :moominmamma:"
72 assert Formatter.get_emoji(text) == [{"moominmamma", "/finmoji/128px/moominmamma-128.png"}]