test(ctx): Add integration test for Preview button with real FileItems
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user