diff options
Diffstat (limited to 'test_llamachat.py')
| -rwxr-xr-x | test_llamachat.py | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/test_llamachat.py b/test_llamachat.py index 7707b7b..ae2b478 100755 --- a/test_llamachat.py +++ b/test_llamachat.py @@ -579,6 +579,81 @@ def test_prompt_column_migration(): print("ok prompt column migration") +def test_sidebar_toggle(): + """The history panel hides, restores its width, and persists.""" + os.environ.setdefault("QT_QPA_PLATFORM", "offscreen") + from PySide6.QtWidgets import QApplication + + from llamachat import backend as _backend + from llamachat import config as _config + from llamachat.ui import ChatWindow + + app = QApplication.instance() or QApplication([]) + assert app is not None + + with tempfile.TemporaryDirectory() as tmp: + cfg = _config.load(Path(tmp) / "config.toml") + cfg.prompts_dir = Path(tmp) / "prompts" + cfg.db_path = Path(tmp) / "t.db" + # state_path already points inside tmp, since it is derived from the + # config path, so these checks cannot touch the real saved layout. + assert cfg.state_path.parent == Path(tmp), cfg.state_path + + history = db.History(cfg.db_path) + client = _backend.Client(cfg.base_url) + presets = _config.parse_presets(cfg.presets_path) + + window = ChatWindow(cfg, history, client, presets) + window.resize(1000, 700) + + # The shortcut must be registered on the window itself. + shortcuts = [ + a.shortcut().toString() + for a in window.actions() + if not a.shortcut().isEmpty() + ] + assert "Ctrl+\\" in shortcuts, shortcuts + + window.show() + assert window.sidebar_visible() + assert window.sidebar_button.isChecked() + + window.toggle_sidebar() + assert not window.sidebar_visible() + assert not window.sidebar_button.isChecked() + + window.toggle_sidebar() + assert window.sidebar_visible() + + # The width survives a hide/show rather than snapping to a default. + window.splitter.setSizes([333, 667]) + app.processEvents() + window.toggle_sidebar() + window.toggle_sidebar() + assert window.sidebar_width == 333, window.sidebar_width + + # Driving the button directly must take the same path. + window.sidebar_button.setChecked(False) + app.processEvents() + assert not window.sidebar_visible() + window.sidebar_button.setChecked(True) + app.processEvents() + assert window.sidebar_visible() + assert window.sidebar_width == 333, window.sidebar_width + + # Hidden state and width must come back on the next start. + window.sidebar_button.setChecked(False) + window._save_layout() + restored = ChatWindow(cfg, history, client, presets) + assert not restored.sidebar_button.isChecked() + assert restored.sidebar_width == 333, restored.sidebar_width + + restored.close() + window.close() + history.close() + print("ok sidebar toggle") + + def test_version_matches_changelog(): """The package version must be the newest release in the changelog.""" import re @@ -682,6 +757,7 @@ if __name__ == "__main__": test_session_prompt_storage() test_prompt_column_migration() test_markdown_rendering() + test_sidebar_toggle() test_system_qt_theme_guard() test_version_matches_changelog() test_venv_discovery() |
