aboutsummaryrefslogtreecommitdiff
path: root/tests/test-mail-config-helpers.el
blob: f33013b4f8675ab5298a7acff90cbd805ca1074e (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
;;; test-mail-config-helpers.el --- Tests for mail-config small helpers -*- lexical-binding: t; -*-

;;; Commentary:
;; Sibling tests cover transport setup + the email keymap.  This file
;; covers the three small command helpers:
;;
;;   cj/toggle-smtpmail-debug
;;   cj/disable-auto-composition
;;   cj/mu4e-mark-all-headers

;;; Code:

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

(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
(require 'mail-config)

;; Top-level defvar so let-bindings reach the dynamic var under
;; lexical scope.
(defvar smtpmail-debug-info nil)

;;; cj/toggle-smtpmail-debug

(ert-deftest test-mail-config-toggle-smtpmail-debug-flips-from-off ()
  "Normal: toggle from disabled flips both flags on."
  (let ((cj/smtpmail-debug-enabled nil)
        (smtpmail-debug-info nil))
    (cl-letf (((symbol-function 'message) #'ignore))
      (cj/toggle-smtpmail-debug))
    (should cj/smtpmail-debug-enabled)
    (should smtpmail-debug-info)))

(ert-deftest test-mail-config-toggle-smtpmail-debug-flips-from-on ()
  "Normal: toggle from enabled flips both flags off."
  (let ((cj/smtpmail-debug-enabled t)
        (smtpmail-debug-info t))
    (cl-letf (((symbol-function 'message) #'ignore))
      (cj/toggle-smtpmail-debug))
    (should-not cj/smtpmail-debug-enabled)
    (should-not smtpmail-debug-info)))

;;; cj/disable-auto-composition

(ert-deftest test-mail-config-disable-auto-composition-turns-off ()
  "Normal: disable-auto-composition invokes auto-composition-mode with -1."
  (let (received-arg)
    (cl-letf (((symbol-function 'auto-composition-mode)
               (lambda (arg) (setq received-arg arg))))
      (cj/disable-auto-composition))
    (should (eq received-arg -1))))

;;; cj/mu4e-mark-all-headers

(ert-deftest test-mail-config-mark-all-headers-passes-something-and-true ()
  "Normal: mark-all-headers delegates to `mu4e-headers-mark-for-each-if'
with the something tag and a predicate that always returns non-nil."
  (let (mark-arg predicate-arg)
    (cl-letf (((symbol-function 'mu4e-headers-mark-for-each-if)
               (lambda (mark pred)
                 (setq mark-arg mark
                       predicate-arg pred))))
      (cj/mu4e-mark-all-headers))
    (should (equal mark-arg '(something)))
    (should (functionp predicate-arg))
    (should (funcall predicate-arg 'any-msg 'any-param))
    (should (funcall predicate-arg nil nil))))

(provide 'test-mail-config-helpers)
;;; test-mail-config-helpers.el ends here