Update fronted.
[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 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>."
11
12 assert Formatter.linkify(text) == expected
13
14 text = "https://mastodon.social/@lambadalambda"
15 expected = "<a href='https://mastodon.social/@lambadalambda'>https://mastodon.social/@lambadalambda</a>"
16
17 assert Formatter.linkify(text) == expected
18
19 text = "@lambadalambda"
20 expected = "@lambadalambda"
21
22 assert Formatter.linkify(text) == expected
23
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>"
26
27 assert Formatter.linkify(text) == expected
28 end
29 end
30
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 #は。"
34 expected = [
35 {"#Test", "test"},
36 {"#working", "working"},
37 {"#漢字", "漢字"},
38 {"#は", "は"}
39 ]
40
41 assert Formatter.parse_tags(text) == expected
42 end
43 end
44
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"
47
48 gsimg = insert(:user, %{nickname: "gsimg"})
49 archaeme = insert(:user, %{nickname: "archaeme"})
50 archaeme_remote = insert(:user, %{nickname: "archaeme@archae.me"})
51
52 expected_result = [
53 {"@gsimg", gsimg},
54 {"@archaeme", archaeme},
55 {"@archaeme@archae.me", archaeme_remote},
56 ]
57
58 assert Formatter.parse_mentions(text) == expected_result
59 end
60
61 test "it adds cool emoji" do
62 text = "I love :moominmamma:"
63
64 expected_result = "I love <img height='32px' width='32px' alt='moominmamma' title='moominmamma' src='/finmoji/128px/moominmamma-128.png' />"
65
66 assert Formatter.emojify(text) == expected_result
67 end
68
69 test "it returns the emoji used in the text" do
70 text = "I love :moominmamma:"
71
72 assert Formatter.get_emoji(text) == [{"moominmamma", "/finmoji/128px/moominmamma-128.png"}]
73 end
74 end