Files
frigate-camera-control-bridge/tests/test_ui_render.py
T
2026-08-03 01:05:11 +02:00

67 lines
2.1 KiB
Python

import unittest
from frigate_camera_control_bridge.ui import render_page
class DummyAction:
def __init__(self, suffix="siren", name_key="action.siren", state="ON", kind="dahua_coaxial_io"):
self.id = f"example_camera_{suffix}"
self.platform = "switch"
self.kind = kind
self.state = state
self.auto_off_seconds = 180
self.auto_off_at = 1234567890
self.cfg = {
"name_key": name_key,
"camera_name": "Example camera",
"requires_ack": name_key == "action.siren",
"snapshot": {
"camera": "example",
"frigate_url": "http://frigate.example.test:5000",
},
}
def display_name(self, lang):
return f"Example {self.id}"
def command_list(self):
return ["on", "off"]
class UiRenderTest(unittest.TestCase):
def test_timer_timestamp_and_ack_survive_server_render(self):
html = render_page([DummyAction()], "en")
self.assertIn('data-auto-off-at="1234567890"', html)
self.assertIn('data-requires-ack="true"', html)
self.assertIn("Example camera", html)
def test_controls_from_same_camera_share_one_card(self):
actions = [
DummyAction("siren", "action.siren"),
DummyAction("white", "action.manual_white", state="OFF"),
DummyAction("red_blue", "action.red_blue", state="OFF"),
]
html = render_page(actions, "en")
self.assertEqual(html.count('class="camera-card"'), 1)
self.assertEqual(html.count('class="action-control"'), 3)
self.assertIn("3 controls", html)
self.assertIn("White light", html)
self.assertIn("Red-blue light", html)
self.assertIn("Siren", html)
def test_all_off_renders_in_topbar_not_camera_grid(self):
action = DummyAction("all_off", "action.all_off", state=None, kind="all_off")
html = render_page([action], "en")
self.assertIn('class="global-strip"', html)
self.assertIn('class="global-action"', html)
self.assertNotIn('class="camera-card"', html)
if __name__ == "__main__":
unittest.main()