import pytest from unittest.mock import Mock from pathlib import Path from src.gui_2 import App from src.models import FileItem def test_preview_button_syncs_context_files_to_controller(): app = Mock(spec=App) app.context_files = [FileItem(path='test.py', view_mode='summary')] app.files = [] app.controller = Mock() app.controller.context_files = [] app.controller._do_generate.return_value = ('# Test Content', Path('.'), [], '', '') app.show_windows = {'Context Preview': False} app.ui_selected_context_files = set() from src.gui_2 import render_context_batch_actions import unittest.mock as mock with mock.patch('src.gui_2.imgui') as mock_imgui: mock_imgui.button.return_value = True mock_imgui.same_line = mock.Mock() mock_imgui.text = mock.Mock() mock_imgui.open_popup = mock.Mock() render_context_batch_actions(app, 100, 50) assert len(app.controller.context_files) == 1 assert app.controller.context_files[0].path == 'test.py' def test_preview_button_empty_state_message(): app = Mock(spec=App) app.context_files = [] app.files = [] app.controller = Mock() app.controller.context_files = [] app.controller._do_generate.return_value = ('', Path('.'), [], '', '') app.show_windows = {'Context Preview': False} app.context_preview_text = None app.ui_selected_context_files = set() from src.gui_2 import render_context_batch_actions import unittest.mock as mock with mock.patch('src.gui_2.imgui') as mock_imgui: mock_imgui.button.return_value = True mock_imgui.same_line = mock.Mock() mock_imgui.text = mock.Mock() mock_imgui.open_popup = mock.Mock() render_context_batch_actions(app, 0, 0) assert app.context_preview_text == '' or 'No files' in str(app.context_preview_text) def test_text_viewer_window_invoked_in_render_loop(): import src.gui_2 as gui_2 assert hasattr(gui_2, 'render_text_viewer_window'), "render_text_viewer_window function must exist" assert callable(gui_2.render_text_viewer_window), "render_text_viewer_window must be callable" import re with open('src/gui_2.py', 'r', encoding='utf-8', newline='') as f: content = f.read() call_pattern = r'render_text_viewer_window\(app\)' matches = list(re.finditer(call_pattern, content)) assert len(matches) >= 2, f"render_text_viewer_window should be called at least 2 times (once in window, once in modal hook), found {len(matches)}" if __name__ == '__main__': pytest.main([__file__, '-v'])