467357291afcaf744f11a028b1d4c97e93907e3b
[akkoma] / test / emoji_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.EmojiTest do
6 use ExUnit.Case, async: true
7 alias Pleroma.Emoji
8
9 describe "is_unicode_emoji?/1" do
10 test "tells if a string is an unicode emoji" do
11 refute Emoji.is_unicode_emoji?("X")
12 assert Emoji.is_unicode_emoji?("☂")
13 assert Emoji.is_unicode_emoji?("🥺")
14 end
15 end
16
17 describe "get_all/0" do
18 setup do
19 emoji_list = Emoji.get_all()
20 {:ok, emoji_list: emoji_list}
21 end
22
23 test "first emoji", %{emoji_list: emoji_list} do
24 [emoji | _others] = emoji_list
25 {code, path, tags} = emoji
26
27 assert tuple_size(emoji) == 3
28 assert is_binary(code)
29 assert is_binary(path)
30 assert is_list(tags)
31 end
32
33 test "random emoji", %{emoji_list: emoji_list} do
34 emoji = Enum.random(emoji_list)
35 {code, path, tags} = emoji
36
37 assert tuple_size(emoji) == 3
38 assert is_binary(code)
39 assert is_binary(path)
40 assert is_list(tags)
41 end
42 end
43
44 describe "match_extra/2" do
45 setup do
46 groups = [
47 "list of files": ["/emoji/custom/first_file.png", "/emoji/custom/second_file.png"],
48 "wildcard folder": "/emoji/custom/*/file.png",
49 "wildcard files": "/emoji/custom/folder/*.png",
50 "special file": "/emoji/custom/special.png"
51 ]
52
53 {:ok, groups: groups}
54 end
55
56 test "config for list of files", %{groups: groups} do
57 group =
58 groups
59 |> Emoji.match_extra("/emoji/custom/first_file.png")
60 |> to_string()
61
62 assert group == "list of files"
63 end
64
65 test "config with wildcard folder", %{groups: groups} do
66 group =
67 groups
68 |> Emoji.match_extra("/emoji/custom/some_folder/file.png")
69 |> to_string()
70
71 assert group == "wildcard folder"
72 end
73
74 test "config with wildcard folder and subfolders", %{groups: groups} do
75 group =
76 groups
77 |> Emoji.match_extra("/emoji/custom/some_folder/another_folder/file.png")
78 |> to_string()
79
80 assert group == "wildcard folder"
81 end
82
83 test "config with wildcard files", %{groups: groups} do
84 group =
85 groups
86 |> Emoji.match_extra("/emoji/custom/folder/some_file.png")
87 |> to_string()
88
89 assert group == "wildcard files"
90 end
91
92 test "config with wildcard files and subfolders", %{groups: groups} do
93 group =
94 groups
95 |> Emoji.match_extra("/emoji/custom/folder/another_folder/some_file.png")
96 |> to_string()
97
98 assert group == "wildcard files"
99 end
100
101 test "config for special file", %{groups: groups} do
102 group =
103 groups
104 |> Emoji.match_extra("/emoji/custom/special.png")
105 |> to_string()
106
107 assert group == "special file"
108 end
109
110 test "no mathing returns nil", %{groups: groups} do
111 group =
112 groups
113 |> Emoji.match_extra("/emoji/some_undefined.png")
114
115 refute group
116 end
117 end
118 end