Add recent events and stats to eggs, feed, and move forms
All checks were successful
Deploy / deploy (push) Successful in 2m40s

- Create recent_events.py helper for rendering event lists with humanized
  timestamps and deleted event styling (line-through + opacity)
- Query events with ORDER BY ts_utc DESC to show newest first
- Join event_tombstones to detect deleted events
- Fix move form to read animal_ids (not resolved_ids) from entity_refs
- Fix feed purchase format to use total_kg from entity_refs
- Use hx_get with #event-panel-content target for slide-over panel
- Add days-since-last stats for move and feed forms

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-08 21:10:09 +00:00
parent 62cc6c07d1
commit e42eede010
11 changed files with 1102 additions and 33 deletions

View File

@@ -360,3 +360,99 @@ class TestInventoryWarning:
assert resp.status_code in [200, 302, 303]
# The response should contain a warning about negative inventory
assert "warning" in resp.text.lower() or "negative" in resp.text.lower()
class TestFeedRecentEvents:
"""Tests for recent events display on feed page."""
def test_give_tab_shows_recent_events_section(self, client):
"""Give Feed tab shows Recent Feed Given section."""
resp = client.get("/feed")
assert resp.status_code == 200
assert "Recent Feed Given" in resp.text
def test_purchase_tab_shows_recent_events_section(self, client):
"""Purchase Feed tab shows Recent Purchases section."""
resp = client.get("/feed?tab=purchase")
assert resp.status_code == 200
assert "Recent Purchases" in resp.text
def test_give_feed_event_appears_in_recent(
self, client, seeded_db, location_strip1_id, feed_purchase_in_db
):
"""Newly created feed given event appears in recent events list."""
resp = client.post(
"/actions/feed-given",
data={
"location_id": location_strip1_id,
"feed_type_code": "layer",
"amount_kg": "5",
"nonce": "test-nonce-recent-feed-1",
},
)
assert resp.status_code == 200
# Recent events should include the newly created event
assert "/events/" in resp.text
def test_give_feed_event_links_to_detail(
self, client, seeded_db, location_strip1_id, feed_purchase_in_db
):
"""Feed given events in recent list link to event detail page."""
resp = client.post(
"/actions/feed-given",
data={
"location_id": location_strip1_id,
"feed_type_code": "layer",
"amount_kg": "5",
"nonce": "test-nonce-recent-feed-2",
},
)
assert resp.status_code == 200
# Get the event ID from DB
event_row = seeded_db.execute(
"SELECT id FROM events WHERE type = 'FeedGiven' ORDER BY id DESC LIMIT 1"
).fetchone()
event_id = event_row[0]
# The response should contain a link to the event detail
assert f"/events/{event_id}" in resp.text
def test_purchase_event_appears_in_recent(self, client, seeded_db):
"""Newly created purchase event appears in recent events list."""
resp = client.post(
"/actions/feed-purchased",
data={
"feed_type_code": "layer",
"bag_size_kg": "20",
"bags_count": "2",
"bag_price_euros": "24.00",
"nonce": "test-nonce-recent-purchase-1",
},
)
# The route returns purchase tab active after purchase
assert resp.status_code == 200
assert "/events/" in resp.text
def test_purchase_event_links_to_detail(self, client, seeded_db):
"""Purchase events in recent list link to event detail page."""
resp = client.post(
"/actions/feed-purchased",
data={
"feed_type_code": "layer",
"bag_size_kg": "20",
"bags_count": "2",
"bag_price_euros": "24.00",
"nonce": "test-nonce-recent-purchase-2",
},
)
assert resp.status_code == 200
# Get the event ID from DB
event_row = seeded_db.execute(
"SELECT id FROM events WHERE type = 'FeedPurchased' ORDER BY id DESC LIMIT 1"
).fetchone()
event_id = event_row[0]
# The response should contain a link to the event detail
assert f"/events/{event_id}" in resp.text