Merge branch 'develop' of https://git.pleroma.social/pleroma/pleroma into develop
[akkoma] / test / emoji_test.exs
1 defmodule Pleroma.EmojiTest do
2 use ExUnit.Case, async: true
3 alias Pleroma.Emoji
4
5 describe "get_all/0" do
6 setup do
7 emoji_list = Emoji.get_all()
8 {:ok, emoji_list: emoji_list}
9 end
10
11 test "first emoji", %{emoji_list: emoji_list} do
12 [emoji | _others] = emoji_list
13 {code, path, tags} = emoji
14
15 assert tuple_size(emoji) == 3
16 assert is_binary(code)
17 assert is_binary(path)
18 assert is_list(tags)
19 end
20
21 test "random emoji", %{emoji_list: emoji_list} do
22 emoji = Enum.random(emoji_list)
23 {code, path, tags} = emoji
24
25 assert tuple_size(emoji) == 3
26 assert is_binary(code)
27 assert is_binary(path)
28 assert is_list(tags)
29 end
30 end
31
32 describe "match_extra/2" do
33 setup do
34 groups = [
35 "list of files": ["/emoji/custom/first_file.png", "/emoji/custom/second_file.png"],
36 "wildcard folder": "/emoji/custom/*/file.png",
37 "wildcard files": "/emoji/custom/folder/*.png",
38 "special file": "/emoji/custom/special.png"
39 ]
40
41 {:ok, groups: groups}
42 end
43
44 test "config for list of files", %{groups: groups} do
45 group =
46 groups
47 |> Emoji.match_extra("/emoji/custom/first_file.png")
48 |> to_string()
49
50 assert group == "list of files"
51 end
52
53 test "config with wildcard folder", %{groups: groups} do
54 group =
55 groups
56 |> Emoji.match_extra("/emoji/custom/some_folder/file.png")
57 |> to_string()
58
59 assert group == "wildcard folder"
60 end
61
62 test "config with wildcard folder and subfolders", %{groups: groups} do
63 group =
64 groups
65 |> Emoji.match_extra("/emoji/custom/some_folder/another_folder/file.png")
66 |> to_string()
67
68 assert group == "wildcard folder"
69 end
70
71 test "config with wildcard files", %{groups: groups} do
72 group =
73 groups
74 |> Emoji.match_extra("/emoji/custom/folder/some_file.png")
75 |> to_string()
76
77 assert group == "wildcard files"
78 end
79
80 test "config with wildcard files and subfolders", %{groups: groups} do
81 group =
82 groups
83 |> Emoji.match_extra("/emoji/custom/folder/another_folder/some_file.png")
84 |> to_string()
85
86 assert group == "wildcard files"
87 end
88
89 test "config for special file", %{groups: groups} do
90 group =
91 groups
92 |> Emoji.match_extra("/emoji/custom/special.png")
93 |> to_string()
94
95 assert group == "special file"
96 end
97
98 test "no mathing returns nil", %{groups: groups} do
99 group =
100 groups
101 |> Emoji.match_extra("/emoji/some_undefined.png")
102
103 refute group
104 end
105 end
106 end