4d8e949720
- Insert imgui.new_line() before rendering discussion content. - Ensures the Markdown renderer inherits the full horizontal width of the panel. - Definitively fixes vertical squashing of tables and long text blocks.
84 lines
2.9 KiB
Python
84 lines
2.9 KiB
Python
import unittest
|
|
from unittest.mock import MagicMock, patch
|
|
import sys
|
|
import os
|
|
|
|
# Ensure project root is in path so we can import src.gui_2
|
|
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
|
|
if project_root not in sys.path:
|
|
sys.path.insert(0, project_root)
|
|
|
|
class TestMarkdownTableWidth(unittest.TestCase):
|
|
def test_render_discussion_entry_full_width(self):
|
|
"""
|
|
Verify that render_discussion_entry calls imgui.dummy with the full available width.
|
|
This is critical for ensuring that the background and Markdown content expand to
|
|
the full width of the discussion panel.
|
|
"""
|
|
# Mock all dependencies to avoid side effects and complex setup during import/execution
|
|
with patch('src.gui_2.imgui') as mock_imgui, \
|
|
patch('src.gui_2.imscope') as mock_imscope, \
|
|
patch('src.gui_2.theme') as mock_theme, \
|
|
patch('src.gui_2.ui_shared') as mock_ui_shared, \
|
|
patch('src.gui_2.project_manager') as mock_pm, \
|
|
patch('src.gui_2.render_thinking_trace') as mock_rtt, \
|
|
patch('src.gui_2.render_discussion_entry_read_mode') as mock_rderm:
|
|
|
|
# 1. Setup available width and coordinates
|
|
expected_width = 850.0
|
|
mock_avail = MagicMock()
|
|
mock_avail.x = expected_width
|
|
mock_imgui.get_content_region_avail.return_value = mock_avail
|
|
|
|
# Mock ImVec2 to return a simple tuple for easier assertion
|
|
mock_imgui.ImVec2.side_effect = lambda x, y: (x, y)
|
|
|
|
# Mock screen position
|
|
mock_p_min = MagicMock()
|
|
mock_p_min.x = 100.0
|
|
mock_p_min.y = 200.0
|
|
mock_imgui.get_cursor_screen_pos.return_value = mock_p_min
|
|
|
|
# Mock rect max
|
|
mock_p_max = MagicMock()
|
|
mock_imgui.get_item_rect_max.return_value = mock_p_max
|
|
|
|
# 2. Mock drawing and style dependencies
|
|
mock_draw_list = MagicMock()
|
|
mock_imgui.get_window_draw_list.return_value = mock_draw_list
|
|
|
|
mock_style = MagicMock()
|
|
mock_style.window_padding.x = 10.0
|
|
mock_imgui.get_style.return_value = mock_style
|
|
|
|
# 3. Mock app and entry state
|
|
mock_app = MagicMock()
|
|
mock_app.disc_roles = ["User", "Assistant"]
|
|
|
|
entry = {
|
|
"role": "User",
|
|
"content": "Hello world",
|
|
"collapsed": False,
|
|
"read_mode": False
|
|
}
|
|
|
|
# Mock combo and other interactive elements to prevent deep branching
|
|
mock_imgui.begin_combo.return_value = False
|
|
mock_imgui.button.return_value = False
|
|
mock_imgui.input_text_multiline.return_value = (False, entry["content"])
|
|
|
|
# 4. Import the function within the patch context
|
|
# Note: We import here to ensure mocks are in place during module initialization if needed
|
|
from src.gui_2 import render_discussion_entry
|
|
|
|
# 5. Execute the function
|
|
render_discussion_entry(mock_app, entry, 0)
|
|
|
|
# 6. Verification
|
|
# The function should call imgui.dummy(imgui.ImVec2(full_width, 0)) at line 3153
|
|
# Our mock ImVec2 returns (full_width, 0)
|
|
mock_imgui.dummy.assert_any_call((expected_width, 0.0))
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|