81 lines
2 KiB
Elixir
81 lines
2 KiB
Elixir
defmodule ToweropsWeb.Live.Components.GlobalSearchComponentTest do
|
|
use ToweropsWeb.ConnCase, async: true
|
|
|
|
import Phoenix.LiveViewTest
|
|
|
|
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
|