diff options
Diffstat (limited to 'tests/test-ai-vterm--displayed-claude-window.el')
| -rw-r--r-- | tests/test-ai-vterm--displayed-claude-window.el | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/test-ai-vterm--displayed-claude-window.el b/tests/test-ai-vterm--displayed-claude-window.el new file mode 100644 index 00000000..283a1b3c --- /dev/null +++ b/tests/test-ai-vterm--displayed-claude-window.el @@ -0,0 +1,64 @@ +;;; test-ai-vterm--displayed-claude-window.el --- Tests for the displayed-window helper -*- lexical-binding: t; -*- + +;;; Commentary: +;; The helper returns a window in the selected frame whose buffer +;; satisfies `cj/--ai-vterm-buffer-p', or nil when no such window +;; exists. Used by F9 dispatch and M-F9 in-place replacement. + +;;; Code: + +(require 'ert) + +(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) +(require 'ai-vterm) + +(defun test-ai-vterm--displayed-cleanup () + "Kill any leftover claude-prefixed buffers." + (dolist (b (buffer-list)) + (when (string-prefix-p "claude [" (buffer-name b)) + (kill-buffer b)))) + +(ert-deftest test-ai-vterm--displayed-claude-window-no-buffers-returns-nil () + "Boundary: no claude buffers anywhere -> nil." + (test-ai-vterm--displayed-cleanup) + (save-window-excursion + (delete-other-windows) + (should-not (cj/--ai-vterm-displayed-claude-window)))) + +(ert-deftest test-ai-vterm--displayed-claude-window-not-displayed-returns-nil () + "Boundary: claude buffer exists but not in any window -> nil." + (test-ai-vterm--displayed-cleanup) + (let ((b1 (get-buffer-create "claude [hidden]"))) + (unwind-protect + (save-window-excursion + (delete-other-windows) + (should-not (cj/--ai-vterm-displayed-claude-window))) + (kill-buffer b1)))) + +(ert-deftest test-ai-vterm--displayed-claude-window-returns-window-when-displayed () + "Normal: claude buffer in a window -> returns that window." + (test-ai-vterm--displayed-cleanup) + (let ((b1 (get-buffer-create "claude [shown]"))) + (unwind-protect + (save-window-excursion + (delete-other-windows) + (let ((win (split-window-right))) + (set-window-buffer win b1) + (let ((result (cj/--ai-vterm-displayed-claude-window))) + (should (windowp result)) + (should (eq (window-buffer result) b1))))) + (kill-buffer b1)))) + +(ert-deftest test-ai-vterm--displayed-claude-window-ignores-non-claude-windows () + "Boundary: only a non-claude buffer is displayed -> nil." + (test-ai-vterm--displayed-cleanup) + (let ((other (get-buffer-create "regular-displayed-buffer"))) + (unwind-protect + (save-window-excursion + (delete-other-windows) + (set-window-buffer (selected-window) other) + (should-not (cj/--ai-vterm-displayed-claude-window))) + (kill-buffer other)))) + +(provide 'test-ai-vterm--displayed-claude-window) +;;; test-ai-vterm--displayed-claude-window.el ends here |
