Fix IRC incoming announcements and add focus.tui default

This commit is contained in:
Storm Dragon
2026-03-25 03:24:29 -04:00
parent 57c09e0db9
commit 17dea6b026
6 changed files with 219 additions and 1 deletions

View File

@@ -0,0 +1,140 @@
"""
Unit tests for incoming text announcement behavior.
"""
import importlib.util
from pathlib import Path
from unittest.mock import Mock
import pytest
def _load_incoming_module():
module_path = (
Path(__file__).resolve().parents[2]
/ "src"
/ "fenrirscreenreader"
/ "commands"
/ "onScreenUpdate"
/ "70000-incoming.py"
)
spec = importlib.util.spec_from_file_location(
"fenrir_incoming_command", module_path
)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
@pytest.fixture
def incoming_command():
incoming_module = _load_incoming_module()
output_manager = Mock(present_text=Mock())
settings_manager = Mock()
settings_manager.get_setting_as_bool.side_effect = (
lambda section, setting: True
if (section, setting) == ("speech", "auto_read_incoming")
else False
)
settings_manager.get_setting_as_float.side_effect = (
lambda section, setting: {
("speech", "rapid_update_window"): 0.3,
("speech", "batch_flush_interval"): 0.5,
}[(section, setting)]
)
settings_manager.get_setting_as_int.side_effect = (
lambda section, setting: {
("speech", "rapid_update_threshold"): 5,
("speech", "flood_line_threshold"): 500,
("speech", "max_batch_lines"): 100,
}[(section, setting)]
)
env = {
"runtime": {
"OutputManager": output_manager,
"SettingsManager": settings_manager,
"ScreenManager": Mock(
is_delta=Mock(return_value=True),
is_screen_change=Mock(return_value=False),
),
},
"screen": {
"new_delta": "",
"old_content_text": "",
"new_content_text": "",
"old_cursor": {"x": 0, "y": 0},
"new_cursor": {"x": 0, "y": 0},
"newNegativeDelta": "",
},
"commandBuffer": {},
}
command = incoming_module.command()
command.initialize(env)
return command, env, output_manager
@pytest.mark.unit
class TestIncomingCommand:
"""Test incoming text filtering for chat-like screen updates."""
def test_prefers_inserted_chat_line_over_changed_headers(
self, incoming_command
):
command, env, output_manager = incoming_command
env["screen"]["old_content_text"] = "\n".join(
[
"Status old",
"Users old",
"alice: hi",
"bob: hello",
"> ",
]
)
env["screen"]["new_content_text"] = "\n".join(
[
"Status new",
"Users new",
"bob: hello",
"carol: test",
"> ",
]
)
env["screen"]["new_delta"] = "\n".join(
["Status new", "Users new", "carol: test"]
)
command.run()
output_manager.present_text.assert_called_once_with(
"carol: test", interrupt=False, flush=False
)
def test_keeps_header_update_when_no_lower_screen_insert_exists(
self, incoming_command
):
command, env, output_manager = incoming_command
env["screen"]["old_content_text"] = "\n".join(
[
"Status old",
"Users old",
"alice: hi",
"bob: hello",
]
)
env["screen"]["new_content_text"] = "\n".join(
[
"Status new",
"Users new",
"alice: hi",
"bob: hello",
]
)
env["screen"]["new_delta"] = "\n".join(["Status new", "Users new"])
command.run()
output_manager.present_text.assert_called_once_with(
"Status new\nUsers new", interrupt=False, flush=False
)

View File

@@ -10,6 +10,7 @@ import sys
from pathlib import Path
# Import the settings manager
from fenrirscreenreader.core.settingsData import settings_data
from fenrirscreenreader.core.settingsManager import SettingsManager
@@ -186,3 +187,10 @@ class TestValidationSkipsUnknownSettings:
"""Unknown settings in known sections should not raise errors."""
# Should not raise - only specific critical settings are validated
self.manager._validate_setting_value("speech", "unknown_setting", "value")
@pytest.mark.unit
@pytest.mark.settings
def test_focus_settings_define_tui_toggle():
"""Focus settings should include the TUI toggle used by on-screen handlers."""
assert settings_data["focus"]["tui"] is False