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

assert_line(app, line_number, expected_text)

@spec assert_line(map(), non_neg_integer(), String.t()) :: map()

Assert that a specific line contains text.

Example

app |> assert_line(0, "Title")

assert_screen_contains(app, expected_text)

@spec assert_screen_contains(map(), String.t()) :: map()

Assert that the screen contains specific text.

Example

app |> assert_screen_contains("Welcome")

assert_state(app, expected_state)

@spec assert_state(map(), map() | keyword()) :: map()

Assert that the application state matches a pattern.

Example

app |> assert_state(%{selected_index: 2})

clear_event_log(app)

@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_event_log(app)

@spec get_event_log(map()) :: list()

Get the event log showing all events processed.

Example

events = get_event_log(app)

get_screen(app)

@spec get_screen(map()) :: String.t()

Get the current screen content as a string.

Example

screen = get_screen(app)

get_screen_line(app, line_number)

@spec get_screen_line(map(), non_neg_integer()) :: String.t()

Get a specific line from the screen.

Example

line = get_screen_line(app, 0)

refute_screen_contains(app, unexpected_text)

@spec refute_screen_contains(map(), String.t()) :: map()

Assert that the screen does not contain specific text.

Example

app |> refute_screen_contains("Error")

send_click(app, x, y, opts \\ [])

@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)

send_key(app, key, modifiers \\ [])

@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_keys(app, keys)

@spec send_keys(map(), list()) :: map()

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"])

send_resize(app, width, height)

@spec send_resize(map(), pos_integer(), pos_integer()) :: map()

Send a resize event to the application.

Example

app = send_resize(app, 120, 40)

start_test_app(app_module, opts \\ [])

@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_text(app, text)

@spec type_text(map(), String.t()) :: map()

Type a string as individual key presses.

Example

app = type_text(app, "Hello, World!")

wait_for(app, condition_fn, opts \\ [])

@spec wait_for(map(), (map() -> boolean()), keyword()) :: map()

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)