Packages
pages
0.3.1
4.1.0
4.0.0
3.5.0
3.4.2
3.4.1
3.4.0
3.3.0
3.2.0
3.1.0
3.0.1
3.0.0
2.3.0
2.2.1
2.2.0
2.1.1
2.1.0
2.0.0
1.3.1
1.3.0
1.2.0
1.1.0
1.0.3
1.0.2
1.0.1
1.0.0
0.14.0
0.13.4
0.13.3
0.13.2
0.13.1
0.13.0
0.12.0
0.11.1
0.11.0
0.10.1
0.10.0
0.9.0
0.8.0
0.7.1
0.7.0
0.6.2
0.6.1
0.6.0
0.5.7
0.5.6
0.5.5
0.5.4
0.5.3
0.5.2
0.5.1
0.5.0
0.4.3
0.4.2
0.4.1
0.4.0
0.3.1
0.3.0
0.2.6
0.2.5
0.2.4
0.2.3
0.2.2
0.2.1
0.2.0
0.1.0
Page pattern for interacting with web pages
Current section
Files
Jump to
Current section
Files
lib/pages/driver/conn.ex
defmodule Pages.Driver.Conn do
# @related [drivers](lib/pages/driver.ex)
@moduledoc """
A page driver for interacting with Phoenix controllers.
"""
@behaviour Pages.Driver
defstruct ~w[conn]a
@type t() :: %__MODULE__{
conn: Plug.Conn.t()
}
def new(%Plug.Conn{state: :unset} = conn),
do:
conn
|> Pages.Shim.__dispatch(:get, conn.request_path, conn.path_params)
|> Pages.new()
def new(%Plug.Conn{status: 302} = conn) do
redirect = Phoenix.ConnTest.redirected_to(conn)
__struct__(conn: conn) |> visit(redirect)
end
def new(%Plug.Conn{} = conn),
do: __struct__(conn: conn)
# # #
def visit(%__MODULE__{} = page, path) do
page.conn
|> Pages.Shim.__dispatch(:get, path)
|> Pages.new()
end
# # #
defimpl String.Chars do
def to_string(%Pages.Driver.Conn{conn: %Plug.Conn{status: 200} = conn}),
do: Phoenix.ConnTest.html_response(conn, 200)
end
end