Implement full-text search for members closes #11 #163

Merged
carla merged 6 commits from feature/11-fulltext-search into main 2025-09-29 14:26:38 +02:00
2 changed files with 47 additions and 0 deletions
Showing only changes of commit 53f6b62289 - Show all commits

View 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

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?

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

Yes, you are right :) Changed that to checking if members are not present instead
# 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

View file

@ -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

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