from unittest.mock import Mock import pytest from fenrirscreenreader.core.screenManager import ScreenManager def _build_screen_manager(old_text, old_cursor): manager = ScreenManager() env = { "runtime": { "AttributeManager": Mock( reset_attributes=Mock(), reset_attribute_cursor=Mock(), set_attributes=Mock(), reset_attribute_delta=Mock(), is_attribute_change=Mock(return_value=False), ), "CursorManager": Mock(is_application_window_set=Mock(return_value=False)), "DebugManager": Mock(write_debug_out=Mock()), "ScreenManager": manager, "SettingsManager": Mock(get_setting_as_bool=Mock(return_value=False)), }, "screen": { "newContentBytes": b"", "oldContentBytes": b"", "new_content_text": old_text, "old_content_text": "", "new_cursor": old_cursor.copy(), "old_cursor": {"x": 0, "y": 0}, "new_delta": "", "new_delta_is_typing": False, "oldDelta": "", "newNegativeDelta": "", "oldNegativeDelta": "", "oldTTY": "pty", "newTTY": "pty", }, } manager.initialize = Mock() manager.env = env return manager, env @pytest.mark.unit def test_prompt_repaint_during_typing_keeps_only_typed_delta(): manager, env = _build_screen_manager("[0] ", {"x": 4, "y": 0}) manager.update( { "bytes": b"[1] h", "lines": 1, "columns": 20, "textCursor": {"x": 5, "y": 0}, "screen": "pty", "text": "[1] h", "attributes": [], }, "onScreenUpdate", ) assert env["screen"]["new_delta"] == "h" assert env["screen"]["new_delta_is_typing"] is True