Implement full-text search for members closes #11 #163
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"
|
||||
|
simon marked this conversation as resolved
Outdated
|
||||
|
||||
# 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
|
||||
|
carla marked this conversation as resolved
simon
commented
a bit picky, but this comment should be in english :) a bit picky, but this comment should be in english :)
|
||||
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
Doesn't this just assert that "Friedrich" should occur anywhere in the html?
If I'm not wrong, this would also apply to the exact same search string "Friedrich" which is rendered in html, too, and therefore it doesn't matter for the test which result is presented?
Yes, you are right :) Changed that to checking if members are not present instead