Raxol. PluginTestHelpers
(Raxol v2.6.0)
View Source
Test helpers for Raxol plugins.
Provides utilities for testing plugin lifecycle, hook registration, event handling, and configuration management.
Usage
defmodule MyPluginTest do
use ExUnit.Case
import Raxol.PluginTestHelpers
test "plugin initializes correctly" do
plugin = create_test_plugin(MyPlugin)
assert plugin.state.initialized == true
end
test "plugin handles events" do
plugin = create_test_plugin(MyPlugin)
{plugin, result} = call_hook(plugin, :on_key, %{key: :enter})
assert result == :handled
end
end
Summary
Functions
Assert that a hook was called with specific arguments.
Assert plugin state matches expected values.
Call a hook on a test plugin.
Clear the call log.
Create a test instance of a plugin.
Get plugin metadata if available.
Get the call count for a specific hook.
Assert that a hook was not called.
Simulate plugin lifecycle events.
Check if a plugin supports a specific hook.
Update plugin configuration.
Types
Functions
Assert that a hook was called with specific arguments.
Example
assert_hook_called(plugin, :on_key)
assert_hook_called(plugin, :on_key, %{key: :enter})
Assert plugin state matches expected values.
Example
assert_state(plugin, %{enabled: true, count: 5})
@spec call_hook(test_plugin(), atom(), term()) :: {test_plugin(), term()}
Call a hook on a test plugin.
Example
{plugin, result} = call_hook(plugin, :on_key, %{key: :enter})
@spec clear_call_log(test_plugin()) :: test_plugin()
Clear the call log.
Example
plugin = clear_call_log(plugin)
@spec create_test_plugin( module(), keyword() ) :: test_plugin()
Create a test instance of a plugin.
Options
:config- Plugin configuration:state- Initial state override
Example
plugin = create_test_plugin(MyPlugin, config: %{enabled: true})
Get plugin metadata if available.
Example
metadata = get_metadata(plugin)
@spec hook_call_count(map(), atom()) :: non_neg_integer()
Get the call count for a specific hook.
Example
count = hook_call_count(plugin, :on_key)
Assert that a hook was not called.
Example
refute_hook_called(plugin, :on_error)
Simulate plugin lifecycle events.
Example
plugin = simulate_lifecycle(plugin, :enable)
plugin = simulate_lifecycle(plugin, :disable)
Check if a plugin supports a specific hook.
Example
supports_hook?(plugin, :on_key)
@spec update_config(test_plugin(), map()) :: test_plugin()
Update plugin configuration.
Example
plugin = update_config(plugin, %{enabled: false})