test-org-agenda.el 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. ;;; test-org-agenda.el --- Tests for org-agenda.el -*- lexical-binding: t ; -*-
  2. ;; Copyright (C) 2017 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 auxilliaries
  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/sticky-agenda-name ()
  70. "Agenda buffer name after having created one sticky agenda buffer."
  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. (buf (get-buffer org-agenda-buffer-name))
  76. org-agenda-files)
  77. (when buf (kill-buffer buf))
  78. (org-test-with-temp-text "<2017-03-17 Fri>"
  79. (org-follow-timestamp-link)) ;creates a sticky agenda
  80. (org-test-agenda--kill-all-agendas)
  81. (org-agenda-list)
  82. (should (= 1 (length (org-test-agenda--agenda-buffers))))
  83. (should (string= "*Org Agenda*"
  84. (buffer-name (car (org-test-agenda--agenda-buffers))))))
  85. (org-test-agenda--kill-all-agendas))
  86. (ert-deftest test-org-agenda/sticky-agenda-name-after-reload ()
  87. "Agenda buffer name of sticky agenda after reload."
  88. (cl-assert (not org-agenda-sticky) nil "precondition violation")
  89. (cl-assert (not (org-test-agenda--agenda-buffers))
  90. nil "precondition violation")
  91. (org-toggle-sticky-agenda)
  92. (let (org-agenda-files)
  93. (org-agenda-list)
  94. (let* ((agenda-buffer-name
  95. (progn
  96. (cl-assert (= 1 (length (org-test-agenda--agenda-buffers))))
  97. (buffer-name (car (org-test-agenda--agenda-buffers))))))
  98. (set-buffer agenda-buffer-name)
  99. (org-agenda-redo)
  100. (should (= 1 (length (org-test-agenda--agenda-buffers))))
  101. (should (string= agenda-buffer-name
  102. (buffer-name (car (org-test-agenda--agenda-buffers)))))))
  103. (org-toggle-sticky-agenda)
  104. (org-test-agenda--kill-all-agendas))
  105. ;; agenda redo
  106. (require 'face-remap)
  107. (ert-deftest test-org-agenda/rescale ()
  108. "Text scale survives `org-agenda-redo'."
  109. (org-test-agenda--kill-all-agendas)
  110. (unwind-protect
  111. (let ((org-agenda-span 'day)
  112. org-agenda-files)
  113. (org-agenda-list)
  114. (set-buffer org-agenda-buffer-name)
  115. (text-scale-mode)
  116. (text-scale-set 11)
  117. (cl-assert (and (boundp text-scale-mode) text-scale-mode))
  118. (org-agenda-redo)
  119. (should text-scale-mode)
  120. (should (= 11 text-scale-mode-amount)))
  121. (org-test-agenda--kill-all-agendas)))
  122. (provide 'test-org-agenda)
  123. ;;; test-org-agenda.el ends here