aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-14 03:34:15 -0500
committerCraig Jennings <c@cjennings.net>2026-05-14 03:34:15 -0500
commitc16d53e8787cd9f197c358ac21b05a78738a77de (patch)
treef0c3c8fb0bed6e350a7f3bf354c4727c0aded4f2 /tests
parent5374ab0f5aaf020880caf7f804085b7af4bd746f (diff)
downloaddotemacs-c16d53e8787cd9f197c358ac21b05a78738a77de.tar.gz
dotemacs-c16d53e8787cd9f197c358ac21b05a78738a77de.zip
test(org-refile-config): cover refresh-targets, org-refile, refile-in-file
Sibling tests covered the ensure-org-mode helper and the build-targets pipeline. The three wrapper commands were uncovered: - `cj/org-refile-refresh-targets`: passes the `force-rebuild` flag to `cj/build-org-refile-targets`. - `cj/org-refile`: builds the cache, then calls `org-refile` with the four positional args. - `cj/org-refile-in-file`: scopes `org-refile-targets` to the current file at maxlevel 6, then saves after the refile completes. Top-level `defvar` for `org-refile-targets` so the let-binding inside the function is dynamic under lexical scope.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-org-refile-config-commands.el82
1 files changed, 82 insertions, 0 deletions
diff --git a/tests/test-org-refile-config-commands.el b/tests/test-org-refile-config-commands.el
new file mode 100644
index 00000000..9bdd3364
--- /dev/null
+++ b/tests/test-org-refile-config-commands.el
@@ -0,0 +1,82 @@
+;;; test-org-refile-config-commands.el --- Tests for org-refile-config command wrappers -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; Sibling tests cover the ensure-org-mode helper and the build-targets
+;; pipeline. This file covers the wrapper commands:
+;;
+;; cj/org-refile-refresh-targets
+;; cj/org-refile
+;; cj/org-refile-in-file
+
+;;; Code:
+
+(require 'ert)
+(require 'cl-lib)
+
+(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
+(require 'org-refile-config)
+
+;; `org-refile-targets' is normally provided by org-refile; the module's
+;; `cj/org-refile-in-file' let-binds it. Declare it at top level so the
+;; let-binding is dynamic under lexical scope.
+(defvar org-refile-targets nil
+ "Dynamic stand-in for `org-refile-targets'.")
+
+;;; cj/org-refile-refresh-targets
+
+(ert-deftest test-org-refile-refresh-targets-forces-rebuild ()
+ "Normal: refresh-targets calls build-targets with the force-rebuild flag."
+ (let ((forced nil))
+ (cl-letf (((symbol-function 'cj/build-org-refile-targets)
+ (lambda (&optional flag) (setq forced flag))))
+ (cj/org-refile-refresh-targets))
+ (should (eq forced 'force-rebuild))))
+
+;;; cj/org-refile
+
+(ert-deftest test-org-refile-builds-targets-then-delegates ()
+ "Normal: cj/org-refile builds the cache then calls `org-refile' with the args."
+ (let ((built nil)
+ (call-args nil))
+ (cl-letf (((symbol-function 'cj/build-org-refile-targets)
+ (lambda (&optional _) (setq built t)))
+ ((symbol-function 'org-refile)
+ (lambda (&rest args) (setq call-args args))))
+ (cj/org-refile 'arg 'buffer 'rfloc 'msg))
+ (should built)
+ (should (equal call-args '(arg buffer rfloc msg)))))
+
+;;; cj/org-refile-in-file
+
+(ert-deftest test-org-refile-in-file-uses-current-file-as-target ()
+ "Normal: refile-in-file scopes `org-refile-targets' to the current file."
+ (let ((seen-targets nil))
+ (with-temp-buffer
+ (setq buffer-file-name "/tmp/notes.org")
+ (cl-letf (((symbol-function 'call-interactively)
+ (lambda (_fn)
+ (setq seen-targets org-refile-targets)))
+ ((symbol-function 'save-buffer) #'ignore))
+ (cj/org-refile-in-file))
+ (setq buffer-file-name nil))
+ ;; The let-bound targets are: (((file) :maxlevel . 6))
+ (should seen-targets)
+ (let* ((entry (car seen-targets))
+ (files (car entry)))
+ (should (member "/tmp/notes.org" files))
+ (should (equal (cdr entry) '(:maxlevel . 6))))))
+
+(ert-deftest test-org-refile-in-file-saves-after-refile ()
+ "Normal: refile-in-file calls `save-buffer' after the refile."
+ (let ((saved nil))
+ (with-temp-buffer
+ (setq buffer-file-name "/tmp/notes.org")
+ (cl-letf (((symbol-function 'call-interactively) #'ignore)
+ ((symbol-function 'save-buffer)
+ (lambda () (setq saved t))))
+ (cj/org-refile-in-file))
+ (setq buffer-file-name nil))
+ (should saved)))
+
+(provide 'test-org-refile-config-commands)
+;;; test-org-refile-config-commands.el ends here