blob: 260abfcca9df29c90d49f96172278bcb6c1d5a45 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
;;; test-chime-day-wide-notifications.el --- Tests for chime--day-wide-notifications -*- lexical-binding: t; -*-
;; Copyright (C) 2026 Craig Jennings
;; Author: Craig Jennings <c@cjennings.net>
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;; Commentary:
;; Direct unit tests for `chime--day-wide-notifications', which combines the
;; day-wide filter, the notification-text builder, dedup, and severity
;; wrapping into a single pipeline.
;;
;; Mock-clock note: `with-test-time' replaces `current-time' with a lambda
;; that returns the captured base time. The base must be computed BEFORE
;; entering the macro, because `test-time-now' itself calls `current-time'
;; — passing `(test-time-now)' inside the macro causes infinite recursion.
;;; Code:
(require 'test-bootstrap (expand-file-name "test-bootstrap.el"))
(require 'testutil-time (expand-file-name "testutil-time.el"))
(ert-deftest test-chime-day-wide-notifications-normal-wraps-with-medium-severity ()
"Normal: each generated text is wrapped as (TEXT . \\='medium)."
(let* ((base (test-time-now))
(today (test-time-today-at 0 0))
(ts (test-timestamp-string today t))
(event (chime--make-event (list (cons ts nil))
"Birthday"
'((0 . medium))))
(chime-day-wide-advance-notice nil)
(chime-show-any-overdue-with-day-wide-alerts t))
(with-test-time base
(let ((result (chime--day-wide-notifications (list event))))
(should (= 1 (length result)))
(should (eq 'medium (cdr (car result))))
(should (stringp (car (car result))))
(should (string-match-p "Birthday" (car (car result))))))))
(ert-deftest test-chime-day-wide-notifications-boundary-empty-events ()
"Boundary: empty events list yields empty notification list."
(should (null (chime--day-wide-notifications '()))))
(ert-deftest test-chime-day-wide-notifications-boundary-deduplicates-identical-text ()
"Boundary: two events producing identical notification text collapse to one."
(let* ((base (test-time-now))
(today (test-time-today-at 0 0))
(ts (test-timestamp-string today t))
(event1 (chime--make-event (list (cons ts nil))
"Birthday"
'((0 . medium))))
(event2 (chime--make-event (list (cons ts nil))
"Birthday"
'((0 . medium))))
(chime-day-wide-advance-notice nil)
(chime-show-any-overdue-with-day-wide-alerts t))
(with-test-time base
(let ((result (chime--day-wide-notifications (list event1 event2))))
(should (= 1 (length result)))))))
(ert-deftest test-chime-day-wide-notifications-boundary-filters-non-day-wide-events ()
"Boundary: events that don't pass the day-wide filter contribute nothing."
(let* ((base (test-time-now))
(future (test-time-tomorrow-at 9 0))
(ts (test-timestamp-string future))
(event (chime--make-event (list (cons ts future))
"Future Timed"
'((10 . medium))))
(chime-day-wide-advance-notice nil)
(chime-show-any-overdue-with-day-wide-alerts t))
(with-test-time base
(should (null (chime--day-wide-notifications (list event)))))))
(provide 'test-chime-day-wide-notifications)
;;; test-chime-day-wide-notifications.el ends here
|