blob: 407335f8061d74fac980c12b21daaedbec3cf82f (
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
;;; test-ui-navigation--split-dashboard.el --- Tests for split-with-dashboard -*- lexical-binding: t; -*-
;;; Commentary:
;; C-x 2 / C-x 3 split and show the *dashboard* in the new window while point
;; stays in the original. cj/--split-show-buffer does the placement;
;; cj/split-below/right-with-dashboard wire it to the two split directions.
;;; Code:
(require 'ert)
(require 'cl-lib)
(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
(require 'ui-navigation)
(ert-deftest test-ui-navigation-split-dashboard-keybindings ()
"Normal: C-x 2 / C-x 3 are bound to the dashboard-split commands."
(should (eq (key-binding (kbd "C-x 2")) #'cj/split-below-with-dashboard))
(should (eq (key-binding (kbd "C-x 3")) #'cj/split-right-with-dashboard)))
(ert-deftest test-ui-navigation-split-show-buffer-displays-and-keeps-point ()
"Normal: the new window shows the buffer; the original stays selected."
(let ((buf (get-buffer-create " *split-dash-test*"))
(config (current-window-configuration)))
(unwind-protect
(progn
(delete-other-windows)
(let* ((orig (selected-window))
(new (cj/--split-show-buffer #'split-window-below buf)))
(should (window-live-p new))
(should (not (eq new orig)))
(should (eq (window-buffer new) buf))
(should (eq (selected-window) orig)))) ; point stays put
(set-window-configuration config)
(kill-buffer buf))))
(ert-deftest test-ui-navigation-split-below-routes-to-split-window-below ()
"Normal: cj/split-below-with-dashboard splits below with the dashboard buffer."
(let (captured)
(cl-letf (((symbol-function 'cj/--dashboard-buffer) (lambda () 'dashboard))
((symbol-function 'cj/--split-show-buffer)
(lambda (fn buf) (setq captured (list fn buf)) nil)))
(cj/split-below-with-dashboard))
(should (eq (car captured) #'split-window-below))
(should (eq (cadr captured) 'dashboard))))
(ert-deftest test-ui-navigation-split-right-routes-to-split-window-right ()
"Normal: cj/split-right-with-dashboard splits right with the dashboard buffer."
(let (captured)
(cl-letf (((symbol-function 'cj/--dashboard-buffer) (lambda () 'dashboard))
((symbol-function 'cj/--split-show-buffer)
(lambda (fn buf) (setq captured (list fn buf)) nil)))
(cj/split-right-with-dashboard))
(should (eq (car captured) #'split-window-right))
(should (eq (cadr captured) 'dashboard))))
(ert-deftest test-ui-navigation-split-from-dashboard-p ()
"Normal/Boundary: only the dashboard buffer routes the companion to *scratch*."
(should (cj/--split-from-dashboard-p "*dashboard*"))
(should-not (cj/--split-from-dashboard-p "todo.org"))
(should-not (cj/--split-from-dashboard-p "*scratch*")))
(ert-deftest test-ui-navigation-split-companion-scratch-from-dashboard ()
"Normal: splitting from the dashboard yields the *scratch* buffer, not the
dashboard again."
(cl-letf (((symbol-function 'cj/--split-from-dashboard-p) (lambda (_) t))
((symbol-function 'get-scratch-buffer-create) (lambda () 'scratch))
((symbol-function 'cj/--dashboard-buffer) (lambda () 'dashboard)))
(should (eq (cj/--split-companion-buffer) 'scratch))))
(ert-deftest test-ui-navigation-split-companion-dashboard-otherwise ()
"Normal: splitting from any other buffer yields the dashboard."
(cl-letf (((symbol-function 'cj/--split-from-dashboard-p) (lambda (_) nil))
((symbol-function 'get-scratch-buffer-create) (lambda () 'scratch))
((symbol-function 'cj/--dashboard-buffer) (lambda () 'dashboard)))
(should (eq (cj/--split-companion-buffer) 'dashboard))))
(ert-deftest test-ui-navigation-dashboard-buffer-returns-existing ()
"Boundary: cj/--dashboard-buffer returns an existing *dashboard* without opening."
(let ((db (get-buffer-create "*dashboard*"))
(opened nil))
(unwind-protect
(cl-letf (((symbol-function 'dashboard-open)
(lambda (&rest _) (setq opened t))))
(should (eq (cj/--dashboard-buffer) db))
(should-not opened))
(kill-buffer db))))
(provide 'test-ui-navigation--split-dashboard)
;;; test-ui-navigation--split-dashboard.el ends here
|