-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_helpers.ex
77 lines (62 loc) · 1.99 KB
/
test_helpers.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
defmodule Iamvery.Phoenix.LiveView.TestHelpers do
defmacro __using__([]) do
quote do
import Phoenix.LiveViewTest
def start(conn, path) do
{conn, live(conn, path)}
end
def escape(html) do
Plug.HTML.html_escape(html)
end
def rerender({conn, {:ok, view, _html}}) do
html = render(view)
{conn, {:ok, view, html}}
end
def assert_html({conn, {:ok, view, html}}, expected_html) do
assert html =~ expected_html
{conn, {:ok, view, html}}
end
def refute_html({conn, {:ok, view, html}}, unexpected_html) do
refute html =~ unexpected_html
{conn, {:ok, view, html}}
end
def assert_path({conn, {:ok, view, html}}, path) do
assert_patch(view, path)
{conn, {:ok, view, html}}
end
def assert_element({conn, {:ok, view, html}}, selector, text \\ nil) do
assert has_element?(view, selector, text)
{conn, {:ok, view, html}}
end
def refute_element({conn, {:ok, view, html}}, selector, text \\ nil) do
refute has_element?(view, selector, text)
{conn, {:ok, view, html}}
end
def click({conn, {:ok, view, _html}}, selector, text \\ nil) do
html =
view
|> element(selector, text)
|> render_click()
{conn, {:ok, view, html}}
end
def follow(session, selector, text \\ nil) do
{conn, {:ok, _view, html}} = click(session, selector, text)
{conn, follow_redirect(html, conn)}
end
def change_form({conn, {:ok, view, _html}}, selector, attributes) do
html =
view
|> form(selector, attributes)
|> render_change()
{conn, {:ok, view, html}}
end
def submit_form({conn, {:ok, view, _html}}, selector, attributes) do
html =
view
|> form(selector, attributes)
|> render_submit()
{conn, follow_redirect(html, conn)}
end
end
end
end