View Source Heyya.LiveTest (heyya v0.4.0)
Heyya.LiveTest
module provides helper methods that make it easier to write a
more linear live view test. It takes care of the fact that there's
connection state, view state, and last html state.
These ideas origionally came from: https://www.reddit.com/r/elixir/comments/ydyt2m/better_liveview_tests/
This implementation doesn't hide follow (in large part because of the ergonomics of follow_redirect being a macro)
example
Example
defmodule MyPhoenixWeb.ListLiveTest do
use Heyya.LiveTest
use MyPhoenixWeb.ConnCase
test "widget list with new button", %{conn: conn} do
start(conn, ~p|/widgets|)
|> assert_html("Widgets List")
|> click("a", "New Widgets")
|> follow(~p|/widgets/new|)
end
end
Link to this section Summary
Functions
This method clicks on an element that's selected via selector then renders the result. Finally returning a new LiveTestSession with updated rendered html
Sets the form specified by the selector to a new value.
Macro that creates code to start a new LiveTestSession. This takes in a plug connection (Usually from your ConnTest)
Submits the form and renders the result of submitting.
Link to this section Functions
@spec assert_element(Heyya.LiveTestSession.t(), String.t(), String.t() | nil) :: Heyya.LiveTestSession.t()
@spec assert_html(Heyya.LiveTestSession.t(), String.t() | Regex.t()) :: Heyya.LiveTestSession.t()
@spec assert_page_title(Heyya.LiveTestSession.t(), String.t() | Regex.t()) :: Heyya.LiveTestSession.t()
@spec click(Heyya.LiveTestSession.t(), String.t(), String.t() | nil) :: Heyya.LiveTestSession.t()
This method clicks on an element that's selected via selector then renders the result. Finally returning a new LiveTestSession with updated rendered html
This will also assert that there is an element that's specified by the selector
This doesn't follow navigations or redirect.
returns: %Heyya.LiveTestSession{}
@spec form(Heyya.LiveTestSession.t(), String.t(), any()) :: Heyya.LiveTestSession.t()
Sets the form specified by the selector to a new value.
This doesn't submit the form
returns: %Heyya.LiveTestSession{}
@spec refute_element(Heyya.LiveTestSession.t(), String.t(), String.t() | nil) :: Heyya.LiveTestSession.t()
@spec refute_html(Heyya.LiveTestSession.t(), String.t() | Regex.t()) :: Heyya.LiveTestSession.t()
@spec refute_page_title(Heyya.LiveTestSession.t(), String.t() | Regex.t()) :: Heyya.LiveTestSession.t()
Macro that creates code to start a new LiveTestSession. This takes in a plug connection (Usually from your ConnTest)
@spec submit_form(Heyya.LiveTestSession.t(), String.t(), any()) :: Heyya.LiveTestSession.t()
Submits the form and renders the result of submitting.
This doesn't follow any redirects.
returns: %Heyya.LiveTestSession{}