test-org-agenda.el 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. ;;; test-org-agenda.el --- Tests for org-agenda.el -*- lexical-binding: t ; -*-
  2. ;; Copyright (C) 2017, 2019 Marco Wahl
  3. ;; Author: Marco Wahl <marcowahlsoft@gmail.com>
  4. ;; This program is free software; you can redistribute it and/or modify
  5. ;; it under the terms of the GNU General Public License as published by
  6. ;; the Free Software Foundation, either version 3 of the License, or
  7. ;; (at your option) any later version.
  8. ;; This program is distributed in the hope that it will be useful,
  9. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;; GNU General Public License for more details.
  12. ;; You should have received a copy of the GNU General Public License
  13. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. ;;; Commentary:
  15. ;; Unit tests for Org Agenda.
  16. ;;; Code:
  17. (require 'org-test)
  18. (require 'org-agenda)
  19. (eval-and-compile (require 'cl-lib))
  20. ;; General auxiliaries
  21. (defun org-test-agenda--agenda-buffers ()
  22. "Return agenda buffers in a list."
  23. (cl-remove-if-not (lambda (x)
  24. (with-current-buffer x
  25. (eq major-mode 'org-agenda-mode)))
  26. (buffer-list)))
  27. (defun org-test-agenda--kill-all-agendas ()
  28. "Kill all agenda buffers."
  29. (mapc #'kill-buffer
  30. (org-test-agenda--agenda-buffers)))
  31. ;; Test the Agenda
  32. (ert-deftest test-org-agenda/empty ()
  33. "Empty agenda."
  34. (cl-assert (not org-agenda-sticky) nil "precondition violation")
  35. (cl-assert (not (org-test-agenda--agenda-buffers))
  36. nil "precondition violation")
  37. (let ((org-agenda-span 'day)
  38. org-agenda-files)
  39. (org-agenda-list)
  40. (set-buffer org-agenda-buffer-name)
  41. (should (= 2 (count-lines (point-min) (point-max)))))
  42. (org-test-agenda--kill-all-agendas))
  43. (ert-deftest test-org-agenda/one-line ()
  44. "One informative line in the agenda."
  45. (cl-assert (not org-agenda-sticky) nil "precondition violation")
  46. (cl-assert (not (org-test-agenda--agenda-buffers))
  47. nil "precondition violation")
  48. (let ((org-agenda-span 'day)
  49. (org-agenda-files `(,(expand-file-name "examples/agenda-file.org"
  50. org-test-dir))))
  51. (org-agenda-list nil "<2017-03-10 Fri>")
  52. (set-buffer org-agenda-buffer-name)
  53. (should (= 3 (count-lines (point-min) (point-max)))))
  54. (org-test-agenda--kill-all-agendas))
  55. (ert-deftest test-org-agenda/scheduled-non-todo ()
  56. "One informative line in the agenda from scheduled non-todo-keyword-item."
  57. (cl-assert (not org-agenda-sticky) nil "precondition violation")
  58. (cl-assert (not (org-test-agenda--agenda-buffers))
  59. nil "precondition violation")
  60. (let ((org-agenda-span 'day)
  61. (org-agenda-files `(,(expand-file-name "examples/agenda-file.org"
  62. org-test-dir))))
  63. (org-agenda-list nil "<2017-07-19 Wed>")
  64. (set-buffer org-agenda-buffer-name)
  65. (should
  66. (progn (goto-line 3)
  67. (looking-at " *agenda-file:Scheduled: *test agenda"))))
  68. (org-test-agenda--kill-all-agendas))
  69. (ert-deftest test-org-agenda/set-priority ()
  70. "One informative line in the agenda. Check that org-agenda-priority updates the agenda."
  71. (cl-assert (not org-agenda-sticky) nil "precondition violation")
  72. (cl-assert (not (org-test-agenda--agenda-buffers))
  73. nil "precondition violation")
  74. (let ((org-agenda-span 'day)
  75. (org-agenda-files `(,(expand-file-name "examples/agenda-file.org"
  76. org-test-dir))))
  77. (org-agenda-list nil "<2017-07-19 Wed>")
  78. (set-buffer org-agenda-buffer-name)
  79. (should
  80. (progn (goto-line 3)
  81. (org-agenda-priority ?B)
  82. (looking-at-p " *agenda-file:Scheduled: *\\[#B\\] test agenda"))))
  83. (org-test-agenda--kill-all-agendas))
  84. (ert-deftest test-org-agenda/sticky-agenda-name ()
  85. "Agenda buffer name after having created one sticky agenda buffer."
  86. (cl-assert (not org-agenda-sticky) nil "precondition violation")
  87. (cl-assert (not (org-test-agenda--agenda-buffers))
  88. nil "precondition violation")
  89. (let ((org-agenda-span 'day)
  90. (buf (get-buffer org-agenda-buffer-name))
  91. org-agenda-files)
  92. (when buf (kill-buffer buf))
  93. (org-test-with-temp-text "<2017-03-17 Fri>"
  94. (org-follow-timestamp-link)) ;creates a sticky agenda
  95. (org-test-agenda--kill-all-agendas)
  96. (org-agenda-list)
  97. (should (= 1 (length (org-test-agenda--agenda-buffers))))
  98. (should (string= "*Org Agenda*"
  99. (buffer-name (car (org-test-agenda--agenda-buffers))))))
  100. (org-test-agenda--kill-all-agendas))
  101. (ert-deftest test-org-agenda/sticky-agenda-name-after-reload ()
  102. "Agenda buffer name of sticky agenda after reload."
  103. (cl-assert (not org-agenda-sticky) nil "precondition violation")
  104. (cl-assert (not (org-test-agenda--agenda-buffers))
  105. nil "precondition violation")
  106. (org-toggle-sticky-agenda)
  107. (let (org-agenda-files)
  108. (org-agenda-list)
  109. (let* ((agenda-buffer-name
  110. (progn
  111. (cl-assert (= 1 (length (org-test-agenda--agenda-buffers))))
  112. (buffer-name (car (org-test-agenda--agenda-buffers))))))
  113. (set-buffer agenda-buffer-name)
  114. (org-agenda-redo)
  115. (should (= 1 (length (org-test-agenda--agenda-buffers))))
  116. (should (string= agenda-buffer-name
  117. (buffer-name (car (org-test-agenda--agenda-buffers)))))))
  118. (org-toggle-sticky-agenda)
  119. (org-test-agenda--kill-all-agendas))
  120. ;; agenda redo
  121. (require 'face-remap)
  122. (ert-deftest test-org-agenda/rescale ()
  123. "Text scale survives `org-agenda-redo'."
  124. (org-test-agenda--kill-all-agendas)
  125. (unwind-protect
  126. (let ((org-agenda-span 'day)
  127. org-agenda-files)
  128. (org-agenda-list)
  129. (set-buffer org-agenda-buffer-name)
  130. (text-scale-mode)
  131. (text-scale-set 11)
  132. (cl-assert (and (boundp text-scale-mode) text-scale-mode))
  133. (org-agenda-redo)
  134. (should text-scale-mode)
  135. (should (= 11 text-scale-mode-amount)))
  136. (org-test-agenda--kill-all-agendas)))
  137. (ert-deftest test-org-agenda/diary-inclusion ()
  138. "Diary inclusion happens."
  139. (org-test-agenda--kill-all-agendas)
  140. (let ((diary-file (expand-file-name "examples/diary-file" org-test-dir))
  141. (org-agenda-files `(,(expand-file-name "examples/agenda-file.org"
  142. org-test-dir)))
  143. (diary-date-forms '((month "[-/]" day "[^-/0-9]")
  144. (year "[-/]" month "[-/]" day "[^0-9]")
  145. (monthname " *" day "[^-0-9]")
  146. (year " *" monthname " *" day "[^0-9]")
  147. (dayname "\\W")))
  148. (org-agenda-span 'day)
  149. (org-agenda-include-diary t))
  150. (org-agenda-list nil "<2019-01-08>")
  151. (should (search-forward "f0bcf0cd8bad93c1451bb6e1b2aaedef5cce7cbb" nil t))
  152. (org-test-agenda--kill-all-agendas)))
  153. (provide 'test-org-agenda)
  154. ;;; test-org-agenda.el ends here