emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Add tests for org agenda bulk functions
@ 2021-02-20 18:56 Kevin Foley
  2021-02-27 22:44 ` Kyle Meyer
  0 siblings, 1 reply; 2+ messages in thread
From: Kevin Foley @ 2021-02-20 18:56 UTC (permalink / raw)
  To: emacs-orgmode

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



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] Add tests for org agenda bulk functions
  2021-02-20 18:56 [PATCH] Add tests for org agenda bulk functions Kevin Foley
@ 2021-02-27 22:44 ` Kyle Meyer
  0 siblings, 0 replies; 2+ messages in thread
From: Kyle Meyer @ 2021-02-27 22:44 UTC (permalink / raw)
  To: Kevin Foley; +Cc: emacs-orgmode

Thanks, pushed (63c5cacb0).


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-02-27 22:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-02-20 18:56 [PATCH] Add tests for org agenda bulk functions Kevin Foley
2021-02-27 22:44 ` Kyle Meyer

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).