GPUI.Test (gpui v0.2.0-rc.1)

Copy Markdown View Source

ExUnit helpers for renderer-independent application tests and deterministic GPUI interaction tests.

Ordinary tests use a lightweight GPUI.Test.Display:

use GPUI.Test, async: true

Tests that exercise real operating-system windows opt in to an owned desktop session:

use GPUI.Test, desktop: true

Deterministic tests that need GPUI layout, focus, hit testing, or keyboard dispatch opt in to a supervised native UI:

use GPUI.Test, native: [size: {640, 480}]

Native UI cases are skipped by ordinary ExUnit runs. Use the dedicated deterministic native-test Mix task so the package is compiled for the native_test target.

Both modes import one concise helper vocabulary; the first argument identifies whether an interaction targets a runtime or an interactive UI.

defmodule FocusTimerTest do
  use GPUI.Test, async: true

  test "advances from an OTP message" do
    runtime = start_runtime!(FocusTimerApp, args: %{seconds: 2})

    click(runtime, "start")
    send_view(runtime, :tick)
    assert %{remaining: 1, status: :running} = assigns(runtime)
  end
end

Events are dispatched through GPUI.Test.Display, so the same GPUI.Runtime polling boundary used by a real display is exercised without loading GPUI or requiring desktop libraries.

Summary

Functions

Advances GPUI's deterministic clock by the given milliseconds.

Returns root-view assigns for a selected window.

Returns the rendered bounds for a stable element ID.

Dispatches a change event and returns the updated snapshot.

Clicks a stable element ID or logical point in an interactive deterministic UI.

Dispatches a click event and returns the updated snapshot.

Dispatches an application command and returns the updated snapshot.

Acknowledges deterministic copying of a selected code-viewer line.

Dispatches a normalized display event and returns handled events plus the new snapshot.

Cancels a deterministic display-side button file read.

Selects deterministic file bytes for a display-side button file read.

Moves native keyboard focus to a stable element ID.

Presses a semantic key in an interactive deterministic UI.

Delivers a deterministic source-backed virtual-list range request.

Dispatches a slider release event and returns the updated snapshot.

Renders a view directly with map or keyword assigns.

Renders a view into an interactive deterministic native UI.

Resizes the deterministic native viewport.

Scrolls a stable target by a bounded logical-pixel delta.

Dispatches a combobox search event and returns the updated snapshot.

Selects a controlled form value and returns the updated snapshot.

Delivers an OTP message to a root view and returns the updated snapshot.

Runs native UI work until GPUI is parked.

Returns a runtime snapshot, or passes an existing snapshot through.

Starts a supervised runtime backed by GPUI.Test.Display.

Dispatches an input submission with its current string value.

Dispatches a deterministic data-table cell selection.

Dispatches a deterministic sortable data-table header selection.

Returns the rendered tree for a selected window.

Types text into the focused native input.

Returns a window snapshot from a runtime or full snapshot.

Functions

advance(ui, milliseconds)

@spec advance(GPUI.Test.UI.t(), non_neg_integer()) :: GPUI.Test.UI.t()

Advances GPUI's deterministic clock by the given milliseconds.

assigns(source, selector \\ :first)

@spec assigns(
  GenServer.server() | GPUI.Snapshot.t(),
  :first | pos_integer() | String.t()
) :: map()

Returns root-view assigns for a selected window.

bounds(ui, target)

@spec bounds(GPUI.Test.UI.t(), String.t()) :: map()

Returns the rendered bounds for a stable element ID.

change(runtime, event, value, opts \\ [])

@spec change(GenServer.server(), String.t(), term(), keyword()) :: GPUI.Snapshot.t()

Dispatches a change event and returns the updated snapshot.

click(ui, target)

@spec click(GPUI.Test.UI.t(), String.t() | {number(), number()}) :: GPUI.Test.UI.t()

Clicks a stable element ID or logical point in an interactive deterministic UI.

click(runtime, event, opts \\ [])

@spec click(GenServer.server(), String.t(), keyword()) :: GPUI.Snapshot.t()

Dispatches a click event and returns the updated snapshot.

command(runtime, event, opts \\ [])

@spec command(GenServer.server(), String.t(), keyword()) :: GPUI.Snapshot.t()

Dispatches an application command and returns the updated snapshot.

copy_selected_line(runtime, event, opts \\ [])

@spec copy_selected_line(GenServer.server(), String.t(), keyword()) ::
  GPUI.Snapshot.t()

Acknowledges deterministic copying of a selected code-viewer line.

dispatch(runtime, event)

