Plushie.Test.Backend.Runtime (Plushie v0.6.0)

Copy Markdown View Source

Test backend that starts a real Plushie app (Runtime + Bridge).

Starts the full Plushie supervisor tree connected to the shared SessionPool via a PoolAdapter. All event processing goes through the real Runtime, giving tests production-equivalent behavior. Canvas widget state, event transformation, subscriptions, effects, and scoped IDs all work identically to production.

Architecture

Test process
  |
  v
Backend.Runtime (GenServer)
  |-- owns Plushie supervisor (Bridge + Runtime)
  |-- PoolAdapter connects Bridge <-> SessionPool
  |-- queries go to Runtime.get_model/get_tree
  |-- interactions go to Runtime.interact -> Bridge -> renderer

Windowed sessions wait after interactions, before the backend asks the renderer for tree hashes. That keeps renderer-backed reads from racing the last update without adding extra startup work to every session.

Options

Passed through from start/2:

  • :pool -- the SessionPool server (default: Plushie.TestPool)
  • :format -- wire format (default: :msgpack)
  • :init_arg -- argument passed to the app's init/1 callback

Example

{:ok, pid} = Plushie.Test.Backend.Runtime.start(MyApp, pool: Plushie.TestPool)
:ok = Plushie.Test.Backend.Runtime.click(pid, "#save")
model = Plushie.Test.Backend.Runtime.model(pid)
assert model.saved?
Plushie.Test.Backend.Runtime.stop(pid)

Summary

Types

Renderer mode used by the test backend.

t()

Types

mode()

@type mode() :: :mock | :headless | :windowed

Renderer mode used by the test backend.

t()

@type t() :: %Plushie.Test.Backend.Runtime{
  app: module(),
  format: :json | :msgpack,
  instance_name: atom(),
  mode: mode(),
  pool: GenServer.server(),
  runtime: pid(),
  session_id: String.t(),
  sup: pid()
}

Functions

advance_frame(pid, timestamp)

await_async(pid, tag, timeout \\ 5000)

canvas_move(pid, selector, x, y, opts \\ [])

canvas_press(pid, selector, x, y, button, opts \\ [])

canvas_release(pid, selector, x, y, button, opts \\ [])

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

click(pid, selector, opts \\ [])

find(pid, selector)

find!(pid, selector)

get_diagnostics(pid)

model(pid)

move_to(pid, x, y)

pane_focus_cycle(pid, selector, opts \\ [])

paste(pid, selector, text, opts \\ [])

press(pid, key)

register_effect_stub(pid, kind, response)

release(pid, key)

reset(pid)

screenshot(pid, name, opts \\ [])

scroll(pid, selector, delta_x, delta_y, opts \\ [])

select(pid, selector, value, opts \\ [])

slide(pid, selector, value, opts \\ [])

sort(pid, selector, column, direction, opts \\ [])

start(app, opts)

stop(pid)

submit(pid, selector, opts \\ [])

toggle(pid, selector, value \\ nil, opts \\ [])

tree(pid)

tree_hash(pid, name)

type_key(pid, key)

type_text(pid, selector, text, opts \\ [])

unregister_effect_stub(pid, kind)