View Source Pages (Pages v0.13.2)
Entry point for interacting with pages.
Pages are built around Pages.Driver.t/0
structs. Drivers hold state about
the current connection, implement @behavior Pages.Driver
and must implement
the String.Chars
protocol to transform themselves into HTML.
available-drivers
Available drivers
Pages.Driver.Conn.t/0
- Given aPlug.Conn.t/0
, this driver will be used.Pages.Driver.LiveView.t/0
- Given aPlug.Conn.t/0
with inner data that appears as if aPhoenix.LiveView
is configured, this driver will be used.
Link to this section Summary
Types
In most cases, when interacting with pages, a new page will be returned (either a
%Pages.Driver.LiveView{}
or a %Pages.Driver.Conn{}
). When actions redirect to
an external URL, Pages
functions will return a tuple with {:error, :external, url}
Functions
Clears out any params set via Phoenix.LiveViewTest.put_connect_params/2
Simulates clicking on an element at selector
with title title
.
Set the method
param to :post
to click on a link that has data-method=post
.
Instantiates a new page.
Render a change to the element at selector
with the value value
. See Phoenix.LiveViewTest.render_change/2
for
a description of the value
field.
Sends a hook event to the live view.
Performs an upload of a file input and renders the result. See Phoenix.LiveViewTest.file_input/4
for
a description of the upload
field.
Re-renders the page.
Submits a form without specifying any attributes. This function will submit any values currently set in the form HTML.
Fills in a form with attributes
and submits it. Hidden parameters can by send by including
a fifth enumerable.
See Pages.submit_form/4
for more information.
Updates fields in a form with attributes
without submitting it.
Visits path
.
Finds a phoenix component with an id matching child_id
, and passes it to the given
function. This is helpful when a site implements stateful LiveView components, and
messages should be directed to a process other than the parent LiveView pid.
Link to this section Types
@type http_method() :: :get | :post
@type page_type_t() :: :live_view
@type result() :: Pages.Driver.t() | {:error, :external, Path.t()}
In most cases, when interacting with pages, a new page will be returned (either a
%Pages.Driver.LiveView{}
or a %Pages.Driver.Conn{}
). When actions redirect to
an external URL, Pages
functions will return a tuple with {:error, :external, url}
Link to this section Functions
@spec clear_connect_params(Pages.Driver.t()) :: result()
Clears out any params set via Phoenix.LiveViewTest.put_connect_params/2
@spec click(Pages.Driver.t(), HtmlQuery.Css.selector()) :: result()
@spec click(Pages.Driver.t(), http_method(), HtmlQuery.Css.selector()) :: result()
@spec click(Pages.Driver.t(), text_filter(), HtmlQuery.Css.selector()) :: result()
@spec click(Pages.Driver.t(), http_method(), text_filter(), HtmlQuery.Css.selector()) :: result()
Simulates clicking on an element at selector
with title title
.
Set the method
param to :post
to click on a link that has data-method=post
.
@spec new(Plug.Conn.t()) :: result()
Instantiates a new page.
@spec render_change(Pages.Driver.t(), HtmlQuery.Css.selector(), Enum.t()) :: result()
Render a change to the element at selector
with the value value
. See Phoenix.LiveViewTest.render_change/2
for
a description of the value
field.
@spec render_hook(Pages.Driver.t(), binary(), attrs_t(), keyword()) :: result()
Sends a hook event to the live view.
arguments
Arguments
name | decription |
---|---|
page | The current page struct. |
event | The event name to send to handle_event . |
value_attrs | A map of params to send to handle_event . |
opts | An optional keyword list of options. |
options
Options
name | description |
---|---|
target | The selector of an embedded live componont to receive the event. Example: #sub-module |
See Phoenix.LiveViewTest.render_hook/3
for more information.
@spec render_upload(Pages.Driver.t(), live_view_upload(), binary(), integer()) :: result()
Performs an upload of a file input and renders the result. See Phoenix.LiveViewTest.file_input/4
for
a description of the upload
field.
@spec rerender(Pages.Driver.t()) :: result()
Re-renders the page.
@spec submit_form(Pages.Driver.t(), HtmlQuery.Css.selector()) :: result()
Submits a form without specifying any attributes. This function will submit any values currently set in the form HTML.
@spec submit_form(Pages.Driver.t(), HtmlQuery.Css.selector(), atom(), attrs_t()) :: result()
Fills in a form with attributes
and submits it. Hidden parameters can by send by including
a fifth enumerable.
arguments
Arguments
name | decription |
---|---|
page | The current page struct. |
selector | A CSS selector matching the form. |
schema | An atom representing the schema of the form. Attributes will be nested under this key when submitted. See Schema. |
attrs | A map of attributes to send. |
hidden_attrs | An optional map or keyword of hidden values to include. |
schema
Schema
This atom determines the key under which attrs will be nested when sent to the server,
and corresponds to the atom which an t:Ecto.Changeset.t/0
serializes to, or the value
of :as
passed to Phoenix.HTML.Form.form_for/4
.
notes
Notes
When used with LiveView, this will trigger phx-submit
with the specified attributes,
and handles phx-trigger-action
if present.
@spec submit_form( Pages.Driver.t(), HtmlQuery.Css.selector(), atom(), attrs_t(), attrs_t() ) :: result()
See Pages.submit_form/4
for more information.
@spec update_form( Pages.Driver.t(), HtmlQuery.Css.selector(), atom(), attrs_t(), keyword() ) :: result()
Updates fields in a form with attributes
without submitting it.
arguments
Arguments
name | decription |
---|---|
page | The current page struct. |
selector | A CSS selector matching the form. |
schema | An atom representing the schema of the form. Attributes will be nested under this key when submitted. See Schema. |
attrs | A map of attributes to send. |
opts | A keyword list of options. |
options
Options
name | type | description |
---|---|---|
target | list(binary()) | A list to be sent in the _target of the form params, indicating which field has been changes. |
schema
Schema
This atom determines the key under which attrs will be nested when sent to the server,
and corresponds to the atom which an t:Ecto.Changeset.t/0
serializes to, or the value
of :as
passed to Phoenix.HTML.Form.form_for/4
.
notes
Notes
When used with LiveView, this will trigger phx-change
with the specified attributes,
and handles phx-trigger-action
if present.
@spec visit(Pages.Driver.t(), Path.t()) :: result()
Visits path
.
@spec with_child_component( Pages.Driver.t(), child_id :: binary(), (Pages.Driver.t() -> term()) ) :: Pages.Driver.t()
Finds a phoenix component with an id matching child_id
, and passes it to the given
function. This is helpful when a site implements stateful LiveView components, and
messages should be directed to a process other than the parent LiveView pid.
examples
Examples
Pages.with_child_component(page, "chat-component", fn child ->
Pages.submit_form(child,
[test_role: "new-chat-message"],
:chat_message,
contents: "Hi there!")
end)