Helpers for Phoenix.LiveViewTest, to choose and search in tests with
no browser.
import Erabi.Test
test "labels a task", %{conn: conn} do
{:ok, view, _html} = live(conn, ~p"/tasks/1")
assert choices(view, "task_labels_picker") == ["Bug", "Feature", "Docs"]
html = choose(view, "task_labels_picker", ["bug", "docs"])
assert html =~ "2 labels"
endchoose/3 sends the form's phx-change with the values in the
picker's input, as the picker does in a browser, and with the other
pickers of the form as they are. The form must have an id. The values
are checked by the LiveView, not here: a test can choose a value that
the rules refuse, to see the error.
The inputs of a picker are not updated in LiveViewTest's copy of the
page (they are under phx-update="ignore", as in a browser, where the
hook keeps them). To submit, give the form the values:
view
|> form("#task-form", task: %{labels: ["bug"]})
|> render_submit()search/3 runs a picker's search (Erabi.Live) as the picker does,
and returns the labels it finds.
Summary
Functions
The labels of a picker's options, in order, as its list shows them
before people type. (Not options/2: Phoenix.ConnTest has one.)
Chooses values in the picker with the id picker_id (a value, a list
of them for a picker of several, or nil to clear it), and returns the
rendered LiveView (as Phoenix.LiveViewTest.render_change/2 does). A
value is what the picker posts: an option's value, as text or as it is
(an atom, an integer).
The labels of the values chosen in a picker, as the server rendered it.
Runs the search of the picker picker_id for a query, as the picker
does as people type, and returns the labels it finds (the first page).
Functions
The labels of a picker's options, in order, as its list shows them
before people type. (Not options/2: Phoenix.ConnTest has one.)
Chooses values in the picker with the id picker_id (a value, a list
of them for a picker of several, or nil to clear it), and returns the
rendered LiveView (as Phoenix.LiveViewTest.render_change/2 does). A
value is what the picker posts: an option's value, as text or as it is
(an atom, an integer).
The labels of the values chosen in a picker, as the server rendered it.
Runs the search of the picker picker_id for a query, as the picker
does as people type, and returns the labels it finds (the first page).