aboutsummaryrefslogtreecommitdiff
path: root/tests/test-org-capture-templates-integrity.el
blob: dd7e1dc374ee77dcd8a453a19d4c73e43d1e0f27 (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
;;; test-org-capture-templates-integrity.el --- Capture-template smoke tests -*- lexical-binding: t; -*-

;;; Commentary:
;; Org capture templates are assembled across several feature modules
;; (org-capture-config, quick-video-capture, org-contacts-config, ...), so a
;; duplicate dispatch key or a file target pointing at an unset path variable
;; would be easy to miss.  These smoke tests load the cleanly-loadable capture
;; modules, apply their lazy additions, and assert key uniqueness and that
;; symbol-valued file targets resolve to non-empty path strings.
;;
;; Webclipper templates register only when org-web-tools is installed and are
;; covered by their own test (test-org-webclipper-commands.el), so they are out
;; of scope here.

;;; Code:

(require 'ert)
(require 'cl-lib)
(require 'user-constants)
(require 'org)
(require 'org-capture)

(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
(require 'org-capture-config)
(require 'quick-video-capture)
(require 'org-contacts-config)

(defun test-capture--assembled-templates ()
  "Return `org-capture-templates' with the cleanly-loadable lazy additions.
Contacts registers its template via `with-eval-after-load' on load; the
video-download template is registered on demand here."
  (cj/setup-video-download)
  org-capture-templates)

(defun test-capture--file-target-path-symbol (entry)
  "Return ENTRY's file-target path symbol, or nil for literal/lambda targets.
Only plain symbol path slots are returned; a literal \"\" (the video
template's no-save target) or a lambda (the drill file pickers) yields nil."
  (when (>= (length entry) 4)
    (let ((target (nth 3 entry)))
      (when (and (consp target)
                 (memq (car target)
                       '(file file+headline file+olp file+datetree
                         file+olp+datetree file+function)))
        (let ((path (nth 1 target)))
          (and (symbolp path) path))))))

;;; Smoke Cases

(ert-deftest test-org-capture-template-keys-are-unique ()
  "Smoke: no two capture templates share a dispatch key."
  (let* ((keys (mapcar #'car (test-capture--assembled-templates)))
         (deduped (cl-remove-duplicates keys :test #'equal :from-end t)))
    (should (equal keys deduped))))

(ert-deftest test-org-capture-file-targets-point-at-nonempty-paths ()
  "Smoke: every symbol-valued file target resolves to a non-empty string path.
Literal-string targets and lambda targets are intentionally excluded."
  (dolist (entry (test-capture--assembled-templates))
    (let ((sym (test-capture--file-target-path-symbol entry)))
      (when sym
        (should (boundp sym))
        (should (stringp (symbol-value sym)))
        (should-not (string-empty-p (symbol-value sym)))))))

(provide 'test-org-capture-templates-integrity)
;;; test-org-capture-templates-integrity.el ends here