feat(server): overview LiveView with status ampel + pubsub updates
This commit is contained in:
parent
62996d883d
commit
d0507f290e
2 changed files with 194 additions and 0 deletions
64
server/test/server_web/live/overview_live_test.exs
Normal file
64
server/test/server_web/live/overview_live_test.exs
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
defmodule ServerWeb.OverviewLiveTest do
|
||||
use ServerWeb.ConnCase, async: false
|
||||
|
||||
import Phoenix.LiveViewTest
|
||||
alias Server.{Hosts, Metrics}
|
||||
|
||||
defp auth(conn), do: Plug.Test.init_test_session(conn, %{authenticated: true})
|
||||
|
||||
describe "mount" do
|
||||
test "redirects to /login when unauthenticated", %{conn: conn} do
|
||||
assert {:error, {:redirect, %{to: "/login"}}} = live(conn, "/")
|
||||
end
|
||||
|
||||
test "renders a card for each host", %{conn: conn} do
|
||||
{:ok, {_h1, _}} = Hosts.create_host("pve-01")
|
||||
{:ok, {_h2, _}} = Hosts.create_host("pve-02")
|
||||
|
||||
{:ok, _view, html} = live(auth(conn), "/")
|
||||
|
||||
assert html =~ "pve-01"
|
||||
assert html =~ "pve-02"
|
||||
|
||||
assert length(Floki.find(Floki.parse_document!(html), "[data-role=host-card]")) == 2
|
||||
end
|
||||
|
||||
test "reflects :critical status for a degraded pool", %{conn: conn} do
|
||||
{:ok, {host, _}} = Hosts.create_host("pve-01")
|
||||
{:ok, _} = Hosts.mark_online(host, "0.1.0")
|
||||
|
||||
payload = %{
|
||||
"zfs_pools" => %{
|
||||
"pools" => [%{"name" => "rpool", "health" => "DEGRADED", "capacity_percent" => 40}]
|
||||
}
|
||||
}
|
||||
|
||||
{:ok, _} = Metrics.record_sample(host.id, "fast", DateTime.utc_now(), payload)
|
||||
|
||||
{:ok, _view, html} = live(auth(conn), "/")
|
||||
|
||||
assert html =~ ~r/data-status=\"critical\"/
|
||||
end
|
||||
end
|
||||
|
||||
describe "pubsub" do
|
||||
test "updates the card when a new metric arrives", %{conn: conn} do
|
||||
{:ok, {host, _}} = Hosts.create_host("pve-01")
|
||||
{:ok, _} = Hosts.mark_online(host, "0.1.0")
|
||||
|
||||
{:ok, view, _html} = live(auth(conn), "/")
|
||||
assert render(view) =~ ~r/data-status=\"ok\"/
|
||||
|
||||
payload = %{
|
||||
"zfs_pools" => %{
|
||||
"pools" => [%{"name" => "rpool", "health" => "DEGRADED", "capacity_percent" => 40}]
|
||||
}
|
||||
}
|
||||
|
||||
{:ok, _} = Metrics.record_sample(host.id, "fast", DateTime.utc_now(), payload)
|
||||
|
||||
Process.sleep(50)
|
||||
assert render(view) =~ ~r/data-status=\"critical\"/
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue