feat(map): geofence inbox shows cameras and the news line
Some checks failed
build-and-deploy / build-push-deploy (push) Failing after 6s
Some checks failed
build-and-deploy / build-push-deploy (push) Failing after 6s
A hit with evidence keeps the meta line and adds a second line: camera count, the first camera name, and the first headline. A non-empty news url is an anchor; an empty url stays text. Hits without evidence stay the one-liner. snapshot_url is never written into the inbox.
This commit is contained in:
parent
3f11e647f0
commit
0f91127233
2 changed files with 207 additions and 2 deletions
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import subprocess
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
|
|
@ -54,3 +57,151 @@ def test_fence_dvr_at_endpoint():
|
|||
assert "/at?timestamp=" in HTML or "/at?timestamp=${" in HTML
|
||||
assert "function dvrScrubFence" in HTML
|
||||
assert "gfSelectedId" in HTML
|
||||
|
||||
|
||||
def _inbox_src() -> str:
|
||||
news = HTML.split("function newsEsc", 1)[1].split("function newsTimeAgo", 1)[0]
|
||||
inbox = HTML.split("function gfHitTime", 1)[1].split("function onGfHitClick", 1)[0]
|
||||
return "function newsEsc" + news + "function gfHitTime" + inbox
|
||||
|
||||
|
||||
def _render_inbox(hits: list) -> list[dict]:
|
||||
harness = r"""
|
||||
const fs = require('fs');
|
||||
const src = fs.readFileSync(process.argv[2], 'utf8');
|
||||
const hits = JSON.parse(fs.readFileSync(process.argv[3], 'utf8'));
|
||||
var gfNameById = {};
|
||||
function makeBox() {
|
||||
const kids = [];
|
||||
const box = {
|
||||
children: kids,
|
||||
prepend(el) { kids.unshift(el); },
|
||||
removeChild(el) {
|
||||
const i = kids.indexOf(el);
|
||||
if (i >= 0) kids.splice(i, 1);
|
||||
},
|
||||
};
|
||||
global.document = {
|
||||
getElementById(id) { return id === 'gf-inbox' ? box : null; },
|
||||
createElement() {
|
||||
return { type: '', className: '', dataset: {}, innerHTML: '', onclick: null };
|
||||
},
|
||||
};
|
||||
return box;
|
||||
}
|
||||
eval(src);
|
||||
const out = [];
|
||||
for (const hit of hits) {
|
||||
const box = makeBox();
|
||||
pushGfInbox(hit);
|
||||
const el = box.children[0];
|
||||
out.push({
|
||||
html: el ? el.innerHTML : '',
|
||||
hasOnclick: !!(el && typeof el.onclick === 'function'),
|
||||
});
|
||||
}
|
||||
process.stdout.write(JSON.stringify(out));
|
||||
"""
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
root = Path(td)
|
||||
src_path = root / "inbox.js"
|
||||
hits_path = root / "hits.json"
|
||||
harness_path = root / "harness.js"
|
||||
src_path.write_text(_inbox_src())
|
||||
hits_path.write_text(json.dumps(hits))
|
||||
harness_path.write_text(harness)
|
||||
proc = subprocess.run(
|
||||
["node", str(harness_path), str(src_path), str(hits_path)],
|
||||
check=False,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
assert proc.returncode == 0, proc.stderr
|
||||
return json.loads(proc.stdout)
|
||||
|
||||
|
||||
def test_push_gf_inbox_evidence_pack():
|
||||
"""Second line from payload.evidence; missing evidence stays the one-liner."""
|
||||
linked = {
|
||||
"geofence_name": "Yard",
|
||||
"source_kind": "news",
|
||||
"entity_id": "n-1",
|
||||
"created_at": "2026-11-14T05:00:00Z",
|
||||
"payload": {
|
||||
"evidence": {
|
||||
"cameras": [
|
||||
{"id": "c1", "name": "North Gate", "snapshot_url": "rtsp://camera/1"},
|
||||
{"id": "c2", "name": "South Gate", "snapshot_url": "/api/cameras/c2/snapshot"},
|
||||
],
|
||||
"news": [{"headline": "Fence brief", "url": "https://ex.com/1", "importance": "high"}],
|
||||
"snapshot": "/api/geofences/g1/at?ts=2026-11-14T05:00:00Z",
|
||||
}
|
||||
},
|
||||
}
|
||||
text_news = {
|
||||
"geofence_name": "Yard",
|
||||
"source_kind": "earthquake",
|
||||
"entity_id": "eq-9",
|
||||
"payload": {
|
||||
"evidence": {
|
||||
"cameras": [],
|
||||
"news": [{"headline": "Silent quake", "url": "", "importance": ""}],
|
||||
}
|
||||
},
|
||||
}
|
||||
bare = {
|
||||
"geofence_name": "Old Fence",
|
||||
"source_kind": "adsb",
|
||||
"entity_id": "abc123",
|
||||
"payload": {"icao": "abc123"},
|
||||
}
|
||||
top_level = {
|
||||
"geofence_name": "Top",
|
||||
"source_kind": "fire_incident",
|
||||
"entity_id": "fi-1",
|
||||
"evidence": {
|
||||
"cameras": [{"id": "c9", "name": "Lot Cam", "snapshot_url": "rtsp://camera/1"}],
|
||||
"news": [{"headline": "Lot fire", "url": "https://ex.com/1", "importance": ""}],
|
||||
},
|
||||
}
|
||||
as_string = {
|
||||
"geofence_name": "String Fence",
|
||||
"source_kind": "news",
|
||||
"entity_id": "s1",
|
||||
"payload": json.dumps({
|
||||
"evidence": {
|
||||
"cameras": [{"id": "c3", "name": "Cam A", "snapshot_url": "rtsp://camera/1"}],
|
||||
"news": [{"headline": "From string", "url": "https://ex.com/1", "importance": ""}],
|
||||
}
|
||||
}),
|
||||
}
|
||||
rendered = _render_inbox([linked, text_news, bare, top_level, as_string])
|
||||
html, quiet, plain, fallback, parsed = [row["html"] for row in rendered]
|
||||
|
||||
assert "2 cams" in html
|
||||
assert "North Gate" in html
|
||||
assert 'href="https://ex.com/1"' in html
|
||||
assert 'target="_blank"' in html
|
||||
assert 'rel="noopener"' in html
|
||||
assert "stopPropagation" in html
|
||||
assert "rtsp://camera/1" not in html
|
||||
assert rendered[0]["hasOnclick"]
|
||||
|
||||
assert "Silent quake" in quiet
|
||||
assert "<a" not in quiet
|
||||
assert "Yard" in quiet
|
||||
|
||||
assert "Old Fence" in plain
|
||||
assert "adsb" in plain
|
||||
assert "abc123" in plain
|
||||
assert "cams" not in plain
|
||||
assert "<br>" not in plain
|
||||
assert rendered[2]["hasOnclick"]
|
||||
|
||||
assert "1 cams" in fallback
|
||||
assert 'href="https://ex.com/1"' in fallback
|
||||
assert "rtsp://camera/1" not in fallback
|
||||
|
||||
assert "1 cams" in parsed
|
||||
assert "From string" in parsed
|
||||
assert "rtsp://camera/1" not in parsed
|
||||
|
|
|
|||
Loading…
Reference in a new issue