Split dashboard into home page and battery list page

This commit is contained in:
2026-06-19 21:43:10 -05:00
parent 1980453cab
commit 0b893ffcbb
9 changed files with 817 additions and 49 deletions
+41 -6
View File
@@ -30,17 +30,52 @@ def follow(client, resp):
# ------------------------------------------------------------------ #
# Dashboard
# Home page
# ------------------------------------------------------------------ #
def test_dashboard_loads(seeded_client):
def test_home_loads(seeded_client):
resp = seeded_client.get("/")
assert resp.status_code == 200
assert b"Available" in resp.data
assert b"Installed" in resp.data
assert b"Devices" in resp.data
assert b"BrandX 001" not in resp.data # no battery table on home page
def test_home_needs_attention_shows_low_capacity(client):
client.post("/battery/add", data={"brand": "Eneloop", "count": "1"})
client.post("/battery/1/edit-details", data={"capacity_mah": "2000"})
client.post("/battery/1/capacity-test/add",
data={"tested_capacity_mah": "1500", "tested_date": "2026-01-01"})
resp = client.get("/")
assert b"Needs Attention" in resp.data
assert b"Eneloop 001" in resp.data
def test_home_shows_device_counts(seeded_client):
resp = seeded_client.get("/")
assert resp.status_code == 200
assert b"Devices" in resp.data
# ------------------------------------------------------------------ #
# Battery list
# ------------------------------------------------------------------ #
def test_battery_list_loads(seeded_client):
resp = seeded_client.get("/battery/")
assert resp.status_code == 200
assert b"BrandX 001" in resp.data
assert b"BrandY 001" in resp.data
assert b"BrandX 002" in resp.data
def test_battery_list_has_filter_bar(seeded_client):
resp = seeded_client.get("/battery/")
assert b"filter-status" in resp.data
assert b"filter-brand" in resp.data
# ------------------------------------------------------------------ #
# Battery add — label preview data
# ------------------------------------------------------------------ #
@@ -197,7 +232,7 @@ def test_unassign_next_honors_local_path(seeded_client):
def test_unassign_next_rejects_external_redirect(seeded_client):
seeded_client.post("/battery/1/assign", data={"device_id": "1"})
resp = seeded_client.post("/battery/1/unassign", data={"next": "//evil.com/phish"})
assert resp.headers["Location"] == "/"
assert resp.headers["Location"] == "/battery/"
def test_unassign_all_next_rejects_external_redirect(seeded_client):
@@ -741,7 +776,7 @@ def test_import_creates_devices_and_batteries(client):
resp = _post_import(client, payload)
assert resp.status_code == 200
assert b"Import Results" in resp.data
dash = client.get("/")
dash = client.get("/battery/")
assert b"Eneloop 001" in dash.data
assert b"RC Car" in dash.data
@@ -1054,10 +1089,10 @@ def test_subcomponent_install_batteries(client):
assert b"full" in resp.data.lower()
def test_dashboard_shows_parent_slash_child(client):
def test_battery_list_shows_parent_slash_child(client):
_setup_rc_car(client)
client.post("/device/2/install-one", data={"battery_id": "1"})
resp = client.get("/", follow_redirects=True)
resp = client.get("/battery/", follow_redirects=True)
assert resp.status_code == 200
assert b"RC Car Set" in resp.data
assert b"Remote" in resp.data
+2 -2
View File
@@ -314,7 +314,7 @@ def test_poll_handles_api_error_gracefully(ha_app, ha_client_f):
# ---------------------------------------------------------------------------
def test_dashboard_shows_ha_column_when_enabled(ha_client_f):
resp = ha_client_f.get("/")
resp = ha_client_f.get("/battery/")
assert resp.status_code == 200
assert b"ha-pct" in resp.data
@@ -351,7 +351,7 @@ def test_dashboard_no_warning_for_high_percentage(ha_app, ha_client_f):
s.commit()
s.close()
resp = ha_client_f.get("/")
resp = ha_client_f.get("/battery/")
assert b"85%" in resp.data
# badge-warning should NOT appear for this battery's percentage
# (may still appear in page for other reasons, so check row contains 85% but not warning badge near it)