summaryrefslogtreecommitdiff
path: root/test/pleroma/emoji/loader_test.exs
blob: 717424fc8673487f6a8811ca6e544ac68ca18d68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Pleroma: A lightweight social networking server
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only

defmodule Pleroma.Emoji.LoaderTest do
  use ExUnit.Case, async: true
  alias Pleroma.Emoji.Loader

  describe "match_extra/2" do
    setup do
      groups = [
        "list of files": ["/emoji/custom/first_file.png", "/emoji/custom/second_file.png"],
        "wildcard folder": "/emoji/custom/*/file.png",
        "wildcard files": "/emoji/custom/folder/*.png",
        "special file": "/emoji/custom/special.png"
      ]

      {:ok, groups: groups}
    end

    test "config for list of files", %{groups: groups} do
      group =
        groups
        |> Loader.match_extra("/emoji/custom/first_file.png")
        |> to_string()

      assert group == "list of files"
    end

    test "config with wildcard folder", %{groups: groups} do
      group =
        groups
        |> Loader.match_extra("/emoji/custom/some_folder/file.png")
        |> to_string()

      assert group == "wildcard folder"
    end

    test "config with wildcard folder and subfolders", %{groups: groups} do
      group =
        groups
        |> Loader.match_extra("/emoji/custom/some_folder/another_folder/file.png")
        |> to_string()

      assert group == "wildcard folder"
    end

    test "config with wildcard files", %{groups: groups} do
      group =
        groups
        |> Loader.match_extra("/emoji/custom/folder/some_file.png")
        |> to_string()

      assert group == "wildcard files"
    end

    test "config with wildcard files and subfolders", %{groups: groups} do
      group =
        groups
        |> Loader.match_extra("/emoji/custom/folder/another_folder/some_file.png")
        |> to_string()

      assert group == "wildcard files"
    end

    test "config for special file", %{groups: groups} do
      group =
        groups
        |> Loader.match_extra("/emoji/custom/special.png")
        |> to_string()

      assert group == "special file"
    end

    test "no mathing returns nil", %{groups: groups} do
      group =
        groups
        |> Loader.match_extra("/emoji/some_undefined.png")

      refute group
    end
  end
end