Skip to content

Commit 455207a

Browse files
authored
Use with_target in tests and remove unnecessary phx-target (#146)
1 parent 79768d7 commit 455207a

2 files changed

Lines changed: 12 additions & 10 deletions

File tree

lib/elixir_console_web/live/console_live/command_input_component.html.leex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
autocomplete="off"
99
autofocus
1010
name="command"
11-
phx-target="#command_input"
1211
phx-hook="CommandInput"
1312
data-input_value="<%= @input_value %>"
1413
data-caret_position="<%= @caret_position %>"

test/elixir_console_web/live/console_live_test.exs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,9 @@ defmodule ElixirConsoleWeb.ConsoleLiveTest do
102102
test "show suggestions if more than one", %{conn: conn} do
103103
{:ok, view, _html} = live(conn, "/")
104104

105-
input = element(view, "#command_input input")
106-
render_hook(input, :suggest, %{"value" => "Enum.co", "caret_position" => 7})
105+
view
106+
|> with_target("#command_input")
107+
|> render_hook(:suggest, %{"value" => "Enum.co", "caret_position" => 7})
107108

108109
html = render(view)
109110

@@ -113,8 +114,9 @@ defmodule ElixirConsoleWeb.ConsoleLiveTest do
113114
test "autocomplete and do not show suggestions if only one", %{conn: conn} do
114115
{:ok, view, _html} = live(conn, "/")
115116

116-
input = element(view, "#command_input input")
117-
render_hook(input, :suggest, %{"value" => "Enum.conc", "caret_position" => 9})
117+
view
118+
|> with_target("#command_input")
119+
|> render_hook(:suggest, %{"value" => "Enum.conc", "caret_position" => 9})
118120

119121
html = render(view)
120122

@@ -127,8 +129,9 @@ defmodule ElixirConsoleWeb.ConsoleLiveTest do
127129
test "show suggestions considering caret position in the command input", %{conn: conn} do
128130
{:ok, view, _html} = live(conn, "/")
129131

130-
input = element(view, "#command_input input")
131-
render_hook(input, :suggest, %{"value" => "Enum.co([1,2]) - 2", "caret_position" => 7})
132+
view
133+
|> with_target("#command_input")
134+
|> render_hook(:suggest, %{"value" => "Enum.co([1,2]) - 2", "caret_position" => 7})
132135

133136
html = render(view)
134137

@@ -138,10 +141,10 @@ defmodule ElixirConsoleWeb.ConsoleLiveTest do
138141
test "autocomplete considering caret position in the command input", %{conn: conn} do
139142
{:ok, view, _html} = live(conn, "/")
140143

141-
input = element(view, "#command_input input")
142-
143144
html =
144-
render_hook(input, :suggest, %{"value" => "Enum.conc([1,2], [3])", "caret_position" => 9})
145+
view
146+
|> with_target("#command_input")
147+
|> render_hook(:suggest, %{"value" => "Enum.conc([1,2], [3])", "caret_position" => 9})
145148

146149
assert html =~ ~r/\<input .* data-input_value\="Enum.concat\(\[1,2\], \[3\]\)"/
147150
assert html =~ ~r/\<input .* data-caret_position\="11"/

0 commit comments

Comments
 (0)