towerops/test/towerops_web/live/components/global_search_component_test.exs
Graham McIntire 0832abf33a
feat: comprehensive e2e test coverage for all user-facing features
- Added e2e tests for agents, insights, maintenance windows, maps, help pages
- Added e2e tests for organization settings, config timeline, MikroTik backups
- Added comprehensive search functionality tests
- Added dashboard and sites navigation tests
- Updated existing tests to handle sudo verification redirects
- Fixed navigation tests to be more defensive about missing data
- All 301 tests passing across chromium, firefox, and webkit
2026-03-06 16:58:06 -06:00

82 lines
2.1 KiB
Elixir

defmodule ToweropsWeb.Live.Components.GlobalSearchComponentTest do
use ToweropsWeb.ConnCase, async: true
import Phoenix.LiveViewTest
import Towerops.AccountsFixtures
setup :register_and_log_in_user
setup %{conn: conn, user: user} do
{:ok, organization} = Towerops.Organizations.create_organization(%{name: "Test ISP"}, user.id)
{:ok, site} =
Towerops.Sites.create_site(%{
name: "Tower Alpha",
organization_id: organization.id
})
{:ok, _device} =
Towerops.Devices.create_device(%{
name: "Core Router",
ip_address: "10.0.0.1",
site_id: site.id,
organization_id: organization.id,
snmp_enabled: true
})
conn = Plug.Conn.put_session(conn, :current_organization_id, organization.id)
%{conn: conn, organization: organization}
end
describe "global search" do
test "search event with value param finds results", %{conn: conn} do
{:ok, view, _html} = live(conn, ~p"/dashboard")
html =
view
|> element("#global-search")
|> render_hook("open", %{})
assert html =~ "Search devices"
html =
view
|> element("#global-search")
|> render_hook("search", %{"value" => "Core Router"})
assert html =~ "Core Router"
assert html =~ "Devices"
end
test "search event with value param finds sites", %{conn: conn} do
{:ok, view, _html} = live(conn, ~p"/dashboard")
view
|> element("#global-search")
|> render_hook("open", %{})
html =
view
|> element("#global-search")
|> render_hook("search", %{"value" => "Tower"})
assert html =~ "Tower Alpha"
assert html =~ "Sites"
end
test "short query returns no results", %{conn: conn} do
{:ok, view, _html} = live(conn, ~p"/dashboard")
view
|> element("#global-search")
|> render_hook("open", %{})
html =
view
|> element("#global-search")
|> render_hook("search", %{"value" => "a"})
assert html =~ "No results found"
end
end
end