org-manual: Improve accuracy of a paragraph
[org-mode/org-tableheadings.git] / testing / lisp / test-org-agenda.el
blobfca8896e8fc61ee0a46072f8167f541b2f1e9c6b
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 (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)))
37 (buffer-list)))
39 (defun org-test-agenda--kill-all-agendas ()
40 "Kill all agenda buffers."
41 (mapc #'kill-buffer
42 (org-test-agenda--agenda-buffers)))
45 ;; Test the Agenda
47 (ert-deftest test-org-agenda/empty ()
48 "Empty agenda."
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)
53 org-agenda-files)
54 (org-agenda-list)
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"
66 org-test-dir))))
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"
79 org-test-dir))))
80 (org-agenda-list nil "<2017-07-19 Wed>")
81 (set-buffer org-agenda-buffer-name)
82 (should
83 (progn (goto-line 3)
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))
94 org-agenda-files)
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)
99 (org-agenda-list)
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)
112 (org-agenda-list)
113 (let* ((agenda-buffer-name
114 (progn
115 (assert (= 1 (length (org-test-agenda--agenda-buffers))))
116 (buffer-name (car (org-test-agenda--agenda-buffers))))))
117 (set-buffer agenda-buffer-name)
118 (org-agenda-redo)
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