Raxol. UI. IntegrationTest
(Raxol v2.6.0)
View Source
Integration testing utilities for Raxol applications.
Provides helpers for testing complete application flows including component interactions, state management, and event handling.
Usage
defmodule MyAppIntegrationTest do
use ExUnit.Case
import Raxol.UI.IntegrationTest
test "user can navigate menu and select option" do
app = start_test_app(MyApp)
app
|> send_key(:down)
|> send_key(:down)
|> send_key(:enter)
|> assert_screen_contains("Option 2 selected")
end
end
Summary
Functions
Assert that a specific line contains text.
Assert that the screen contains specific text.
Assert that the application state matches a pattern.
Clear the event log.
Get the event log showing all events processed.
Get the current screen content as a string.
Get a specific line from the screen.
Assert that the screen does not contain specific text.
Send a mouse click event to the application.
Send a key event to the application.
Send a sequence of keys to the application.
Send a resize event to the application.
Start an application for integration testing.
Type a string as individual key presses.
Wait for a condition to be true (useful for async operations).
Functions
@spec assert_line(map(), non_neg_integer(), String.t()) :: map()
Assert that a specific line contains text.
Example
app |> assert_line(0, "Title")
Assert that the screen contains specific text.
Example
app |> assert_screen_contains("Welcome")
Assert that the application state matches a pattern.
Example
app |> assert_state(%{selected_index: 2})
@spec clear_event_log(%{ module: module(), state: map(), buffer: term(), width: non_neg_integer(), height: non_neg_integer(), event_log: list() }) :: %{ module: module(), state: map(), buffer: term(), width: non_neg_integer(), height: non_neg_integer(), event_log: list() }
Clear the event log.
Example
app = clear_event_log(app)
Get the event log showing all events processed.
Example
events = get_event_log(app)
Get the current screen content as a string.
Example
screen = get_screen(app)
@spec get_screen_line(map(), non_neg_integer()) :: String.t()
Get a specific line from the screen.
Example
line = get_screen_line(app, 0)
Assert that the screen does not contain specific text.
Example
app |> refute_screen_contains("Error")
@spec send_click(map(), non_neg_integer(), non_neg_integer(), keyword()) :: map()
Send a mouse click event to the application.
Example
app = send_click(app, 10, 5)
app = send_click(app, 10, 5, button: :right)
@spec send_key( %{ module: module(), state: map(), buffer: term(), width: non_neg_integer(), height: non_neg_integer(), event_log: list() }, atom() | String.t(), keyword() ) :: %{ module: module(), state: map(), buffer: term(), width: non_neg_integer(), height: non_neg_integer(), event_log: list() }
Send a key event to the application.
Example
app = send_key(app, :enter)
app = send_key(app, "a")
app = send_key(app, :tab, ctrl: true)
Send a sequence of keys to the application.
Example
app = send_keys(app, [:down, :down, :enter])
app = send_keys(app, ["h", "e", "l", "l", "o"])
@spec send_resize(map(), pos_integer(), pos_integer()) :: map()
Send a resize event to the application.
Example
app = send_resize(app, 120, 40)
@spec start_test_app( module(), keyword() ) :: %{ module: module(), state: map(), buffer: term(), width: non_neg_integer(), height: non_neg_integer(), event_log: list() }
Start an application for integration testing.
Options
:width- Terminal width (default: 80):height- Terminal height (default: 24):initial_state- Override initial state
Example
app = start_test_app(MyApp, width: 120, height: 40)
Type a string as individual key presses.
Example
app = type_text(app, "Hello, World!")
Wait for a condition to be true (useful for async operations).
Example
app = wait_for(app, fn a -> a.state.loading == false end, timeout: 1000)