Current section
Files
Jump to
Current section
Files
src/plushie@testing.erl
-module(plushie@testing).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/plushie/testing.gleam").
-export([start/1, model/1, tree/1, send_event/2, click/2, type_text/3, toggle/2, submit/2, slide/3, select/3, find/2, element_text/1, element_prop/2, element_children/1]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(
" Test facade for plushie applications.\n"
"\n"
" Provides a pure functional test harness that runs the Elm loop\n"
" (init -> update -> view -> normalize) without the Rust binary.\n"
" State is threaded immutably through each operation.\n"
"\n"
" ## Usage\n"
"\n"
" let session = test.start(my_app)\n"
" let session = test.click(session, \"increment\")\n"
" let model = test.model(session)\n"
" should.equal(model.count, 1)\n"
).
-file("src/plushie/testing.gleam", 23).
?DOC(" Start a test session for a simple app (msg = Event).\n").
-spec start(plushie@app:app(QIJ, plushie@event:event())) -> plushie@testing@session:test_session(QIJ, plushie@event:event()).
start(App) ->
plushie@testing@session:start(App).
-file("src/plushie/testing.gleam", 28).
?DOC(" Return the current model from the session.\n").
-spec model(plushie@testing@session:test_session(QIO, plushie@event:event())) -> QIO.
model(Session) ->
plushie@testing@session:model(Session).
-file("src/plushie/testing.gleam", 33).
?DOC(" Return the current normalized tree from the session.\n").
-spec tree(plushie@testing@session:test_session(any(), plushie@event:event())) -> plushie@node:node_().
tree(Session) ->
plushie@testing@session:current_tree(Session).
-file("src/plushie/testing.gleam", 38).
?DOC(" Dispatch a raw event through the update cycle.\n").
-spec send_event(
plushie@testing@session:test_session(QIU, plushie@event:event()),
plushie@event:event()
) -> plushie@testing@session:test_session(QIU, plushie@event:event()).
send_event(Session, Event) ->
plushie@testing@session:send_event(Session, Event).
-file("src/plushie/testing.gleam", 48).
?DOC(" Simulate a click on a widget by ID.\n").
-spec click(
plushie@testing@session:test_session(QIZ, plushie@event:event()),
binary()
) -> plushie@testing@session:test_session(QIZ, plushie@event:event()).
click(Session, Id) ->
plushie@testing@helpers:click(Session, Id).
-file("src/plushie/testing.gleam", 56).
?DOC(" Simulate text input on a widget by ID.\n").
-spec type_text(
plushie@testing@session:test_session(QJE, plushie@event:event()),
binary(),
binary()
) -> plushie@testing@session:test_session(QJE, plushie@event:event()).
type_text(Session, Id, Text) ->
plushie@testing@helpers:type_text(Session, Id, Text).
-file("src/plushie/testing.gleam", 65).
?DOC(" Simulate a checkbox/toggler toggle by ID.\n").
-spec toggle(
plushie@testing@session:test_session(QJJ, plushie@event:event()),
binary()
) -> plushie@testing@session:test_session(QJJ, plushie@event:event()).
toggle(Session, Id) ->
plushie@testing@helpers:toggle(Session, Id).
-file("src/plushie/testing.gleam", 73).
?DOC(" Simulate form submission on a widget by ID.\n").
-spec submit(
plushie@testing@session:test_session(QJO, plushie@event:event()),
binary()
) -> plushie@testing@session:test_session(QJO, plushie@event:event()).
submit(Session, Id) ->
plushie@testing@helpers:submit(Session, Id).
-file("src/plushie/testing.gleam", 81).
?DOC(" Simulate a slider change by ID.\n").
-spec slide(
plushie@testing@session:test_session(QJT, plushie@event:event()),
binary(),
float()
) -> plushie@testing@session:test_session(QJT, plushie@event:event()).
slide(Session, Id, Value) ->
plushie@testing@helpers:slide(Session, Id, Value).
-file("src/plushie/testing.gleam", 90).
?DOC(" Simulate selection on a widget by ID.\n").
-spec select(
plushie@testing@session:test_session(QJY, plushie@event:event()),
binary(),
binary()
) -> plushie@testing@session:test_session(QJY, plushie@event:event()).
select(Session, Id, Value) ->
plushie@testing@helpers:select(Session, Id, Value).
-file("src/plushie/testing.gleam", 101).
?DOC(" Find an element by ID in the session's current tree.\n").
-spec find(
plushie@testing@session:test_session(any(), plushie@event:event()),
binary()
) -> gleam@option:option(plushie@testing@element:element()).
find(Session, Id) ->
plushie@testing@element:find(
plushie@testing@session:current_tree(Session),
Id
).
-file("src/plushie/testing.gleam", 106).
?DOC(" Extract text content from an element.\n").
-spec element_text(plushie@testing@element:element()) -> gleam@option:option(binary()).
element_text(El) ->
plushie@testing@element:text(El).
-file("src/plushie/testing.gleam", 111).
?DOC(" Get a prop value from an element.\n").
-spec element_prop(plushie@testing@element:element(), binary()) -> gleam@option:option(plushie@node:prop_value()).
element_prop(El, Key) ->
plushie@testing@element:prop(El, Key).
-file("src/plushie/testing.gleam", 116).
?DOC(" Get an element's children.\n").
-spec element_children(plushie@testing@element:element()) -> list(plushie@testing@element:element()).
element_children(El) ->
plushie@testing@element:children(El).