aboutsummaryrefslogtreecommitdiff
path: root/tests/test-org-drill-display-restore.el
blob: 90d1b0de29cabb31b9b730f627762c7795a897b7 (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
;;; test-org-drill-display-restore.el --- Regression for cross-buffer display restore  -*- lexical-binding: t; -*-

;;; Commentary:
;; The display setup / restore pair saved buffer-local state (mode-line,
;; variable-pitch-mode) to global defvars and restored via plain
;; `setq-local'.  If the user switched buffers between setup and
;; restore, the restore wrote to the wrong buffer — leaving the
;; original drill buffer with its modeline still hidden, and trampling
;; the destination buffer's modeline.
;;
;; The fix tracks the buffer at setup and uses `with-current-buffer'
;; to restore in the original.

;;; Code:

(require 'ert)
(require 'cl-lib)
(require 'org)
(require 'org-drill)

;;;; Cross-buffer modeline restore

(ert-deftest test-display-restore-modeline-in-original-buffer-after-buffer-switch ()
  "Setup in buffer A, restore in buffer B — A's mode-line should be restored,
B's mode-line untouched."
  (let ((buffer-a (generate-new-buffer "*org-drill-test-A*"))
        (buffer-b (generate-new-buffer "*org-drill-test-B*"))
        (org-drill-hide-modeline-during-session t)
        (org-drill-text-size-during-session nil)
        (org-drill-use-variable-pitch nil))
    (unwind-protect
        (progn
          (with-current-buffer buffer-a
            (setq-local mode-line-format "A-original")
            (org-drill--setup-display)
            ;; A's modeline is now hidden (nil).
            (should (null mode-line-format)))
          (with-current-buffer buffer-b
            (setq-local mode-line-format "B-original")
            ;; Restore runs from buffer B (simulating a buffer switch
            ;; mid-session).
            (org-drill--restore-display))
          ;; After restore: A's modeline back to original, B's untouched.
          (with-current-buffer buffer-a
            (should (equal "A-original" mode-line-format)))
          (with-current-buffer buffer-b
            (should (equal "B-original" mode-line-format))))
      (kill-buffer buffer-a)
      (kill-buffer buffer-b))))

(provide 'test-org-drill-display-restore)

;;; test-org-drill-display-restore.el ends here