From 1f7bdcaa40ccb562c4a04bc1bd27517ca1e69bea Mon Sep 17 00:00:00 2001 From: "Kevin J. Foley" Date: Sat, 20 Feb 2021 13:42:44 -0500 Subject: [PATCH] test-org-agenda.el: Test bulk functions * testing/lisp/test-org-agenda.el (org-test-agenda-with-agenda): Create macro to setup agenda for tests. (test-org-agenda/bulk): Test that bulk actions are applied to marked items. (test-org-agenda/bulk-custom): Test that custom bulk actions are applied to marked items. (test-org-agenda/bulk-custom-arg-func): Test that argument collection function is properly called for custom bulk functions. --- testing/lisp/test-org-agenda.el | 68 +++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/testing/lisp/test-org-agenda.el b/testing/lisp/test-org-agenda.el index 7c1bfb2be..22449a73b 100644 --- a/testing/lisp/test-org-agenda.el +++ b/testing/lisp/test-org-agenda.el @@ -42,6 +42,13 @@ (defun org-test-agenda--kill-all-agendas () (mapc #'kill-buffer (org-test-agenda--agenda-buffers))) +(defmacro org-test-agenda-with-agenda (text &rest body) + (declare (indent 1)) + `(org-test-with-temp-text-in-file ,text + (let ((org-agenda-files `(,buffer-file-name))) + ,@body + (org-test-agenda--kill-all-agendas)))) + ;; Test the Agenda @@ -180,6 +187,67 @@ (ert-deftest test-org-agenda/diary-inclusion () (should (search-forward "f0bcf0cd8bad93c1451bb6e1b2aaedef5cce7cbb" nil t)) (org-test-agenda--kill-all-agendas))) +;; agenda bulk actions + +(ert-deftest test-org-agenda/bulk () + "Bulk actions are applied to marked items." + (org-test-agenda-with-agenda "* TODO a\n* TODO b" + (org-todo-list) + (org-agenda-bulk-mark-all) + (cl-letf (((symbol-function 'read-char-exclusive) + (lambda () ?t)) + ((symbol-function 'completing-read) + (lambda (&rest rest) "DONE"))) + (org-agenda-bulk-action)) + (org-agenda-previous-item 99) + (should (looking-at ".*DONE a")) + (org-agenda-next-item 1) + (should (looking-at ".*DONE b")))) + +(ert-deftest test-org-agenda/bulk-custom () + "Custom bulk actions are applied to all marked items." + (org-test-agenda-with-agenda "* TODO a\n* TODO b" + (org-todo-list) + (org-agenda-bulk-mark-all) + + ;; Mock read functions + (let* ((f-call-cnt 0) + (org-agenda-bulk-custom-functions + `((?P ,(lambda () (setq f-call-cnt (1+ f-call-cnt))))))) + (cl-letf* (((symbol-function 'read-char-exclusive) + (lambda () ?P))) + (org-agenda-bulk-action) + (should (= f-call-cnt 2)))))) + +(ert-deftest test-org-agenda/bulk-custom-arg-func () + "Argument collection functions can be specified for custom bulk +functions." + (org-test-agenda-with-agenda "* TODO a\n* TODO b" + (org-todo-list) + (org-agenda-bulk-mark-all) + (let* ((f-called-cnt 0) + (arg-f-call-cnt 0) + (f-called-args nil) + (org-agenda-bulk-custom-functions + `((?P + ;; Custom bulk function + ,(lambda (&rest args) + (message "test" args) + (setq f-called-cnt (1+ f-called-cnt) + + f-called-args args)) + ;; Argument collection function + ,(lambda () + (setq arg-f-call-cnt (1+ arg-f-call-cnt)) + '(1 2 3)))))) + (cl-letf (((symbol-function 'read-char-exclusive) + (lambda () ?P))) + (org-agenda-bulk-action)) + (should (= f-called-cnt 2)) + (should (= arg-f-call-cnt 1)) + (should (equal f-called-args '(1 2 3)))))) + + (provide 'test-org-agenda) -- 2.28.0