@spec dispatch(GenServer.server(), GPUI.Event.t() | map() | keyword()) ::
  {[map()], GPUI.Snapshot.t()}

Dispatches a normalized display event and returns handled events plus the new snapshot.

file_cancel(runtime, event, opts \\ [])

@spec file_cancel(GenServer.server(), String.t(), keyword()) :: GPUI.Snapshot.t()

Cancels a deterministic display-side button file read.

file_select(runtime, event, name, data, opts \\ [])

@spec file_select(GenServer.server(), String.t(), String.t(), binary(), keyword()) ::
  GPUI.Snapshot.t()

Selects deterministic file bytes for a display-side button file read.

focus(ui, target)

@spec focus(GPUI.Test.UI.t(), String.t()) :: GPUI.Test.UI.t()

Moves native keyboard focus to a stable element ID.

press(ui, key)

@spec press(GPUI.Test.UI.t(), atom() | String.t()) :: GPUI.Test.UI.t()

Presses a semantic key in an interactive deterministic UI.

range(runtime, event, first, last, opts \\ [])

Delivers a deterministic source-backed virtual-list range request.

release(runtime, event, value, opts \\ [])

@spec release(GenServer.server(), String.t(), number(), keyword()) ::
  GPUI.Snapshot.t()

Dispatches a slider release event and returns the updated snapshot.

render(view, assigns \\ %{})

@spec render(module(), map() | keyword()) :: GPUI.Element.t()

Renders a view directly with map or keyword assigns.

render(ui, view, assigns)

@spec render(GPUI.Test.UI.t(), module(), map() | keyword()) :: GPUI.Test.UI.t()

Renders a view into an interactive deterministic native UI.

resize(ui, size)

@spec resize(
  GPUI.Test.UI.t(),
  {number(), number()}
) :: GPUI.Test.UI.t()

Resizes the deterministic native viewport.

scroll(ui, target, opts)

@spec scroll(GPUI.Test.UI.t(), String.t(), keyword()) :: GPUI.Test.UI.t()

Scrolls a stable target by a bounded logical-pixel delta.

search(runtime, event, query, opts \\ [])

@spec search(GenServer.server(), String.t(), String.t(), keyword()) ::
  GPUI.Snapshot.t()

Dispatches a combobox search event and returns the updated snapshot.

select(runtime, event, value, opts \\ [])

@spec select(GenServer.server(), String.t(), String.t() | nil, keyword()) ::
  GPUI.Snapshot.t()

Selects a controlled form value and returns the updated snapshot.

send_view(runtime, message, opts \\ [])

@spec send_view(GenServer.server(), term(), keyword()) :: GPUI.Snapshot.t()

Delivers an OTP message to a root view and returns the updated snapshot.

settle(ui)

@spec settle(GPUI.Test.UI.t()) :: GPUI.Test.UI.t()

Runs native UI work until GPUI is parked.

snapshot(snapshot)

@spec snapshot(GenServer.server() | GPUI.Snapshot.t()) :: GPUI.Snapshot.t()

Returns a runtime snapshot, or passes an existing snapshot through.

start_runtime!(app, opts \\ [])

@spec start_runtime!(
  module(),
  keyword()
) :: pid()

Starts a supervised runtime backed by GPUI.Test.Display.

submit(runtime, event, value, opts \\ [])

@spec submit(GenServer.server(), String.t(), String.t(), keyword()) ::
  GPUI.Snapshot.t()

Dispatches an input submission with its current string value.

table_cell_select(runtime, event, row_id, column_id, opts \\ [])

@spec table_cell_select(
  GenServer.server(),
  String.t(),
  String.t(),
  String.t(),
  keyword()
) :: GPUI.Snapshot.t()

Dispatches a deterministic data-table cell selection.

table_sort(runtime, event, column_id, opts \\ [])

@spec table_sort(GenServer.server(), String.t(), String.t(), keyword()) ::
  GPUI.Snapshot.t()

Dispatches a deterministic sortable data-table header selection.

tree(source, selector \\ :first)

@spec tree(
  GenServer.server() | GPUI.Snapshot.t(),
  :first | pos_integer() | String.t()
) :: map()

Returns the rendered tree for a selected window.

type(ui, text)

@spec type(GPUI.Test.UI.t(), String.t()) :: GPUI.Test.UI.t()

Types text into the focused native input.

window_snapshot(source, selector \\ :first)

@spec window_snapshot(
  GenServer.server() | GPUI.Snapshot.t(),
  :first | pos_integer() | String.t()
) :: map()

Returns a window snapshot from a runtime or full snapshot.