Private
Public Access
0
0

test(ctx): Add integration test for Preview button with real FileItems

This commit is contained in:
2026-05-16 17:55:23 -04:00
parent e1e4571c68
commit c7f5b6801f
+43
View File
@@ -46,6 +46,49 @@ def test_preview_button_empty_state_message():
render_context_batch_actions(app, 0, 0)
assert app.context_preview_text == '' or 'No files' in str(app.context_preview_text)
def test_preview_generates_nonempty_for_real_files(monkeypatch):
"""Integration test: Preview button should generate content when context_files has real FileItems."""
import src.project_manager as pm
import src.aggregate as agg
from src.models import FileItem
app = Mock(spec=App)
test_file = FileItem(path='tests/test_context_composition_decoupled.py', view_mode='summary')
app.context_files = [test_file]
app.files = []
app.controller = Mock()
app.controller.context_files = []
app.show_windows = {'Context Preview': False}
app.ui_selected_context_files = set()
def mock_flat_config(*args, **kwargs):
return {'files': {}, 'project': {}, 'output': {'output_dir': 'tests/artifacts'}, 'discussion': {'history': []}}
def mock_aggregate_run(flat, **kwargs):
paths = flat['files']['paths']
assert len(paths) == 1
assert paths[0].path == 'tests/test_context_composition_decoupled.py'
return ('Generated Markdown Content', Path('tests/artifacts/output.md'), [])
app.controller._do_generate.return_value = ('Generated Markdown Content', Path('tests/artifacts/output.md'), [], '', '')
monkeypatch.setattr(pm, 'flat_config', mock_flat_config)
monkeypatch.setattr(pm, 'save_project', lambda *args: None)
monkeypatch.setattr(agg, 'run', mock_aggregate_run)
monkeypatch.setattr(agg, 'build_markdown_no_history', lambda *args, **kwargs: 'stable')
monkeypatch.setattr(agg, 'build_discussion_text', lambda *args, **kwargs: 'disc')
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 app.context_preview_text == 'Generated Markdown Content'
assert app.controller.context_files == app.context_files
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"