import pytest import sys import os from unittest.mock import patch from typing import Generator, Any from gui_2 import App import ai_client # Ensure project root is in path sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) def test_gui_updates_on_event(app_instance: App) -> None: mock_stats = {"percentage": 50.0, "current": 500, "limit": 1000} app_instance.last_md = "mock_md" with patch.object(app_instance, '_refresh_api_metrics') as mock_refresh: # Simulate event (bypassing events.emit since _init_ai_and_hooks is mocked) app_instance._on_api_event(payload={"text": "test"}) # Process tasks manually app_instance._process_pending_gui_tasks() # Verify that _refresh_api_metrics was called mock_refresh.assert_called_once_with({"text": "test"}, md_content="mock_md")