test-org-agenda.el 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. ;; General auxilliaries
  20. (defun org-test-agenda--agenda-buffers ()
  21. "Return agenda buffers in a list."
  22. (cl-remove-if-not (lambda (x)
  23. (with-current-buffer x
  24. (eq major-mode 'org-agenda-mode)))
  25. (buffer-list)))
  26. (defun org-test-agenda--kill-all-agendas ()
  27. "Kill all agenda buffers."
  28. (mapc #'kill-buffer
  29. (org-test-agenda--agenda-buffers)))
  30. ;; Test the Agenda
  31. (ert-deftest test-org-agenda/empty ()
  32. "Empty agenda."
  33. (cl-assert (not org-agenda-sticky) nil "precondition violation")
  34. (cl-assert (not (org-test-agenda--agenda-buffers))
  35. nil "precondition violation")
  36. (let ((org-agenda-span 'day)
  37. org-agenda-files)
  38. (org-agenda-list)
  39. (set-buffer org-agenda-buffer-name)
  40. (should (= 2 (count-lines (point-min) (point-max)))))
  41. (org-test-agenda--kill-all-agendas))
  42. (ert-deftest test-org-agenda/one-line ()
  43. "One informative line in the agenda."
  44. (cl-assert (not org-agenda-sticky) nil "precondition violation")
  45. (cl-assert (not (org-test-agenda--agenda-buffers))
  46. nil "precondition violation")
  47. (let ((org-agenda-span 'day)
  48. (org-agenda-files `(,(expand-file-name "examples/agenda-file.org"
  49. org-test-dir))))
  50. (org-agenda-list nil "<2017-03-10 Fri>")
  51. (set-buffer org-agenda-buffer-name)
  52. (should (= 3 (count-lines (point-min) (point-max)))))
  53. (org-test-agenda--kill-all-agendas))
  54. (ert-deftest test-org-agenda/scheduled-non-todo ()
  55. "One informative line in the agenda from scheduled non-todo-keyword-item."
  56. (cl-assert (not org-agenda-sticky) nil "precondition violation")
  57. (cl-assert (not (org-test-agenda--agenda-buffers))
  58. nil "precondition violation")
  59. (let ((org-agenda-span 'day)
  60. (org-agenda-files `(,(expand-file-name "examples/agenda-file.org"
  61. org-test-dir))))
  62. (org-agenda-list nil "<2017-07-19 Wed>")
  63. (set-buffer org-agenda-buffer-name)
  64. (should
  65. (progn (goto-line 3)
  66. (looking-at " *agenda-file:Scheduled: *test agenda"))))
  67. (org-test-agenda--kill-all-agendas))
  68. (ert-deftest test-org-agenda/sticky-agenda-name ()
  69. "Agenda buffer name after having created one sticky agenda buffer."
  70. (cl-assert (not org-agenda-sticky) nil "precondition violation")
  71. (cl-assert (not (org-test-agenda--agenda-buffers))
  72. nil "precondition violation")
  73. (let ((org-agenda-span 'day)
  74. (buf (get-buffer org-agenda-buffer-name))
  75. org-agenda-files)
  76. (when buf (kill-buffer buf))
  77. (org-test-with-temp-text "<2017-03-17 Fri>"
  78. (org-follow-timestamp-link)) ;creates a sticky agenda
  79. (org-test-agenda--kill-all-agendas)
  80. (org-agenda-list)
  81. (should (= 1 (length (org-test-agenda--agenda-buffers))))
  82. (should (string= "*Org Agenda*"
  83. (buffer-name (car (org-test-agenda--agenda-buffers))))))
  84. (org-test-agenda--kill-all-agendas))
  85. (ert-deftest test-org-agenda/sticky-agenda-name-after-reload ()
  86. "Agenda buffer name of sticky agenda after reload."
  87. (cl-assert (not org-agenda-sticky) nil "precondition violation")
  88. (cl-assert (not (org-test-agenda--agenda-buffers))
  89. nil "precondition violation")
  90. (org-toggle-sticky-agenda)
  91. (let (org-agenda-files)
  92. (org-agenda-list)
  93. (let* ((agenda-buffer-name
  94. (progn
  95. (assert (= 1 (length (org-test-agenda--agenda-buffers))))
  96. (buffer-name (car (org-test-agenda--agenda-buffers))))))
  97. (set-buffer agenda-buffer-name)
  98. (org-agenda-redo)
  99. (should (= 1 (length (org-test-agenda--agenda-buffers))))
  100. (should (string= agenda-buffer-name
  101. (buffer-name (car (org-test-agenda--agenda-buffers)))))))
  102. (org-toggle-sticky-agenda)
  103. (org-test-agenda--kill-all-agendas))
  104. (provide 'test-org-agenda)
  105. ;;; test-org-agenda.el ends here