Add test fixtures.
[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
29 text = "https://forum.zdoom.org/viewtopic.php?f=44&t=57087"
30 expected = "<a href='https://forum.zdoom.org/viewtopic.php?f=44&t=57087'>https://forum.zdoom.org/viewtopic.php?f=44&t=57087</a>"
31
32 assert Formatter.linkify(text) == expected
33
34 text = "https://en.wikipedia.org/wiki/Sophia_(Gnosticism)#Mythos_of_the_soul"
35 expected = "<a href='https://en.wikipedia.org/wiki/Sophia_(Gnosticism)#Mythos_of_the_soul'>https://en.wikipedia.org/wiki/Sophia_(Gnosticism)#Mythos_of_the_soul</a>"
36
37 assert Formatter.linkify(text) == expected
38 end
39 end
40
41 describe ".parse_tags" do
42 test "parses tags in the text" do
43 text = "Here's a #Test. Maybe these are #working or not. What about #漢字? And #は。"
44 expected = [
45 {"#Test", "test"},
46 {"#working", "working"},
47 {"#漢字", "漢字"},
48 {"#は", "は"}
49 ]
50
51 assert Formatter.parse_tags(text) == expected
52 end
53 end
54
55 test "it can parse mentions and return the relevant users" do
56 text = "@gsimg According to @archaeme, that is @daggsy. Also hello @archaeme@archae.me"
57
58 gsimg = insert(:user, %{nickname: "gsimg"})
59 archaeme = insert(:user, %{nickname: "archaeme"})
60 archaeme_remote = insert(:user, %{nickname: "archaeme@archae.me"})
61
62 expected_result = [
63 {"@gsimg", gsimg},
64 {"@archaeme", archaeme},
65 {"@archaeme@archae.me", archaeme_remote},
66 ]
67
68 assert Formatter.parse_mentions(text) == expected_result
69 end
70
71 test "it adds cool emoji" do
72 text = "I love :moominmamma:"
73
74 expected_result = "I love <img height='32px' width='32px' alt='moominmamma' title='moominmamma' src='/finmoji/128px/moominmamma-128.png' />"
75
76 assert Formatter.emojify(text) == expected_result
77 end
78
79 test "it returns the emoji used in the text" do
80 text = "I love :moominmamma:"
81
82 assert Formatter.get_emoji(text) == [{"moominmamma", "/finmoji/128px/moominmamma-128.png"}]
83 end
84 end