towerops/test/towerops_web/live/my_data_live_test.exs

61 lines
1.8 KiB
Elixir

defmodule ToweropsWeb.AccountLive.MyDataTest do
use ToweropsWeb.ConnCase
import Phoenix.LiveViewTest
setup :register_and_log_in_user
describe "My Data page" do
test "renders for organization owner without additional data", %{conn: conn} do
# register_and_log_in_user creates a user with a Personal org (as owner)
{:ok, _view, html} = live(conn, ~p"/account/my-data")
assert html =~ "My Data"
assert html =~ "Profile Information"
assert html =~ "Security Credentials"
assert html =~ "Organizations"
assert html =~ "Devices"
assert html =~ "Audit Log"
end
test "renders for organization owner with full data", %{conn: conn, user: user} do
{:ok, organization} = Towerops.Organizations.create_organization(%{name: "Test Org"}, user.id)
{:ok, site} =
Towerops.Sites.create_site(%{
name: "Test Site",
organization_id: organization.id
})
{:ok, device} =
Towerops.Devices.create_device(%{
name: "Test Device",
ip_address: "192.168.1.1",
site_id: site.id,
monitoring_enabled: true
})
# Create an alert
{:ok, _alert} =
Towerops.Alerts.create_alert(%{
device_id: device.id,
alert_type: :device_down,
triggered_at: DateTime.utc_now(),
message: "Device is down"
})
{:ok, _view, html} = live(conn, ~p"/account/my-data")
assert html =~ "My Data"
assert html =~ "Profile Information"
assert html =~ "Security Credentials"
assert html =~ "Organizations"
assert html =~ "Devices"
assert html =~ "Recent Alerts"
assert html =~ "Audit Log"
assert html =~ "Test Org"
assert html =~ "Test Device"
assert html =~ "192.168.1.1"
end
end
end