@@ -33,6 +33,35 @@ def fire(self):
3333 self .callback (* self .args )
3434
3535
36+ class FakeCairoContext :
37+ def __init__ (self ):
38+ self .shown_text = []
39+
40+ def select_font_face (self , * args ):
41+ pass
42+
43+ def set_font_size (self , * args ):
44+ pass
45+
46+ def text_extents (self , text ):
47+ return (0 , 0 , len (text ) * 5 , 10 , 0 , 0 )
48+
49+ def set_source_rgba (self , * args ):
50+ pass
51+
52+ def rectangle (self , * args ):
53+ pass
54+
55+ def fill (self ):
56+ pass
57+
58+ def move_to (self , * args ):
59+ pass
60+
61+ def show_text (self , text ):
62+ self .shown_text .append (text )
63+
64+
3665class MicOSDRunnerTests (unittest .TestCase ):
3766 def _import_window_with_stubs (self ):
3867 for module_name in ("mic_osd.window" ,):
@@ -219,6 +248,22 @@ def text_extents(self, text):
219248 self .assertEqual (window ._text_width (ObjectContext (), "abcd" ), 20 )
220249 self .assertEqual (window ._text_height (ObjectContext (), "abcd" ), 10 )
221250
251+ def test_preview_text_draws_only_while_recording (self ):
252+ window_module , _ = self ._import_window_with_stubs ()
253+ window = object .__new__ (window_module .OSDWindow )
254+ window ._preview_text = "live partial"
255+ window ._visualizer_state = "processing"
256+
257+ processing_cr = FakeCairoContext ()
258+ window ._draw_preview_text (processing_cr , 400 , 68 )
259+
260+ window ._visualizer_state = "recording"
261+ recording_cr = FakeCairoContext ()
262+ window ._draw_preview_text (recording_cr , 400 , 68 )
263+
264+ self .assertEqual (processing_cr .shown_text , [])
265+ self .assertEqual (recording_cr .shown_text , ["live partial" ])
266+
222267 def test_preview_text_preserves_spaces_but_trims_newlines (self ):
223268 with tempfile .TemporaryDirectory () as tmp :
224269 preview_file = Path (tmp ) / "hyprwhspr" / "transcript_preview"
0 commit comments