skeleton
Some checks failed
CI / Test (push) Failing after 33s

This commit is contained in:
2026-03-25 12:42:19 +01:00
commit 647d5537ff
18 changed files with 701 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
defmodule MyPlugin.ManifestTest do
use ExUnit.Case, async: true
@manifest_path Path.join(__DIR__, "../../manifest.json") |> Path.expand()
setup_all do
content = File.read!(@manifest_path)
manifest = Jason.decode!(content)
%{manifest: manifest}
end
describe "manifest.json" do
test "is valid JSON", %{manifest: manifest} do
assert is_map(manifest)
end
test "has required fields", %{manifest: manifest} do
required = ["name", "version", "entry_module", "host_api", "provides", "requires"]
for field <- required do
assert Map.has_key?(manifest, field),
"manifest.json must contain #{inspect(field)}"
end
end
test "name matches OTP app name", %{manifest: manifest} do
assert manifest["name"] == "my_plugin"
end
test "entry_module is a valid Elixir module name", %{manifest: manifest} do
module_name = manifest["entry_module"]
assert is_binary(module_name)
assert String.starts_with?(module_name, "Elixir.") or not String.contains?(module_name, " ")
end
test "provides contains valid capability identifiers", %{manifest: manifest} do
for cap <- manifest["provides"] do
assert Regex.match?(~r/^[a-z][a-z0-9_]*(@\d+)?$/, cap),
"invalid capability identifier: #{inspect(cap)}"
end
end
test "requires contains valid capability identifiers", %{manifest: manifest} do
for cap <- manifest["requires"] do
assert Regex.match?(~r/^[a-z][a-z0-9_]*(@\d+)?$/, cap),
"invalid capability identifier: #{inspect(cap)}"
end
end
test "host_api is a string version", %{manifest: manifest} do
assert is_binary(manifest["host_api"])
end
test "entry_module matches actual plugin module", %{manifest: manifest} do
module = String.to_atom("Elixir.#{manifest["entry_module"]}")
assert Code.ensure_loaded?(module), "entry_module #{manifest["entry_module"]} must be loadable"
end
end
end

View File

@@ -0,0 +1,63 @@
defmodule MyPlugin.PluginTest do
use ExUnit.Case, async: true
describe "register/1" do
setup do
context = %{pubsub: nil, repo: nil}
%{spec: MyPlugin.Plugin.register(context)}
end
test "returns plugin name and version", %{spec: spec} do
assert spec.name == "my_plugin"
assert is_binary(spec.version)
end
test "provides is a list of capability strings", %{spec: spec} do
assert is_list(spec.provides)
for cap <- spec.provides do
assert is_binary(cap), "capability must be a string, got: #{inspect(cap)}"
end
end
test "requires is a list of capability strings", %{spec: spec} do
assert is_list(spec.requires)
for cap <- spec.requires do
assert is_binary(cap), "capability must be a string, got: #{inspect(cap)}"
end
end
test "nav items have required fields", %{spec: spec} do
assert is_list(spec.nav_items)
for item <- spec.nav_items do
assert is_binary(item.label), "nav item must have a label"
assert is_binary(item.path), "nav item must have a path"
assert is_integer(item.order), "nav item must have an integer order"
end
end
test "pages reference existing modules", %{spec: spec} do
assert is_list(spec.pages)
for page <- spec.pages do
assert is_binary(page.path), "page must have a path"
assert is_atom(page.live_view), "page must have a live_view module"
assert Code.ensure_loaded?(page.live_view), "module #{page.live_view} must be loadable"
end
end
test "children are valid child specs", %{spec: spec} do
assert is_list(spec.children)
end
test "asset lists are string lists", %{spec: spec} do
assert is_list(spec.global_js)
assert is_list(spec.global_css)
for js <- spec.global_js, do: assert(is_binary(js))
for css <- spec.global_css, do: assert(is_binary(css))
end
end
end