test-org-agenda: Non-todo-kwd scheduled item must appear in agenda
[org-mode.git] / testing / lisp / test-org-agenda.el
blob59b7f0baf1463ef553e63a8a9231be77245ad216
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/>.
20 ;;; Commentary:
22 ;; Unit tests for Org Agenda.
24 ;;; Code:
26 (require 'org-test)
27 (require 'org-agenda)
30 ;; General auxilliaries
32 ;; (possibly better move to some location in the source.)
34 ;; Prefixing with '---' on this page.
36 ;; Evaluate the following function for no brainer function naming.
37 (defun ---sha1-as-defun-name-39e8857766df959d8b52f9c38739f5a77c392ec0 ()
38 "Insert the sha1 of the function text in front of arglist.
39 The function text starts at the argument list and ends at the
40 last paren (exclusive).
41 Use this function if you are too lazy to invent a function name."
42 (interactive)
43 (let* ((start (progn
44 (beginning-of-defun)
45 (search-forward-regexp "\(" nil nil 2)
46 (backward-char)
47 (point)))
48 (end (progn
49 (end-of-defun)
50 (backward-char)
51 (point)))
52 (sha1 (sha1 (current-buffer) start end)))
53 (goto-char start)
54 (insert sha1 " ")
55 (backward-word)))
57 (defun ---kill-all-agendas ()
58 "Kill all agenda buffers."
59 (mapc #'kill-buffer
60 (cl-remove-if-not
61 (lambda (x)
62 (set-buffer x)
63 (eq major-mode 'org-agenda-mode))
64 (buffer-list))))
66 (defun ---agenda-buffers ()
67 "Return agenda buffers in a list."
68 (cl-remove-if-not
69 (lambda (x)
70 (set-buffer x)
71 (eq major-mode 'org-agenda-mode))
72 (buffer-list)))
75 ;; Test the Agenda
77 (ert-deftest org-agenda-90c5dce0435b74ba7e9682a4a9a393aeea741739 ()
78 "Empty agenda."
79 (cl-assert (not org-agenda-sticky) nil "precondition violation")
80 (cl-assert (not (---agenda-buffers)) nil "precondition violation")
81 (let ((org-agenda-span 'day)
82 org-agenda-files)
83 (org-agenda-list)
84 (set-buffer org-agenda-buffer-name)
85 (should (= 2 (count-lines (point-min) (point-max)))))
86 (---kill-all-agendas))
88 (ert-deftest org-agenda-668f0e69003051b79eb421146f7626ac9438c105 ()
89 "One informative line in the agenda."
90 (cl-assert (not org-agenda-sticky) nil "precondition violation")
91 (cl-assert (not (---agenda-buffers)) nil "precondition violation")
92 (let ((org-agenda-span 'day)
93 (org-agenda-files `(,(expand-file-name "examples/agenda-file.org" org-test-dir))))
94 (org-agenda-list nil "<2017-03-10 Fri>")
95 (set-buffer org-agenda-buffer-name)
96 (should (= 3 (count-lines (point-min) (point-max)))))
97 (---kill-all-agendas))
99 (ert-deftest org-agenda-91d525871b9003e779df915566bfc0cbf91a24a4 ()
100 "One informative line in the agenda from scheduled non-todo-keyword-item."
101 (cl-assert (not org-agenda-sticky) nil "precondition violation")
102 (cl-assert (not (---agenda-buffers)) nil "precondition violation")
103 (let ((org-agenda-span 'day)
104 (org-agenda-files `(,(expand-file-name "examples/agenda-file.org" org-test-dir))))
105 (org-agenda-list nil "<2017-07-19 Wed>")
106 (set-buffer org-agenda-buffer-name)
107 (should (progn (goto-line 3) (looking-at " *agenda-file:Scheduled: *test agenda"))))
108 (---kill-all-agendas))
110 (ert-deftest org-agenda-8e6c85e9ff1ea9fed0ae0fa04ff9a3dace6c9d17 ()
111 "Agenda buffer name after having created one sticky agenda buffer."
112 (cl-assert (not org-agenda-sticky) nil "precondition violation")
113 (cl-assert (not (---agenda-buffers)) nil "precondition violation")
114 (let ((org-agenda-span 'day)
115 (buf (get-buffer org-agenda-buffer-name))
116 org-agenda-files)
117 (when buf (kill-buffer buf))
118 (org-test-with-temp-text "<2017-03-17 Fri>"
119 (org-follow-timestamp-link) ; creates a sticky agenda.
121 (---kill-all-agendas)
122 (org-agenda-list)
123 (should (= 1 (length (---agenda-buffers))))
124 (should (string= "*Org Agenda*"
125 (buffer-name (car (---agenda-buffers))))))
126 (---kill-all-agendas))
128 (ert-deftest org-agenda-9fa27658bf61d8fe2c5b6f9177e9e8ce07f11f7b ()
129 "Agenda buffer name of sticky agenda after reload."
130 (cl-assert (not org-agenda-sticky) nil "precondition violation")
131 (cl-assert (not (---agenda-buffers)) nil "precondition violation")
132 (org-toggle-sticky-agenda)
133 (let (org-agenda-files)
134 (org-agenda-list)
135 (let* ((agenda-buffer-name
136 (progn
137 (assert (= 1 (length (---agenda-buffers))))
138 (buffer-name (car (---agenda-buffers))))))
139 (set-buffer agenda-buffer-name)
140 (org-agenda-redo)
141 (should (= 1 (length (---agenda-buffers))))
142 (should (string= agenda-buffer-name
143 (buffer-name (car (---agenda-buffers)))))))
144 (org-toggle-sticky-agenda)
145 (---kill-all-agendas))
148 (provide 'test-org-agenda)
150 ;;; test-org-agenda.el ends here