GitHub Actions commited on
Commit
cbff2cf
·
1 Parent(s): a8b67a8

test: add comprehensive easter egg tests

Browse files

Added tests to verify easter egg ticker is properly implemented:
- Script injected via Blocks head parameter (executes in browser)
- HTML/CSS in gr.HTML() component (no script tags)
- Event listener checks for 'e' key (both lowercase and uppercase)
- Guards against INPUT/TEXTAREA to prevent triggering while typing
- Retry logic for DOM element initialization
- Ticker toggles .active class for animation

Also fixed: removed extra triple-quote causing syntax error in app.py

hearthnet/ui/__pycache__/app.cpython-313.pyc CHANGED
Binary files a/hearthnet/ui/__pycache__/app.cpython-313.pyc and b/hearthnet/ui/__pycache__/app.cpython-313.pyc differ
 
hearthnet/ui/app.py CHANGED
@@ -117,7 +117,6 @@ _EASTER_EGG_SCRIPT = """
117
  })();
118
  </script>
119
  """
120
- """
121
 
122
 
123
  class UiApp:
 
117
  })();
118
  </script>
119
  """
 
120
 
121
 
122
  class UiApp:
tests/test_easter_egg.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Test easter egg functionality in Gradio UI."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import re
6
+
7
+
8
+ def test_easter_egg_implementation():
9
+ """Verify easter egg ticker is properly implemented in app.py.
10
+
11
+ Tests that:
12
+ 1. Script is injected via head parameter (not innerHTML)
13
+ 2. HTML/CSS is in gr.HTML() component
14
+ 3. Event listener checks for 'e' key
15
+ 4. Guards against INPUT/TEXTAREA elements
16
+ """
17
+ from hearthnet.ui.app import _EASTER_EGG_SCRIPT, _EASTER_EGG_CSS
18
+
19
+ # Verify CSS contains the ticker styling
20
+ assert ".egg-ticker" in _EASTER_EGG_CSS, "CSS missing .egg-ticker class"
21
+ assert ".egg-ticker.active" in _EASTER_EGG_CSS, "CSS missing .egg-ticker.active state"
22
+ assert "@keyframes scroll" in _EASTER_EGG_CSS, "CSS missing scroll animation"
23
+
24
+ # Verify HTML contains the ticker element
25
+ assert 'id="egg-ticker"' in _EASTER_EGG_CSS, "HTML missing egg-ticker id"
26
+ assert "⚡ LIVE" in _EASTER_EGG_CSS, "HTML missing LIVE label"
27
+ assert 'id="egg-track"' in _EASTER_EGG_CSS, "HTML missing egg-track id"
28
+
29
+ # Verify script is injected via head parameter (must contain <script> tag)
30
+ assert "<script>" in _EASTER_EGG_SCRIPT, "Script must be wrapped in <script> tag for head parameter"
31
+ assert "</script>" in _EASTER_EGG_SCRIPT, "Script must have closing </script> tag"
32
+
33
+ # Verify keydown listener
34
+ assert "evt.key === 'e'" in _EASTER_EGG_SCRIPT, "Script missing 'e' key check (lowercase)"
35
+ assert "evt.key === 'E'" in _EASTER_EGG_SCRIPT, "Script missing 'E' key check (uppercase)"
36
+
37
+ # Verify input guard
38
+ assert "'INPUT'" in _EASTER_EGG_SCRIPT, "Script missing INPUT guard"
39
+ assert "'TEXTAREA'" in _EASTER_EGG_SCRIPT, "Script missing TEXTAREA guard"
40
+
41
+ # Verify toggle function
42
+ assert "toggleEasterEgg" in _EASTER_EGG_SCRIPT, "Script missing toggleEasterEgg function"
43
+ assert ".active" in _EASTER_EGG_SCRIPT, "Script not toggling .active class"
44
+
45
+ # Verify retry logic for DOM element
46
+ assert "initEasterEgg" in _EASTER_EGG_SCRIPT, "Script missing initEasterEgg function"
47
+ assert "setTimeout(initEasterEgg" in _EASTER_EGG_SCRIPT, "Script missing retry logic for DOM"
48
+
49
+ # Verify script is injected in Blocks head parameter
50
+ from hearthnet.ui.app import UiApp
51
+ import inspect
52
+
53
+ build_code = inspect.getsource(UiApp.build)
54
+ assert "head=_EASTER_EGG_SCRIPT" in build_code, "Script not injected via head parameter in Blocks"
55
+ assert "gr.HTML(value=_EASTER_EGG_CSS)" in build_code, "CSS not injected via gr.HTML()"
56
+
57
+
58
+ def test_easter_egg_no_script_in_html():
59
+ """Verify script is NOT embedded in gr.HTML() to avoid Gradio warning."""
60
+ from hearthnet.ui.app import _EASTER_EGG_CSS, _EASTER_EGG_SCRIPT
61
+
62
+ # CSS should NOT contain script tags (they go to head parameter)
63
+ assert "<script>" not in _EASTER_EGG_CSS, "CSS component should not contain script (goes to head parameter)"
64
+
65
+ # Script should be separate
66
+ assert len(_EASTER_EGG_SCRIPT) > 0, "Script must exist"
67
+ assert "<script>" in _EASTER_EGG_SCRIPT, "Script must be in _EASTER_EGG_SCRIPT constant"