aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-04-22 07:19:41 -0500
committerCraig Jennings <c@cjennings.net>2026-04-22 07:19:41 -0500
commit8511cf43f2bf4ab2dc539fd28427e6c81c98b901 (patch)
treea0046f0b9517f85299b42b8e7941e8b749a9e56c /tests
parent4ae0429b6a32377cefbfb3d46d3bc9a5cb8613e9 (diff)
downloadchime-8511cf43f2bf4ab2dc539fd28427e6c81c98b901.tar.gz
chime-8511cf43f2bf4ab2dc539fd28427e6c81c98b901.zip
test: add unit tests for chime--day-label-for-event-time
Seven pure-function tests appended to the group-events-by-day file, covering Normal and Boundary cases. Normal: event on the same calendar day as NOW returns "Today, ...". Event on the same calendar day as TOMORROW returns "Tomorrow, ...". Event three days out returns a weekday label and is neither Today nor Tomorrow. Boundary: event at 00:00 on the NOW calendar day is Today. Event at 00:00 on the TOMORROW calendar day is Tomorrow. Event two calendar days out is not Tomorrow, gets a weekday label. Event on the previous calendar day is neither Today nor Tomorrow. Since NOW and TOMORROW are function arguments, the tests use encode-time to build stable calendar values and skip the clock-mocking dance.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-chime-group-events-by-day.el71
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/test-chime-group-events-by-day.el b/tests/test-chime-group-events-by-day.el
index ee7c923..b8546ee 100644
--- a/tests/test-chime-group-events-by-day.el
+++ b/tests/test-chime-group-events-by-day.el
@@ -267,6 +267,77 @@ instead of by calendar day."
(should (string-match-p "Tomorrow" (car (car result))))))
(test-chime-group-events-by-day-teardown)))
+;;;; Tests for chime--day-label-for-event-time
+
+;; Pure-function tests. NOW and TOMORROW are passed in, so no clock mocking
+;; is needed — we just construct stable calendar times with `encode-time'.
+
+(ert-deftest test-chime-day-label-normal-same-day-returns-today ()
+ "Normal: event on the same calendar day as NOW returns \"Today, ...\"."
+ (let* ((now (encode-time 0 0 12 15 5 2026)) ; 2026-05-15 12:00
+ (tomorrow (time-add now (days-to-time 1)))
+ (event (encode-time 0 0 9 15 5 2026)) ; 2026-05-15 09:00
+ (label (chime--day-label-for-event-time event now tomorrow)))
+ (should (stringp label))
+ (should (string-match-p "\\`Today" label))
+ (should (string-match-p "May 15" label))))
+
+(ert-deftest test-chime-day-label-normal-next-calendar-day-returns-tomorrow ()
+ "Normal: event on the same calendar day as TOMORROW returns \"Tomorrow, ...\"."
+ (let* ((now (encode-time 0 0 12 15 5 2026)) ; 2026-05-15 12:00
+ (tomorrow (time-add now (days-to-time 1)))
+ (event (encode-time 0 0 10 16 5 2026)) ; 2026-05-16 10:00
+ (label (chime--day-label-for-event-time event now tomorrow)))
+ (should (string-match-p "\\`Tomorrow" label))
+ (should (string-match-p "May 16" label))))
+
+(ert-deftest test-chime-day-label-normal-distant-future-returns-weekday ()
+ "Normal: event three days out returns a weekday label (not Today/Tomorrow)."
+ (let* ((now (encode-time 0 0 12 15 5 2026)) ; 2026-05-15 (Fri) 12:00
+ (tomorrow (time-add now (days-to-time 1)))
+ (event (encode-time 0 0 14 18 5 2026)) ; 2026-05-18 (Mon) 14:00
+ (label (chime--day-label-for-event-time event now tomorrow)))
+ (should (stringp label))
+ (should-not (string-match-p "\\`Today" label))
+ (should-not (string-match-p "\\`Tomorrow" label))
+ (should (string-match-p "Monday" label))
+ (should (string-match-p "May 18" label))))
+
+(ert-deftest test-chime-day-label-boundary-event-at-today-midnight ()
+ "Boundary: event at 00:00 on the same calendar day as NOW is Today."
+ (let* ((now (encode-time 0 0 12 15 5 2026)) ; 2026-05-15 12:00
+ (tomorrow (time-add now (days-to-time 1)))
+ (event (encode-time 0 0 0 15 5 2026)) ; 2026-05-15 00:00
+ (label (chime--day-label-for-event-time event now tomorrow)))
+ (should (string-match-p "\\`Today" label))))
+
+(ert-deftest test-chime-day-label-boundary-event-at-tomorrow-midnight ()
+ "Boundary: event at 00:00 on TOMORROW's calendar day is Tomorrow."
+ (let* ((now (encode-time 0 0 12 15 5 2026)) ; 2026-05-15 12:00
+ (tomorrow (time-add now (days-to-time 1)))
+ (event (encode-time 0 0 0 16 5 2026)) ; 2026-05-16 00:00
+ (label (chime--day-label-for-event-time event now tomorrow)))
+ (should (string-match-p "\\`Tomorrow" label))))
+
+(ert-deftest test-chime-day-label-boundary-day-after-tomorrow-is-weekday ()
+ "Boundary: event two calendar days out is NOT Tomorrow; gets a weekday label."
+ (let* ((now (encode-time 0 0 12 15 5 2026)) ; 2026-05-15 12:00
+ (tomorrow (time-add now (days-to-time 1)))
+ (event (encode-time 0 0 12 17 5 2026)) ; 2026-05-17 12:00
+ (label (chime--day-label-for-event-time event now tomorrow)))
+ (should-not (string-match-p "\\`Tomorrow" label))
+ (should (string-match-p "May 17" label))))
+
+(ert-deftest test-chime-day-label-boundary-yesterday-is-weekday ()
+ "Boundary: event on the previous calendar day is neither Today nor Tomorrow."
+ (let* ((now (encode-time 0 0 12 15 5 2026)) ; 2026-05-15 12:00
+ (tomorrow (time-add now (days-to-time 1)))
+ (event (encode-time 0 0 10 14 5 2026)) ; 2026-05-14 10:00
+ (label (chime--day-label-for-event-time event now tomorrow)))
+ (should-not (string-match-p "\\`Today" label))
+ (should-not (string-match-p "\\`Tomorrow" label))
+ (should (string-match-p "May 14" label))))
+
;;; Error Cases
(ert-deftest test-chime-group-events-by-day-error-nil-input ()