1 ;;; test-org-agenda.el --- Tests for org-agenda.el -*- lexical-binding: t ; -*-
3 ;; Copyright (C) 2017 Marco Wahl
5 ;; Author: Marco Wahl <marcowahlsoft@gmail.com>
7 ;; This program is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation, either version 3 of the License, or
10 ;; (at your option) any later version.
12 ;; This program is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
22 ;; Unit tests for Org Agenda.
30 ;; General auxilliaries
32 (defun org-test-agenda--agenda-buffers ()
33 "Return agenda buffers in a list."
34 (cl-remove-if-not (lambda (x)
35 (with-current-buffer x
36 (eq major-mode
'org-agenda-mode
)))
39 (defun org-test-agenda--kill-all-agendas ()
40 "Kill all agenda buffers."
42 (org-test-agenda--agenda-buffers)))
47 (ert-deftest test-org-agenda
/empty
()
49 (cl-assert (not org-agenda-sticky
) nil
"precondition violation")
50 (cl-assert (not (org-test-agenda--agenda-buffers))
51 nil
"precondition violation")
52 (let ((org-agenda-span 'day
)
55 (set-buffer org-agenda-buffer-name
)
56 (should (= 2 (count-lines (point-min) (point-max)))))
57 (org-test-agenda--kill-all-agendas))
59 (ert-deftest test-org-agenda
/one-line
()
60 "One informative line in the agenda."
61 (cl-assert (not org-agenda-sticky
) nil
"precondition violation")
62 (cl-assert (not (org-test-agenda--agenda-buffers))
63 nil
"precondition violation")
64 (let ((org-agenda-span 'day
)
65 (org-agenda-files `(,(expand-file-name "examples/agenda-file.org"
67 (org-agenda-list nil
"<2017-03-10 Fri>")
68 (set-buffer org-agenda-buffer-name
)
69 (should (= 3 (count-lines (point-min) (point-max)))))
70 (org-test-agenda--kill-all-agendas))
72 (ert-deftest test-org-agenda
/scheduled-non-todo
()
73 "One informative line in the agenda from scheduled non-todo-keyword-item."
74 (cl-assert (not org-agenda-sticky
) nil
"precondition violation")
75 (cl-assert (not (org-test-agenda--agenda-buffers))
76 nil
"precondition violation")
77 (let ((org-agenda-span 'day
)
78 (org-agenda-files `(,(expand-file-name "examples/agenda-file.org"
80 (org-agenda-list nil
"<2017-07-19 Wed>")
81 (set-buffer org-agenda-buffer-name
)
84 (looking-at " *agenda-file:Scheduled: *test agenda"))))
85 (org-test-agenda--kill-all-agendas))
87 (ert-deftest test-org-agenda
/sticky-agenda-name
()
88 "Agenda buffer name after having created one sticky agenda buffer."
89 (cl-assert (not org-agenda-sticky
) nil
"precondition violation")
90 (cl-assert (not (org-test-agenda--agenda-buffers))
91 nil
"precondition violation")
92 (let ((org-agenda-span 'day
)
93 (buf (get-buffer org-agenda-buffer-name
))
95 (when buf
(kill-buffer buf
))
96 (org-test-with-temp-text "<2017-03-17 Fri>"
97 (org-follow-timestamp-link)) ;creates a sticky agenda
98 (org-test-agenda--kill-all-agendas)
100 (should (= 1 (length (org-test-agenda--agenda-buffers))))
101 (should (string= "*Org Agenda*"
102 (buffer-name (car (org-test-agenda--agenda-buffers))))))
103 (org-test-agenda--kill-all-agendas))
105 (ert-deftest test-org-agenda
/sticky-agenda-name-after-reload
()
106 "Agenda buffer name of sticky agenda after reload."
107 (cl-assert (not org-agenda-sticky
) nil
"precondition violation")
108 (cl-assert (not (org-test-agenda--agenda-buffers))
109 nil
"precondition violation")
110 (org-toggle-sticky-agenda)
111 (let (org-agenda-files)
113 (let* ((agenda-buffer-name
115 (assert (= 1 (length (org-test-agenda--agenda-buffers))))
116 (buffer-name (car (org-test-agenda--agenda-buffers))))))
117 (set-buffer agenda-buffer-name
)
119 (should (= 1 (length (org-test-agenda--agenda-buffers))))
120 (should (string= agenda-buffer-name
121 (buffer-name (car (org-test-agenda--agenda-buffers)))))))
122 (org-toggle-sticky-agenda)
123 (org-test-agenda--kill-all-agendas))
126 (provide 'test-org-agenda
)
128 ;;; test-org-agenda.el ends here