Add capacity test history and chart to battery detail

- New CapacityTest model (battery_id FK CASCADE, mah, date, notes)
- DB migration: create capacity_test table, migrate existing single-test data
- Two new routes: add and delete capacity test records
- Battery.tested_capacity_mah/tested_date kept in sync with latest test
  so dashboard display requires no changes
- Battery detail: Capacity History card with sortable table, health %
  per reading, and a canvas line chart (shown when >= 2 records)
- Chart uses CSS variables for colors — works in light and dark mode
- Remove tested_capacity_mah/tested_date from Edit Details form
- 3 new acceptance tests (48 total)
This commit is contained in:
2026-04-13 04:15:55 -05:00
parent 86fb342b0d
commit 2f8a8a2b77
4 changed files with 239 additions and 16 deletions
+27
View File
@@ -480,6 +480,33 @@ def test_edit_device_type(client):
assert b"Flashlight" in resp.data
def test_add_capacity_test(client):
client.post("/battery/add", data={"brand": "Eneloop", "count": "1"})
resp = client.post("/battery/1/capacity-test/add",
data={"tested_capacity_mah": "1900", "tested_date": "2026-01-01"},
follow_redirects=True)
assert resp.status_code == 200
assert b"1900" in resp.data
def test_capacity_test_syncs_battery(client):
"""Adding a test updates battery.tested_capacity_mah."""
client.post("/battery/add", data={"brand": "Eneloop", "count": "1"})
client.post("/battery/1/capacity-test/add",
data={"tested_capacity_mah": "1800", "tested_date": "2026-01-01"})
resp = client.get("/battery/1")
assert b"1800" in resp.data
def test_delete_capacity_test(client):
client.post("/battery/add", data={"brand": "Eneloop", "count": "1"})
client.post("/battery/1/capacity-test/add",
data={"tested_capacity_mah": "1900", "tested_date": "2026-01-01"})
resp = client.post("/battery/1/capacity-test/1/delete", follow_redirects=True)
assert resp.status_code == 200
assert b"No test records" in resp.data
def test_add_install_delete_battery(client):
client.post("/device/add", data={"name": "Gadget", "battery_slots": "1"})
client.post("/battery/add", data={"brand": "AcmeBrand", "count": "1"})