aboutsummaryrefslogtreecommitdiff
path: root/tests/test-slack-config-display.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-26 14:21:20 -0500
committerCraig Jennings <c@cjennings.net>2026-05-26 14:21:20 -0500
commit6c7f9ae225b91dee81a04d2271a6648924c0f3cf (patch)
tree2ca709a04afa25f7d106a425e8cf438f62ddd55d /tests/test-slack-config-display.el
parentfcf3e0f89f47cd377612406c62448b0bf626b389 (diff)
downloaddotemacs-6c7f9ae225b91dee81a04d2271a6648924c0f3cf.tar.gz
dotemacs-6c7f9ae225b91dee81a04d2271a6648924c0f3cf.zip
feat(slack): open rooms in another window, never the selected one
slack-buffer-function defaulted to switch-to-buffer-other-window, which gives no real guarantee about placement: with three or more panes it picks a least-recently-used window, and it offers nothing that keeps Slack out of the window point is in. So opening a room in a split could land it wherever, including over the buffer I was working in. I set slack-buffer-function to cj/slack--display-buffer, a pop-to-buffer call with inhibit-same-window and a reuse / use-some-window / pop-up-window action list. In a split it reuses one of the other windows and leaves the selected window alone; with a lone window it splits. Tests cover both the split-placement case and the selected-window-preserved invariant.
Diffstat (limited to 'tests/test-slack-config-display.el')
-rw-r--r--tests/test-slack-config-display.el48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/test-slack-config-display.el b/tests/test-slack-config-display.el
new file mode 100644
index 00000000..24128ddc
--- /dev/null
+++ b/tests/test-slack-config-display.el
@@ -0,0 +1,48 @@
+;;; test-slack-config-display.el --- Slack buffer placement -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; cj/slack--display-buffer is wired as `slack-buffer-function' so opening a
+;; Slack room or thread shows it in another window and never replaces the
+;; selected window's buffer. These exercise the placement directly with plain
+;; buffers (no live Slack), using a side-by-side split so the window math is
+;; reliable under `emacs --batch'.
+
+;;; Code:
+
+(require 'ert)
+(require 'slack-config)
+
+(ert-deftest test-slack-config-display-buffer-uses-other-window-when-split ()
+ "Normal: with a split, the buffer lands in a non-selected window."
+ (let ((a (get-buffer-create "*slack-disp-a*"))
+ (b (get-buffer-create "*slack-disp-b*")))
+ (unwind-protect
+ (save-window-excursion
+ (delete-other-windows)
+ (set-window-buffer (selected-window) a)
+ (let ((win-a (selected-window)))
+ (split-window win-a nil t) ;; side-by-side, batch-friendly
+ (cj/slack--display-buffer b)
+ (let ((win-b (get-buffer-window b)))
+ (should win-b)
+ (should-not (eq win-b win-a)))))
+ (ignore-errors (kill-buffer a))
+ (ignore-errors (kill-buffer b)))))
+
+(ert-deftest test-slack-config-display-buffer-keeps-selected-window ()
+ "Boundary: displaying does not replace the selected window's buffer."
+ (let ((a (get-buffer-create "*slack-disp-a*"))
+ (b (get-buffer-create "*slack-disp-b*")))
+ (unwind-protect
+ (save-window-excursion
+ (delete-other-windows)
+ (set-window-buffer (selected-window) a)
+ (let ((win-a (selected-window)))
+ (split-window win-a nil t)
+ (cj/slack--display-buffer b)
+ (should (eq (window-buffer win-a) a))))
+ (ignore-errors (kill-buffer a))
+ (ignore-errors (kill-buffer b)))))
+
+(provide 'test-slack-config-display)
+;;; test-slack-config-display.el ends here