;;; 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