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."
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>."
13 assert Formatter.linkify(text) == expected
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 #は。"
22 {"#working", "working"},
27 assert Formatter.parse_tags(text) == expected
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"
34 gsimg = insert(:user, %{nickname: "gsimg"})
35 archaeme = insert(:user, %{nickname: "archaeme"})
36 archaeme_remote = insert(:user, %{nickname: "archaeme@archae.me"})
40 {"@archaeme", archaeme},
41 {"@archaeme@archae.me", archaeme_remote},
44 assert Formatter.parse_mentions(text) == expected_result
47 test "it adds cool emoji" do
48 text = "I love :moominmamma:"
50 expected_result = "I love <img height='32px' width='32px' alt='moominmamma' title='moominmamma' src='/finmoji/128px/moominmamma-128.png' />"
52 assert Formatter.emojify(text) == expected_result
55 test "it returns the emoji used in the text" do
56 text = "I love :moominmamma:"
58 assert Formatter.get_emoji(text) == [{"moominmamma", "/finmoji/128px/moominmamma-128.png"}]