aboutsummaryrefslogtreecommitdiff
path: root/tests/test-slack-config-display.el
blob: 24128ddce9b9d3f4ed21b32e70394353588a4815 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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