35625f8ff9e7ee096f581279adba913fabfdb493
[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 end