Packages
pages
1.0.0
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/shim.ex
defmodule Pages.Shim do
# credo:disable-for-this-file
@moduledoc false
## Pages.Shim is used to unwrap macros provided by Phoenix which require
## @endpoint to be set in the calling file. It is inherently unsafe, and should
## be tested against every version of Phoenix and PhoenixLiveView to ensure that
## private changes to those libraries do not break compatibility.
use Gestalt
def __dispatch(conn, method, path, params \\ %{}),
do: Phoenix.ConnTest.dispatch(conn, __endpoint(), method, path, params)
def __endpoint do
gestalt_config(:pages, :phoenix_endpoint, self()) ||
raise("""
Unable to find configured endpoint.
config :pages, :phoenix_endpoint, My.EndpointModule
""")
end
def __follow_trigger_action(form, conn) do
test_module = Phoenix.LiveViewTest
old_function = :__render_trigger_event__
new_function = :__render_trigger_submit__
cond do
function_exported?(test_module, old_function, 1) ->
{method, path, form_data} = apply(test_module, old_function, [form])
__dispatch(conn, method, path, form_data)
|> __retain_connect_params(conn)
function_exported?(test_module, new_function, 4) ->
{method, path, form_data} =
apply(test_module, new_function, [
form,
:follow_trigger_action,
"phx-trigger-action",
"could not follow trigger action because form #{inspect(form.selector)} " <>
"does not have a phx-trigger-action attribute"
])
__dispatch(conn, method, path, form_data)
|> __retain_connect_params(conn)
true ->
raise "This version of #{test_module} does not define #{old_function} or #{new_function}"
end
end
def __retain_connect_params(conn, original_conn) do
if Map.has_key?(original_conn.private, :live_view_connect_params),
do: Phoenix.LiveViewTest.put_connect_params(conn, original_conn.private.live_view_connect_params),
else: conn
end
end