diff options
| author | Danilo M. <danix@danix.xyz> | 2026-07-31 11:24:58 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-07-31 11:24:58 +0200 |
| commit | e1105f76e127bf8c19511a7494a7c1331181b9dc (patch) | |
| tree | f0f8f72205778c413507c52b5b7b2cbb44681e71 /test_llamachat.py | |
| parent | 9182c84b8ac9d905a9d553b95155a993338568b8 (diff) | |
| download | llamachat-e1105f76e127bf8c19511a7494a7c1331181b9dc.tar.gz llamachat-e1105f76e127bf8c19511a7494a7c1331181b9dc.zip | |
feat: add a history panel toggle
The history panel now hides, on the ☰ button in the top bar and on Ctrl+\.
Its width is captured before hiding and reapplied on show, so toggling does
not snap the panel back to a default. Both the width and whether it was
hidden persist between runs.
Layout state lives in state.ini beside the config rather than at QSettings'
default path, which keeps it obvious where it is and lets the checks point
it somewhere temporary instead of writing to the real one.
The button's checked state, not isVisible(), is the authority for whether
the panel is shown: isVisible() is False for every child of a window that
has not been mapped yet, so consulting it during startup would disagree
with what the user sees.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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() |
