Fix opening custom ID links with percent escaped syntax
[org-mode/org-tableheadings.git] / testing / lisp / test-org-agenda.el
blobb28e122e978886a49032e98bbb7fb33560a643cf
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)
28 (eval-and-compile (require 'cl-lib))
31 ;; General auxilliaries
33 (defun org-test-agenda--agenda-buffers ()
34 "Return agenda buffers in a list."
35 (cl-remove-if-not (lambda (x)
36 (with-current-buffer x
37 (eq major-mode 'org-agenda-mode)))
38 (buffer-list)))
40 (defun org-test-agenda--kill-all-agendas ()
41 "Kill all agenda buffers."
42 (mapc #'kill-buffer
43 (org-test-agenda--agenda-buffers)))
46 ;; Test the Agenda
48 (ert-deftest test-org-agenda/empty ()
49 "Empty agenda."
50 (cl-assert (not org-agenda-sticky) nil "precondition violation")
51 (cl-assert (not (org-test-agenda--agenda-buffers))
52 nil "precondition violation")
53 (let ((org-agenda-span 'day)
54 org-agenda-files)
55 (org-agenda-list)
56 (set-buffer org-agenda-buffer-name)
57 (should (= 2 (count-lines (point-min) (point-max)))))
58 (org-test-agenda--kill-all-agendas))
60 (ert-deftest test-org-agenda/one-line ()
61 "One informative line in the agenda."
62 (cl-assert (not org-agenda-sticky) nil "precondition violation")
63 (cl-assert (not (org-test-agenda--agenda-buffers))
64 nil "precondition violation")
65 (let ((org-agenda-span 'day)
66 (org-agenda-files `(,(expand-file-name "examples/agenda-file.org"
67 org-test-dir))))
68 (org-agenda-list nil "<2017-03-10 Fri>")
69 (set-buffer org-agenda-buffer-name)
70 (should (= 3 (count-lines (point-min) (point-max)))))
71 (org-test-agenda--kill-all-agendas))
73 (ert-deftest test-org-agenda/scheduled-non-todo ()
74 "One informative line in the agenda from scheduled non-todo-keyword-item."
75 (cl-assert (not org-agenda-sticky) nil "precondition violation")
76 (cl-assert (not (org-test-agenda--agenda-buffers))
77 nil "precondition violation")
78 (let ((org-agenda-span 'day)
79 (org-agenda-files `(,(expand-file-name "examples/agenda-file.org"
80 org-test-dir))))
81 (org-agenda-list nil "<2017-07-19 Wed>")
82 (set-buffer org-agenda-buffer-name)
83 (should
84 (progn (goto-line 3)
85 (looking-at " *agenda-file:Scheduled: *test agenda"))))
86 (org-test-agenda--kill-all-agendas))
88 (ert-deftest test-org-agenda/set-priority ()
89 "One informative line in the agenda. Check that org-agenda-priority updates the agenda."
90 (cl-assert (not org-agenda-sticky) nil "precondition violation")
91 (cl-assert (not (org-test-agenda--agenda-buffers))
92 nil "precondition violation")
93 (let ((org-agenda-span 'day)
94 (org-agenda-files `(,(expand-file-name "examples/agenda-file.org"
95 org-test-dir))))
96 (org-agenda-list nil "<2017-07-19 Wed>")
97 (set-buffer org-agenda-buffer-name)
99 (should
100 (progn (goto-line 3)
101 (org-agenda-priority ?B)
102 (looking-at-p " *agenda-file:Scheduled: *\\[#B\\] test agenda"))))
103 (org-test-agenda--kill-all-agendas))
105 (ert-deftest test-org-agenda/sticky-agenda-name ()
106 "Agenda buffer name after having created one sticky agenda buffer."
107 (cl-assert (not org-agenda-sticky) nil "precondition violation")
108 (cl-assert (not (org-test-agenda--agenda-buffers))
109 nil "precondition violation")
110 (let ((org-agenda-span 'day)
111 (buf (get-buffer org-agenda-buffer-name))
112 org-agenda-files)
113 (when buf (kill-buffer buf))
114 (org-test-with-temp-text "<2017-03-17 Fri>"
115 (org-follow-timestamp-link)) ;creates a sticky agenda
116 (org-test-agenda--kill-all-agendas)
117 (org-agenda-list)
118 (should (= 1 (length (org-test-agenda--agenda-buffers))))
119 (should (string= "*Org Agenda*"
120 (buffer-name (car (org-test-agenda--agenda-buffers))))))
121 (org-test-agenda--kill-all-agendas))
123 (ert-deftest test-org-agenda/sticky-agenda-name-after-reload ()
124 "Agenda buffer name of sticky agenda after reload."
125 (cl-assert (not org-agenda-sticky) nil "precondition violation")
126 (cl-assert (not (org-test-agenda--agenda-buffers))
127 nil "precondition violation")
128 (org-toggle-sticky-agenda)
129 (let (org-agenda-files)
130 (org-agenda-list)
131 (let* ((agenda-buffer-name
132 (progn
133 (cl-assert (= 1 (length (org-test-agenda--agenda-buffers))))
134 (buffer-name (car (org-test-agenda--agenda-buffers))))))
135 (set-buffer agenda-buffer-name)
136 (org-agenda-redo)
137 (should (= 1 (length (org-test-agenda--agenda-buffers))))
138 (should (string= agenda-buffer-name
139 (buffer-name (car (org-test-agenda--agenda-buffers)))))))
140 (org-toggle-sticky-agenda)
141 (org-test-agenda--kill-all-agendas))
144 ;; agenda redo
146 (require 'face-remap)
148 (ert-deftest test-org-agenda/rescale ()
149 "Text scale survives `org-agenda-redo'."
150 (org-test-agenda--kill-all-agendas)
151 (unwind-protect
152 (let ((org-agenda-span 'day)
153 org-agenda-files)
154 (org-agenda-list)
155 (set-buffer org-agenda-buffer-name)
156 (text-scale-mode)
157 (text-scale-set 11)
158 (cl-assert (and (boundp text-scale-mode) text-scale-mode))
159 (org-agenda-redo)
160 (should text-scale-mode)
161 (should (= 11 text-scale-mode-amount)))
162 (org-test-agenda--kill-all-agendas)))
165 (provide 'test-org-agenda)
167 ;;; test-org-agenda.el ends here