"""Тесты favicon и прочих вставок в
."""
from __future__ import annotations
import unittest
from flask import Response, make_response
from app.html_head_injects import apply_html_head_injects, inject_favicon_html
class HtmlHeadInjectsTests(unittest.TestCase):
def test_inject_favicon_into_head(self) -> None:
html = "x"
out = inject_favicon_html(html)
self.assertIn('rel="icon"', out)
self.assertIn('href="/static/favicon.svg"', out)
self.assertIn("apple-touch-icon", out)
def test_inject_favicon_idempotent(self) -> None:
html = (
''
''
"x"
)
out = inject_favicon_html(html)
self.assertEqual(out.count('rel="icon"'), 1)
self.assertIn("/custom.ico", out)
def test_apply_on_make_response(self) -> None:
from flask import Flask
app = Flask(__name__)
html = "x"
with app.app_context():
resp = make_response(html)
out = apply_html_head_injects(resp, "/login")
body = out.get_data(as_text=True)
self.assertIn('rel="icon"', body)
def test_kiosk_cursor_hidden_on_calibration_path(self) -> None:
from flask import Flask
app = Flask(__name__)
app.config["WESP_KIOSK_HIDE_CURSOR"] = True
html = "x"
with app.app_context():
resp = make_response(html)
out = apply_html_head_injects(resp, "/calibration")
body = out.get_data(as_text=True)
self.assertIn("kiosk-cursor.css", body)
self.assertIn("wesp-kiosk-hide-cursor", body)
def test_kiosk_cursor_visible_on_scales_path(self) -> None:
from flask import Flask
app = Flask(__name__)
app.config["WESP_KIOSK_HIDE_CURSOR"] = True
html = "x"
with app.app_context():
resp = make_response(html)
out = apply_html_head_injects(resp, "/scales")
body = out.get_data(as_text=True)
self.assertNotIn("kiosk-cursor.css", body)
self.assertNotIn("wesp-kiosk-hide-cursor", body)
def test_apply_skips_direct_passthrough(self) -> None:
resp = Response(
"x",
mimetype="text/html",
direct_passthrough=True,
)
out = apply_html_head_injects(resp, "/login")
self.assertIs(out, resp)
if __name__ == "__main__":
unittest.main()