test: updated tests for member and search bar
This commit is contained in:
parent
78588cbad9
commit
53f6b62289
2 changed files with 47 additions and 0 deletions
34
test/mv_web/components/search_bar_component_test.exs
Normal file
34
test/mv_web/components/search_bar_component_test.exs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
defmodule MvWeb.Components.SearchBarComponentTest do
|
||||
use MvWeb.ConnCase, async: true
|
||||
import Phoenix.LiveViewTest
|
||||
|
||||
describe "SearchBarComponent" do
|
||||
test "renders with placeholder", %{conn: conn} do
|
||||
conn = conn_with_oidc_user(conn)
|
||||
{:ok, view, _html} = live(conn, "/members")
|
||||
|
||||
assert has_element?(view, "input[placeholder='Search...']")
|
||||
end
|
||||
|
||||
test "updates query when user types", %{conn: conn} do
|
||||
conn = conn_with_oidc_user(conn)
|
||||
{:ok, view, _html} = live(conn, "/members")
|
||||
|
||||
# simulate search input and check that correct user is listed
|
||||
html =
|
||||
view
|
||||
|> element("form[role=search]")
|
||||
|> render_change(%{"query" => "Friedrich"})
|
||||
|
||||
assert html =~ "Friedrich"
|
||||
|
||||
# simulate search input and check that not matching user is not shown
|
||||
html =
|
||||
view
|
||||
|> element("form[role=search]")
|
||||
|> render_change(%{"query" => "Greta"})
|
||||
|
||||
refute html =~ "Friedrich"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -73,4 +73,17 @@ defmodule MvWeb.MemberLive.IndexTest do
|
|||
|
||||
assert has_element?(index_view, "#flash-group", "Member create successfully")
|
||||
end
|
||||
|
||||
test "handle_info(:search_changed) updates assigns with search results", %{conn: conn} do
|
||||
conn = conn_with_oidc_user(conn)
|
||||
{:ok, view, _html} = live(conn, "/members")
|
||||
|
||||
send(view.pid, {:search_changed, "Friedrich"})
|
||||
|
||||
# State aus dem LiveView-Prozess holen
|
||||
state = :sys.get_state(view.pid)
|
||||
|
||||
assert state.socket.assigns.query == "Friedrich"
|
||||
assert is_list(state.socket.assigns.members)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue