diff options
| author | Szymon Szukalski <szymon@szymonszukalski.com> | 2026-04-10 13:44:48 +1000 |
|---|---|---|
| committer | Szymon Szukalski <szymon@szymonszukalski.com> | 2026-04-10 13:44:48 +1000 |
| commit | f6fc37d74f0b027ea7cfb1c6ff5c9e362d8af465 (patch) | |
| tree | 1263f3f6736b0e464c78a9916b4ce6cb3855121f /tests | |
| parent | ca8e1ea67b46f427829e272ac3eaf8186c04577a (diff) | |
Add Org refile configuration
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ss-org-tests.el | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/tests/ss-org-tests.el b/tests/ss-org-tests.el new file mode 100644 index 0000000..b8e1eb5 --- /dev/null +++ b/tests/ss-org-tests.el @@ -0,0 +1,88 @@ +;;; ss-org-tests.el --- Tests for ss-org -*- lexical-binding: t; -*- + +;;; Commentary: + +;; Focused ERT coverage for Org refile configuration. + +;;; Code: + +(add-to-list 'load-path (expand-file-name "../lisp" (file-name-directory load-file-name))) + +(require 'ert) +(require 'cl-lib) +(require 'org) +(require 'ss-org) + +(ert-deftest ss-org-configure-refile-sets-org-variables () + (let ((old-refile-targets (and (boundp 'org-refile-targets) + org-refile-targets)) + (old-refile-use-outline-path (and (boundp 'org-refile-use-outline-path) + org-refile-use-outline-path)) + (old-outline-path-complete-in-steps + (and (boundp 'org-outline-path-complete-in-steps) + org-outline-path-complete-in-steps))) + (unwind-protect + (progn + (advice-remove 'org-refile #'ss-org-refresh-agenda-files-for-refile) + (setq org-refile-targets nil + org-refile-use-outline-path nil + org-outline-path-complete-in-steps t) + (ss-org-configure-refile) + (should (equal org-refile-targets + '((org-agenda-files :regexp . "^\\*+ ")))) + (should (eq org-refile-use-outline-path 'file)) + (should-not org-outline-path-complete-in-steps)) + (setq org-refile-targets old-refile-targets + org-refile-use-outline-path old-refile-use-outline-path + org-outline-path-complete-in-steps + old-outline-path-complete-in-steps) + (advice-remove 'org-refile #'ss-org-refresh-agenda-files-for-refile)))) + +(ert-deftest ss-org-configure-refile-discovers-headings-in-agenda-files () + (let* ((file (make-temp-file "ss-org-refile-" nil ".org" + "* Alpha\n** Beta\n")) + (file-name (file-name-nondirectory file)) + (org-agenda-files (list file)) + (old-refile-targets (and (boundp 'org-refile-targets) + org-refile-targets)) + (old-refile-use-outline-path (and (boundp 'org-refile-use-outline-path) + org-refile-use-outline-path)) + (old-outline-path-complete-in-steps + (and (boundp 'org-outline-path-complete-in-steps) + org-outline-path-complete-in-steps)) + targets) + (unwind-protect + (progn + (advice-remove 'org-refile #'ss-org-refresh-agenda-files-for-refile) + (ss-org-configure-refile) + (with-current-buffer (find-file-noselect file) + (setq targets (org-refile-get-targets))) + (should (assoc (format "%s/Alpha" file-name) targets)) + (should (assoc (format "%s/Alpha/Beta" file-name) targets))) + (setq org-refile-targets old-refile-targets + org-refile-use-outline-path old-refile-use-outline-path + org-outline-path-complete-in-steps + old-outline-path-complete-in-steps) + (advice-remove 'org-refile #'ss-org-refresh-agenda-files-for-refile) + (when-let ((buffer (get-file-buffer file))) + (kill-buffer buffer)) + (delete-file file)))) + +(ert-deftest ss-org-configure-refile-adds-refresh-advice () + (unwind-protect + (progn + (advice-remove 'org-refile #'ss-org-refresh-agenda-files-for-refile) + (ss-org-configure-refile) + (should (advice-member-p #'ss-org-refresh-agenda-files-for-refile + 'org-refile))) + (advice-remove 'org-refile #'ss-org-refresh-agenda-files-for-refile))) + +(ert-deftest ss-org-refresh-agenda-files-for-refile-reuses-agenda-helper () + (let (called) + (cl-letf (((symbol-function 'ss-refresh-org-agenda-files) + (lambda (&rest _args) + (setq called t)))) + (ss-org-refresh-agenda-files-for-refile) + (should called)))) + +;;; ss-org-tests.el ends here
\ No newline at end of file |
