From: Kevin Foley <kevin@kevinjfoley.me>
To: emacs-orgmode@gnu.org
Subject: [PATCH] Add tests for org agenda bulk functions
Date: Sat, 20 Feb 2021 13:56:18 -0500 [thread overview]
Message-ID: <m2v9amsh4d.fsf@Kevins-MBP.home.lan> (raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: 0001-test-org-agenda.el-Test-bulk-functions.patch --]
[-- Type: text/x-patch, Size: 3715 bytes --]
From 1f7bdcaa40ccb562c4a04bc1bd27517ca1e69bea Mon Sep 17 00:00:00 2001
From: "Kevin J. Foley" <kevin@kevinjfoley.me>
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))))
+
\f
;; 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))))))
+
+
\f
(provide 'test-org-agenda)
\f
--
2.28.0
next reply other threads:[~2021-02-20 18:57 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-20 18:56 Kevin Foley [this message]
2021-02-27 22:44 ` [PATCH] Add tests for org agenda bulk functions Kyle Meyer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m2v9amsh4d.fsf@Kevins-MBP.home.lan \
--to=kevin@kevinjfoley.me \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).