df6aa1f455
- Update Text Viewer window ID to '###Text_Viewer_Unified'. - Ensures ImGui treats the window as a single stable entity across title changes. - Prevents docking loop glitches.
55 lines
1.8 KiB
Python
55 lines
1.8 KiB
Python
import pytest
|
|
from unittest.mock import patch, MagicMock
|
|
from src.gui_2 import render_text_viewer_window
|
|
|
|
def test_text_viewer_window_id_stability():
|
|
# Setup a mock app with necessary state
|
|
app = MagicMock()
|
|
app.show_windows = {"Text Viewer": True}
|
|
app.text_viewer_title = "Custom Title"
|
|
app.text_viewer_content = "Some content"
|
|
app.text_viewer_type = "text"
|
|
app.ui_editing_slices_file = None
|
|
|
|
# Patch all dependencies
|
|
with patch('src.gui_2.imgui') as mock_imgui, \
|
|
patch('src.gui_2.markdown_helper') as mock_md, \
|
|
patch('src.gui_2.imscope') as mock_scope:
|
|
|
|
# Setup mock returns
|
|
mock_imgui.begin.return_value = (True, True)
|
|
mock_imgui.checkbox.return_value = (False, True)
|
|
|
|
render_text_viewer_window(app)
|
|
|
|
# Verify imgui.begin was called with the stable ID suffix
|
|
args, _ = mock_imgui.begin.call_args
|
|
window_title = args[0]
|
|
assert "###Text_Viewer_Unified" in window_title
|
|
assert window_title.startswith("Custom Title")
|
|
|
|
def test_text_viewer_window_default_title_id_stability():
|
|
# Setup a mock app with default title (None)
|
|
app = MagicMock()
|
|
app.show_windows = {"Text Viewer": True}
|
|
app.text_viewer_title = None
|
|
app.text_viewer_content = "Some content"
|
|
app.text_viewer_type = "text"
|
|
app.ui_editing_slices_file = None
|
|
|
|
with patch('src.gui_2.imgui') as mock_imgui, \
|
|
patch('src.gui_2.markdown_helper') as mock_md, \
|
|
patch('src.gui_2.imscope') as mock_scope:
|
|
|
|
# Setup mock returns
|
|
mock_imgui.begin.return_value = (True, True)
|
|
mock_imgui.checkbox.return_value = (False, True)
|
|
|
|
render_text_viewer_window(app)
|
|
|
|
# Verify imgui.begin was called with the stable ID suffix
|
|
args, _ = mock_imgui.begin.call_args
|
|
window_title = args[0]
|
|
assert "###Text_Viewer_Unified" in window_title
|
|
assert window_title.startswith("Text Viewer")
|