9b6ee2425e939b8c466fe981b08a2c260b639aa2
[akkoma] / test / formatter_test.exs
1 defmodule Pleroma.FormatterTest do
2 alias Pleroma.Formatter
3 use Pleroma.DataCase
4
5 import Pleroma.Factory
6
7 describe ".linkify" do
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
11 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
13 assert Formatter.linkify(text) == expected
14 end
15 end
16
17 describe ".parse_tags" do
18 test "parses tags in the text" do
19 text = "Here's a #Test. Maybe these are #working or not. What about #漢字? And #は。"
20 expected = [
21 {"#Test", "test"},
22 {"#working", "working"},
23 {"#漢字", "漢字"},
24 {"#は", "は"}
25 ]
26
27 assert Formatter.parse_tags(text) == expected
28 end
29 end
30
31 test "it can parse mentions and return the relevant users" do
32 text = "@gsimg According to @archaeme, that is @daggsy. Also hello @archaeme@archae.me"
33
34 gsimg = insert(:user, %{nickname: "gsimg"})
35 archaeme = insert(:user, %{nickname: "archaeme"})
36 archaeme_remote = insert(:user, %{nickname: "archaeme@archae.me"})
37
38 expected_result = [
39 {"@gsimg", gsimg},
40 {"@archaeme", archaeme},
41 {"@archaeme@archae.me", archaeme_remote},
42 ]
43
44 assert Formatter.parse_mentions(text) == expected_result
45 end
46
47 test "it adds cool emoji" do
48 text = "I love :moominmamma:"
49
50 expected_result = "I love <img height='32px' width='32px' alt='moominmamma' title='moominmamma' src='#{Pleroma.Web.Endpoint.static_url}/finmoji/128px/moominmamma-128.png' />"
51
52 assert Formatter.finmojifiy(text) == expected_result
53 end
54 end