feat: add realtime Gitea event stream widget
This commit is contained in:
1 parent
0fc4b2684e
commit
9df3815417
4 files changed
+112
-1
No files matched your search
@@ -0,0 +1,64 @@
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from src import main
|
||||
from src import gitea_proxy
|
||||
|
||||
|
||||
DASHBOARD = Path("frontend/index.html")
|
||||
|
||||
|
||||
def test_dashboard_has_realtime_gitea_event_stream_widget():
|
||||
html = DASHBOARD.read_text()
|
||||
|
||||
assert "Gitea event stream" in html
|
||||
assert "id=\"gitea-events\"" in html
|
||||
assert "function paintEventStream" in html
|
||||
assert "setInterval(loadEventStream, 5000)" in html
|
||||
assert "event.actor?.login" in html
|
||||
assert "event.repo?.full_name" in html
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_event_stream_returns_recent_authenticated_gitea_activity(monkeypatch):
|
||||
expected = [{"type": "create", "actor": {"login": "timmy"}}]
|
||||
|
||||
async def fake_activity_events():
|
||||
return expected
|
||||
|
||||
monkeypatch.setattr(main, "activity_events", fake_activity_events)
|
||||
|
||||
response = await main.event_stream()
|
||||
|
||||
assert response == expected
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_activity_events_fetches_feed_for_authenticated_user(monkeypatch):
|
||||
paths = []
|
||||
|
||||
async def fake_current_user():
|
||||
return {"login": "timmy"}
|
||||
|
||||
async def fake_fetch(path):
|
||||
paths.append(path)
|
||||
return [{
|
||||
"op_type": "push",
|
||||
"act_user": {"login": "timmy"},
|
||||
"repo": {"full_name": "stackchain/stackchain-dashboard"},
|
||||
"created": "2026-08-05T03:00:00Z",
|
||||
}]
|
||||
|
||||
monkeypatch.setattr(gitea_proxy, "current_user", fake_current_user)
|
||||
monkeypatch.setattr(gitea_proxy, "fetch", fake_fetch)
|
||||
|
||||
result = await gitea_proxy.activity_events()
|
||||
|
||||
assert result == [{
|
||||
"type": "push",
|
||||
"actor": {"login": "timmy"},
|
||||
"repo": {"full_name": "stackchain/stackchain-dashboard"},
|
||||
"created_at": "2026-08-05T03:00:00Z",
|
||||
}]
|
||||
assert paths == ["users/timmy/activities/feeds?limit=20"]
|
||||
Reference in new issue
Block a user