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.
This commit is contained in:
parent
0b117f72a8
commit
63c5cacb01
|
@ -42,6 +42,13 @@
|
|||
(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
|
||||
|
||||
|
@ -192,6 +199,67 @@
|
|||
(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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue