TestDispatchForm v0.1.0 TestDispatchForm View Source
A module that contains a function to test the dispatch of forms. This will make it easier to write integration tests to check if forms in Phoenix templates will submit to the intended controller action with the right params.
Link to this section Summary
Functions
Will find a form in the HTML response of the given conn by entity or by
TestSelector
, or, if no entity or test_selector is provided, it will target
the last form found in the response.
Link to this section Functions
dispatch_form_with(conn, attrs \\ %{}, entity_or_test_selector \\ nil)
View Sourcedispatch_form_with( Plug.Conn.t(), %{required(atom()) => term()}, binary() | atom() | nil ) :: Plug.Conn.t()
Will find a form in the HTML response of the given conn by entity or by
TestSelector
, or, if no entity or test_selector is provided, it will target
the last form found in the response.
Next it will look for form controls (inputs, selects), convert these to params
and use the attributes passed to dispatch_form_with/3
to update the values
of the params. The params will now only contain field keys found in the
controls of the form.
If an entity is given, the params will be prepended by this entity.
Ultimately, the conn is dispatched to the conn's private.phoenix_endpoint
using Phoenix.ConnTest.dispatch/5
, with the params and with the method and
action found in the form.