1 defmodule Pleroma.Docs.GeneratorTest do
2 use ExUnit.Case, async: true
3 alias Pleroma.Docs.Generator
17 Generator.list_modules_in_dir(
18 "lib/pleroma/upload/filter",
19 "Elixir.Pleroma.Upload.Filter."
24 type: {:list, :module},
27 Generator.list_modules_in_dir(
28 "lib/pleroma/web/activity_pub/mrf",
29 "Elixir.Pleroma.Web.ActivityPub.MRF."
51 key: :another_key_with_label,
52 label: "Another label",
66 {:tuple, "string", 8080},
67 [:atom, Pleroma.Upload, {:atom, Pleroma.Upload}]
72 label: "Special Label",
78 group: {:subgroup, Swoosh.Adapters.SMTP},
81 description: "`Swoosh.Adapters.SMTP` adapter specific setting",
82 suggestions: [:always, :never, :if_available]
85 key: "application/xml",
86 type: {:list, :string},
100 children: [%{key: :key1, type: :string, suggestions: [""]}]
102 %{group: "Some string group", key: "Some string key", type: :group}
105 describe "convert_to_strings/1" do
106 test "group, key, label" do
107 [desc1, desc2 | _] = Generator.convert_to_strings(@descriptions)
109 assert desc1[:group] == ":pleroma"
110 assert desc1[:key] == "Pleroma.Upload"
111 assert desc1[:label] == "Pleroma.Upload"
113 assert desc2[:group] == ":tesla"
114 assert desc2[:key] == ":adapter"
115 assert desc2[:label] == "Adapter"
118 test "group without key" do
119 descriptions = Generator.convert_to_strings(@descriptions)
120 desc = Enum.at(descriptions, 2)
122 assert desc[:group] == ":cors_plug"
124 assert desc[:label] == "Cors plug"
127 test "children key, label, type" do
128 [%{children: [child1, child2, child3, child4 | _]} | _] =
129 Generator.convert_to_strings(@descriptions)
131 assert child1[:key] == ":uploader"
132 assert child1[:label] == "Uploader"
133 assert child1[:type] == :module
135 assert child2[:key] == ":filters"
136 assert child2[:label] == "Filters"
137 assert child2[:type] == {:list, :module}
139 assert child3[:key] == "Pleroma.Upload"
140 assert child3[:label] == "Pleroma.Upload"
141 assert child3[:type] == :string
143 assert child4[:key] == ":some_key"
144 assert child4[:label] == "Some key"
145 assert child4[:type] == :keyword
148 test "child with predefined label" do
149 [%{children: children} | _] = Generator.convert_to_strings(@descriptions)
150 child = Enum.at(children, 5)
151 assert child[:key] == "Pleroma.Upload"
152 assert child[:label] == "Special Label"
156 [%{children: children} | _] = Generator.convert_to_strings(@descriptions)
157 child = Enum.at(children, 3)
158 %{children: [subchild | _]} = child
160 assert subchild[:key] == ":another_key"
161 assert subchild[:label] == "Another key"
162 assert subchild[:type] == :integer
165 test "subchild with predefined label" do
166 [%{children: children} | _] = Generator.convert_to_strings(@descriptions)
167 child = Enum.at(children, 3)
168 %{children: subchildren} = child
169 subchild = Enum.at(subchildren, 1)
171 assert subchild[:key] == ":another_key_with_label"
172 assert subchild[:label] == "Another label"
175 test "module suggestions" do
176 [%{children: [%{suggestions: suggestions} | _]} | _] =
177 Generator.convert_to_strings(@descriptions)
179 Enum.each(suggestions, fn suggestion ->
180 assert String.starts_with?(suggestion, "Pleroma.")
184 test "atoms in suggestions with leading `:`" do
185 [%{children: children} | _] = Generator.convert_to_strings(@descriptions)
186 %{suggestions: suggestions} = Enum.at(children, 4)
187 assert Enum.at(suggestions, 0) == ":atom"
188 assert Enum.at(suggestions, 1) == "Pleroma.Upload"
189 assert Enum.at(suggestions, 2) == {":tuple", "string", 8080}
190 assert Enum.at(suggestions, 3) == [":atom", "Pleroma.Upload", {":atom", "Pleroma.Upload"}]
192 %{suggestions: suggestions} = Enum.at(children, 6)
193 assert Enum.at(suggestions, 0) == ":always"
194 assert Enum.at(suggestions, 1) == ":never"
195 assert Enum.at(suggestions, 2) == ":if_available"
198 test "group, key as string in main desc" do
199 descriptions = Generator.convert_to_strings(@descriptions)
200 desc = Enum.at(descriptions, 3)
201 assert desc[:group] == "Some string group"
202 assert desc[:key] == "Some string key"
205 test "key as string subchild" do
206 [%{children: children} | _] = Generator.convert_to_strings(@descriptions)
207 child = Enum.at(children, 7)
208 assert child[:key] == "application/xml"