towerops/test/towerops/search_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

62 lines
1.8 KiB
Elixir

defmodule Towerops.SearchTest do
use Towerops.DataCase, async: true
import Towerops.AccountsFixtures
alias Towerops.Search
setup do
user = user_fixture()
{: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
})
%{organization: organization, site: site, device: device}
end
describe "search/2" do
test "finds devices by name", %{organization: organization} do
results = Search.search(organization.id, "Core")
assert Map.has_key?(results, :devices)
assert length(results.devices) == 1
assert hd(results.devices).label == "Core Router"
end
test "finds devices by IP", %{organization: organization} do
results = Search.search(organization.id, "10.0.0")
assert Map.has_key?(results, :devices)
assert length(results.devices) == 1
end
test "finds sites by name", %{organization: organization} do
results = Search.search(organization.id, "Tower")
assert Map.has_key?(results, :sites)
assert length(results.sites) == 1
assert hd(results.sites).label == "Tower Alpha"
end
test "returns empty map for short queries", %{organization: organization} do
assert Search.search(organization.id, "a") == %{}
end
test "returns empty map when nothing matches", %{organization: organization} do
assert Search.search(organization.id, "nonexistent_xyz") == %{}
end
end
end