aboutsummaryrefslogtreecommitdiff
path: root/tests/test-chime-process-notifications.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-06-24 16:18:27 -0400
committerCraig Jennings <c@cjennings.net>2026-06-24 16:18:27 -0400
commitd47f4f90bb1c69697a855a662bb07be1e0ccdc33 (patch)
tree777d0b786a530cb4190f8e062e0afda2506308d4 /tests/test-chime-process-notifications.el
parentab8cc4da57fce5d0a59f4db34fb550919a06ea79 (diff)
downloadchime-d47f4f90bb1c69697a855a662bb07be1e0ccdc33.tar.gz
chime-d47f4f90bb1c69697a855a662bb07be1e0ccdc33.zip
test: add chime-deftest fixture macro and centralize test requiresHEADmain
Every test hand-wrote the same scaffolding: call a per-file setup, wrap the body in unwind-protect, call a per-file teardown. That's 419 unwind-protect blocks and 68 near-identical setup/teardown defuns, with no shared fixture because ERT has no native per-test setup. I added a chime-deftest macro in test-bootstrap that creates the test base directory before the body and deletes it afterward, even on failure. I converted the 10 files whose fixture was exactly that base-dir create/delete and whose every test followed the standard shape, dropping their setup/teardown defuns. Files with custom fixtures (modeline state restore, validation reset) keep explicit setup/teardown, since the macro would silently drop their extra logic. I left the 4 tag-bearing integration files alone. I also moved the near-universal testutil-general and testutil-time requires into test-bootstrap, so individual files no longer repeat them. Behavior is unchanged: still 800 tests, full suite green. Converted bodies are copied verbatim, so the change only removes scaffolding, never an assertion.
Diffstat (limited to 'tests/test-chime-process-notifications.el')
-rw-r--r--tests/test-chime-process-notifications.el567
1 files changed, 257 insertions, 310 deletions
diff --git a/tests/test-chime-process-notifications.el b/tests/test-chime-process-notifications.el
index 75cac9b..1a93842 100644
--- a/tests/test-chime-process-notifications.el
+++ b/tests/test-chime-process-notifications.el
@@ -26,363 +26,310 @@
(require 'test-bootstrap (expand-file-name "test-bootstrap.el"))
-;; Load test utilities
-(require 'testutil-general (expand-file-name "testutil-general.el"))
-(require 'testutil-time (expand-file-name "testutil-time.el"))
-
-;;; Setup and Teardown
-
-(defun test-chime-process-notifications-setup ()
- "Setup function run before each test."
- (chime-create-test-base-dir))
-
-(defun test-chime-process-notifications-teardown ()
- "Teardown function run after each test."
- (chime-delete-test-base-dir))
-
;;; Normal Cases
-(ert-deftest test-chime-process-notifications-normal-single-event-calls-notify ()
+(chime-deftest test-chime-process-notifications-normal-single-event-calls-notify ()
"Test that single event with notification calls chime--notify.
REFACTORED: Uses dynamic timestamps and with-test-time"
- (test-chime-process-notifications-setup)
- (unwind-protect
- (let* ((now (test-time-today-at 14 0))
- ;; Event at 14:10 (10 minutes from now)
- (event-time (test-time-today-at 14 10))
- (timestamp-str (test-timestamp-string event-time))
- (notify-called nil)
- (notify-messages '()))
- (with-test-time now
- (cl-letf (((symbol-function 'chime--notify)
- (lambda (msg)
- (setq notify-called t)
- (push msg notify-messages)))
- ((symbol-function 'chime--current-time-is-day-wide-time)
- (lambda () nil)))
- (let* ((event `((times . ((,timestamp-str . ,event-time)))
- (title . "Team Meeting")
- (intervals . ((10 . medium)))))
- (events (list event)))
- (chime--process-notifications events)
- ;; Should call notify
- (should notify-called)
- (should (= 1 (length notify-messages)))
- (should (string-match-p "Team Meeting" (caar notify-messages)))))))
- (test-chime-process-notifications-teardown)))
-
-(ert-deftest test-chime-process-notifications-normal-multiple-events-calls-notify-multiple-times ()
+ (let* ((now (test-time-today-at 14 0))
+ ;; Event at 14:10 (10 minutes from now)
+ (event-time (test-time-today-at 14 10))
+ (timestamp-str (test-timestamp-string event-time))
+ (notify-called nil)
+ (notify-messages '()))
+ (with-test-time now
+ (cl-letf (((symbol-function 'chime--notify)
+ (lambda (msg)
+ (setq notify-called t)
+ (push msg notify-messages)))
+ ((symbol-function 'chime--current-time-is-day-wide-time)
+ (lambda () nil)))
+ (let* ((event `((times . ((,timestamp-str . ,event-time)))
+ (title . "Team Meeting")
+ (intervals . ((10 . medium)))))
+ (events (list event)))
+ (chime--process-notifications events)
+ ;; Should call notify
+ (should notify-called)
+ (should (= 1 (length notify-messages)))
+ (should (string-match-p "Team Meeting" (caar notify-messages))))))))
+
+(chime-deftest test-chime-process-notifications-normal-multiple-events-calls-notify-multiple-times ()
"Test that multiple events with notifications call chime--notify multiple times.
REFACTORED: Uses dynamic timestamps and with-test-time"
- (test-chime-process-notifications-setup)
- (unwind-protect
- (let* ((now (test-time-today-at 14 0))
- ;; Event 1 at 14:10
- (event-time-1 (test-time-today-at 14 10))
- (timestamp-str-1 (test-timestamp-string event-time-1))
- ;; Event 2 at 14:05
- (event-time-2 (test-time-today-at 14 5))
- (timestamp-str-2 (test-timestamp-string event-time-2))
- (notify-count 0))
- (with-test-time now
- (cl-letf (((symbol-function 'chime--notify)
- (lambda (msg) (setq notify-count (1+ notify-count))))
- ((symbol-function 'chime--current-time-is-day-wide-time)
- (lambda () nil)))
- (let* ((event1 `((times . ((,timestamp-str-1 . ,event-time-1)))
- (title . "Meeting 1")
- (intervals . ((10 . medium)))))
- (event2 `((times . ((,timestamp-str-2 . ,event-time-2)))
- (title . "Meeting 2")
- (intervals . ((5 . medium)))))
- (events (list event1 event2)))
- (chime--process-notifications events)
- ;; Should call notify twice (once per event)
- (should (= 2 notify-count))))))
- (test-chime-process-notifications-teardown)))
-
-(ert-deftest test-chime-process-notifications-normal-deduplication-removes-duplicates ()
+ (let* ((now (test-time-today-at 14 0))
+ ;; Event 1 at 14:10
+ (event-time-1 (test-time-today-at 14 10))
+ (timestamp-str-1 (test-timestamp-string event-time-1))
+ ;; Event 2 at 14:05
+ (event-time-2 (test-time-today-at 14 5))
+ (timestamp-str-2 (test-timestamp-string event-time-2))
+ (notify-count 0))
+ (with-test-time now
+ (cl-letf (((symbol-function 'chime--notify)
+ (lambda (msg) (setq notify-count (1+ notify-count))))
+ ((symbol-function 'chime--current-time-is-day-wide-time)
+ (lambda () nil)))
+ (let* ((event1 `((times . ((,timestamp-str-1 . ,event-time-1)))
+ (title . "Meeting 1")
+ (intervals . ((10 . medium)))))
+ (event2 `((times . ((,timestamp-str-2 . ,event-time-2)))
+ (title . "Meeting 2")
+ (intervals . ((5 . medium)))))
+ (events (list event1 event2)))
+ (chime--process-notifications events)
+ ;; Should call notify twice (once per event)
+ (should (= 2 notify-count)))))))
+
+(chime-deftest test-chime-process-notifications-normal-deduplication-removes-duplicates ()
"Test that duplicate notification messages are deduplicated.
REFACTORED: Uses dynamic timestamps and with-test-time"
- (test-chime-process-notifications-setup)
- (unwind-protect
- (let* ((now (test-time-today-at 14 0))
- ;; Two events with same title and time - should dedupe
- (event-time (test-time-today-at 14 10))
- (timestamp-str (test-timestamp-string event-time))
- (notify-messages '()))
- (with-test-time now
- (cl-letf (((symbol-function 'chime--notify)
- (lambda (msg) (push msg notify-messages)))
- ((symbol-function 'chime--current-time-is-day-wide-time)
- (lambda () nil)))
- (let* ((event1 `((times . ((,timestamp-str . ,event-time)))
- (title . "Team Meeting")
- (intervals . ((10 . medium)))))
- (event2 `((times . ((,timestamp-str . ,event-time)))
- (title . "Team Meeting")
- (intervals . ((10 . medium)))))
- (events (list event1 event2)))
- (chime--process-notifications events)
- ;; Should only call notify once due to deduplication
- (should (= 1 (length notify-messages)))))))
- (test-chime-process-notifications-teardown)))
-
-(ert-deftest test-chime-process-notifications-normal-day-wide-notifications-called-at-right-time ()
+ (let* ((now (test-time-today-at 14 0))
+ ;; Two events with same title and time - should dedupe
+ (event-time (test-time-today-at 14 10))
+ (timestamp-str (test-timestamp-string event-time))
+ (notify-messages '()))
+ (with-test-time now
+ (cl-letf (((symbol-function 'chime--notify)
+ (lambda (msg) (push msg notify-messages)))
+ ((symbol-function 'chime--current-time-is-day-wide-time)
+ (lambda () nil)))
+ (let* ((event1 `((times . ((,timestamp-str . ,event-time)))
+ (title . "Team Meeting")
+ (intervals . ((10 . medium)))))
+ (event2 `((times . ((,timestamp-str . ,event-time)))
+ (title . "Team Meeting")
+ (intervals . ((10 . medium)))))
+ (events (list event1 event2)))
+ (chime--process-notifications events)
+ ;; Should only call notify once due to deduplication
+ (should (= 1 (length notify-messages))))))))
+
+(chime-deftest test-chime-process-notifications-normal-day-wide-notifications-called-at-right-time ()
"Test that day-wide notifications are sent when current time matches.
REFACTORED: Uses dynamic timestamps and with-test-time"
- (test-chime-process-notifications-setup)
- (unwind-protect
- (let* ((now (test-time-today-at 9 0))
- ;; Day-wide event
- (event-time (test-time-today-at 0 0))
- (timestamp-str (test-timestamp-string event-time t)) ; Day-wide
- (notify-count 0))
- (with-test-time now
- (cl-letf (((symbol-function 'chime--notify)
- (lambda (msg) (setq notify-count (1+ notify-count))))
- ;; Mock day-wide time to return true
- ((symbol-function 'chime--current-time-is-day-wide-time)
- (lambda () t))
- ((symbol-function 'chime--day-wide-notifications)
- (lambda (events) (list "Day-wide alert"))))
- (let* ((event `((times . ((,timestamp-str . ,event-time)))
- (title . "All Day Event")
- (intervals . ())))
- (events (list event)))
- (chime--process-notifications events)
- ;; Should call notify at least once for day-wide
- (should (>= notify-count 1))))))
- (test-chime-process-notifications-teardown)))
-
-(ert-deftest test-chime-process-notifications-normal-no-day-wide-when-wrong-time ()
+ (let* ((now (test-time-today-at 9 0))
+ ;; Day-wide event
+ (event-time (test-time-today-at 0 0))
+ (timestamp-str (test-timestamp-string event-time t)) ; Day-wide
+ (notify-count 0))
+ (with-test-time now
+ (cl-letf (((symbol-function 'chime--notify)
+ (lambda (msg) (setq notify-count (1+ notify-count))))
+ ;; Mock day-wide time to return true
+ ((symbol-function 'chime--current-time-is-day-wide-time)
+ (lambda () t))
+ ((symbol-function 'chime--day-wide-notifications)
+ (lambda (events) (list "Day-wide alert"))))
+ (let* ((event `((times . ((,timestamp-str . ,event-time)))
+ (title . "All Day Event")
+ (intervals . ())))
+ (events (list event)))
+ (chime--process-notifications events)
+ ;; Should call notify at least once for day-wide
+ (should (>= notify-count 1)))))))
+
+(chime-deftest test-chime-process-notifications-normal-no-day-wide-when-wrong-time ()
"Test that day-wide notifications are not sent when time doesn't match.
REFACTORED: Uses dynamic timestamps and with-test-time"
- (test-chime-process-notifications-setup)
- (unwind-protect
- (let* ((now (test-time-today-at 14 0))
- (event-time (test-time-today-at 0 0))
- (timestamp-str (test-timestamp-string event-time t)) ; Day-wide
- (day-wide-called nil))
- (with-test-time now
- (cl-letf (((symbol-function 'chime--notify) (lambda (msg) nil))
- ;; Mock day-wide time to return false
- ((symbol-function 'chime--current-time-is-day-wide-time)
- (lambda () nil))
- ((symbol-function 'chime--day-wide-notifications)
- (lambda (events)
- (setq day-wide-called t)
- '())))
- (let* ((event `((times . ((,timestamp-str . ,event-time)))
- (title . "All Day Event")
- (intervals . ())))
- (events (list event)))
- (chime--process-notifications events)
- ;; Day-wide function should not be called
- (should-not day-wide-called)))))
- (test-chime-process-notifications-teardown)))
+ (let* ((now (test-time-today-at 14 0))
+ (event-time (test-time-today-at 0 0))
+ (timestamp-str (test-timestamp-string event-time t)) ; Day-wide
+ (day-wide-called nil))
+ (with-test-time now
+ (cl-letf (((symbol-function 'chime--notify) (lambda (msg) nil))
+ ;; Mock day-wide time to return false
+ ((symbol-function 'chime--current-time-is-day-wide-time)
+ (lambda () nil))
+ ((symbol-function 'chime--day-wide-notifications)
+ (lambda (events)
+ (setq day-wide-called t)
+ '())))
+ (let* ((event `((times . ((,timestamp-str . ,event-time)))
+ (title . "All Day Event")
+ (intervals . ())))
+ (events (list event)))
+ (chime--process-notifications events)
+ ;; Day-wide function should not be called
+ (should-not day-wide-called))))))
;;; Boundary Cases
-(ert-deftest test-chime-process-notifications-boundary-empty-events-no-notifications ()
+(chime-deftest test-chime-process-notifications-boundary-empty-events-no-notifications ()
"Test that empty events list produces no notifications.
REFACTORED: No timestamps used"
- (test-chime-process-notifications-setup)
- (unwind-protect
- (let ((notify-called nil))
- (cl-letf (((symbol-function 'chime--notify)
- (lambda (msg) (setq notify-called t)))
- ((symbol-function 'chime--current-time-is-day-wide-time)
- (lambda () nil)))
- (let ((events '()))
- (chime--process-notifications events)
- ;; Should not call notify
- (should-not notify-called))))
- (test-chime-process-notifications-teardown)))
-
-(ert-deftest test-chime-process-notifications-boundary-events-with-no-matches-no-notifications ()
+ (let ((notify-called nil))
+ (cl-letf (((symbol-function 'chime--notify)
+ (lambda (msg) (setq notify-called t)))
+ ((symbol-function 'chime--current-time-is-day-wide-time)
+ (lambda () nil)))
+ (let ((events '()))
+ (chime--process-notifications events)
+ ;; Should not call notify
+ (should-not notify-called)))))
+
+(chime-deftest test-chime-process-notifications-boundary-events-with-no-matches-no-notifications ()
"Test that events with no matching notifications don't call notify.
REFACTORED: Uses dynamic timestamps and with-test-time"
- (test-chime-process-notifications-setup)
- (unwind-protect
- (let* ((now (test-time-today-at 14 0))
- ;; Event at 15:00 (60 minutes away, doesn't match 10 min interval)
- (event-time (test-time-today-at 15 0))
- (timestamp-str (test-timestamp-string event-time))
- (notify-called nil))
- (with-test-time now
- (cl-letf (((symbol-function 'chime--notify)
- (lambda (msg) (setq notify-called t)))
- ((symbol-function 'chime--current-time-is-day-wide-time)
- (lambda () nil)))
- (let* ((event `((times . ((,timestamp-str . ,event-time)))
- (title . "Future Event")
- (intervals . ((10 . medium)))))
- (events (list event)))
- (chime--process-notifications events)
- ;; Should not call notify
- (should-not notify-called)))))
- (test-chime-process-notifications-teardown)))
-
-(ert-deftest test-chime-process-notifications-boundary-single-event-edge-case ()
+ (let* ((now (test-time-today-at 14 0))
+ ;; Event at 15:00 (60 minutes away, doesn't match 10 min interval)
+ (event-time (test-time-today-at 15 0))
+ (timestamp-str (test-timestamp-string event-time))
+ (notify-called nil))
+ (with-test-time now
+ (cl-letf (((symbol-function 'chime--notify)
+ (lambda (msg) (setq notify-called t)))
+ ((symbol-function 'chime--current-time-is-day-wide-time)
+ (lambda () nil)))
+ (let* ((event `((times . ((,timestamp-str . ,event-time)))
+ (title . "Future Event")
+ (intervals . ((10 . medium)))))
+ (events (list event)))
+ (chime--process-notifications events)
+ ;; Should not call notify
+ (should-not notify-called))))))
+
+(chime-deftest test-chime-process-notifications-boundary-single-event-edge-case ()
"Test processing single event works correctly.
REFACTORED: Uses dynamic timestamps and with-test-time"
- (test-chime-process-notifications-setup)
- (unwind-protect
- (let* ((now (test-time-today-at 14 0))
- (event-time (test-time-today-at 14 10))
- (timestamp-str (test-timestamp-string event-time))
- (notify-count 0))
- (with-test-time now
- (cl-letf (((symbol-function 'chime--notify)
- (lambda (msg) (setq notify-count (1+ notify-count))))
- ((symbol-function 'chime--current-time-is-day-wide-time)
- (lambda () nil)))
- (let* ((event `((times . ((,timestamp-str . ,event-time)))
- (title . "Single Event")
- (intervals . ((10 . medium)))))
- (events (list event)))
- (chime--process-notifications events)
- ;; Should call notify exactly once
- (should (= 1 notify-count))))))
- (test-chime-process-notifications-teardown)))
+ (let* ((now (test-time-today-at 14 0))
+ (event-time (test-time-today-at 14 10))
+ (timestamp-str (test-timestamp-string event-time))
+ (notify-count 0))
+ (with-test-time now
+ (cl-letf (((symbol-function 'chime--notify)
+ (lambda (msg) (setq notify-count (1+ notify-count))))
+ ((symbol-function 'chime--current-time-is-day-wide-time)
+ (lambda () nil)))
+ (let* ((event `((times . ((,timestamp-str . ,event-time)))
+ (title . "Single Event")
+ (intervals . ((10 . medium)))))
+ (events (list event)))
+ (chime--process-notifications events)
+ ;; Should call notify exactly once
+ (should (= 1 notify-count)))))))
;;; Error Cases
-(ert-deftest test-chime-process-notifications-error-nil-events-handles-gracefully ()
+(chime-deftest test-chime-process-notifications-error-nil-events-handles-gracefully ()
"Test that nil events parameter doesn't crash.
REFACTORED: No timestamps used"
- (test-chime-process-notifications-setup)
- (unwind-protect
- (let ((notify-called nil))
- (cl-letf (((symbol-function 'chime--notify)
- (lambda (msg) (setq notify-called t)))
- ((symbol-function 'chime--current-time-is-day-wide-time)
- (lambda () nil)))
- ;; Should not error with nil events
- (should-not (condition-case nil
- (progn (chime--process-notifications nil) nil)
- (error t)))
- ;; Should not call notify
- (should-not notify-called)))
- (test-chime-process-notifications-teardown)))
-
-(ert-deftest test-chime-process-notifications-error-invalid-event-structure-handles-gracefully ()
+ (let ((notify-called nil))
+ (cl-letf (((symbol-function 'chime--notify)
+ (lambda (msg) (setq notify-called t)))
+ ((symbol-function 'chime--current-time-is-day-wide-time)
+ (lambda () nil)))
+ ;; Should not error with nil events
+ (should-not (condition-case nil
+ (progn (chime--process-notifications nil) nil)
+ (error t)))
+ ;; Should not call notify
+ (should-not notify-called))))
+
+(chime-deftest test-chime-process-notifications-error-invalid-event-structure-handles-gracefully ()
"Test that invalid event structure doesn't crash.
REFACTORED: Uses dynamic timestamps and with-test-time"
- (test-chime-process-notifications-setup)
- (unwind-protect
- (let* ((now (test-time-today-at 14 0))
- (notify-called nil))
- (with-test-time now
- (cl-letf (((symbol-function 'chime--notify)
- (lambda (msg) (setq notify-called t)))
- ((symbol-function 'chime--current-time-is-day-wide-time)
- (lambda () nil)))
- (let* (;; Invalid event: missing required fields
- (events (list '((invalid . "structure")))))
- ;; Should not crash even with invalid events
- (should-not (condition-case nil
- (progn (chime--process-notifications events) nil)
- (error t)))))))
- (test-chime-process-notifications-teardown)))
-
-(ert-deftest test-chime-process-notifications-error-mixed-valid-invalid-events-processes-valid ()
+ (let* ((now (test-time-today-at 14 0))
+ (notify-called nil))
+ (with-test-time now
+ (cl-letf (((symbol-function 'chime--notify)
+ (lambda (msg) (setq notify-called t)))
+ ((symbol-function 'chime--current-time-is-day-wide-time)
+ (lambda () nil)))
+ (let* (;; Invalid event: missing required fields
+ (events (list '((invalid . "structure")))))
+ ;; Should not crash even with invalid events
+ (should-not (condition-case nil
+ (progn (chime--process-notifications events) nil)
+ (error t))))))))
+
+(chime-deftest test-chime-process-notifications-error-mixed-valid-invalid-events-processes-valid ()
"Test that mix of valid and invalid events processes valid ones.
REFACTORED: Uses dynamic timestamps and with-test-time"
- (test-chime-process-notifications-setup)
- (unwind-protect
- (let* ((now (test-time-today-at 14 0))
- ;; Valid event
- (event-time (test-time-today-at 14 10))
- (timestamp-str (test-timestamp-string event-time))
- (notify-count 0))
- (with-test-time now
- (cl-letf (((symbol-function 'chime--notify)
- (lambda (msg) (setq notify-count (1+ notify-count))))
- ((symbol-function 'chime--current-time-is-day-wide-time)
- (lambda () nil)))
- (let* ((valid-event `((times . ((,timestamp-str . ,event-time)))
- (title . "Valid Event")
- (intervals . ((10 . medium)))))
- ;; Invalid event
- (invalid-event '((invalid . "data")))
- (events (list valid-event invalid-event)))
- ;; Should not crash
- (should-not (condition-case nil
- (progn (chime--process-notifications events) nil)
- (error t)))
- ;; Should process at least the valid event
- (should (>= notify-count 1))))))
- (test-chime-process-notifications-teardown)))
+ (let* ((now (test-time-today-at 14 0))
+ ;; Valid event
+ (event-time (test-time-today-at 14 10))
+ (timestamp-str (test-timestamp-string event-time))
+ (notify-count 0))
+ (with-test-time now
+ (cl-letf (((symbol-function 'chime--notify)
+ (lambda (msg) (setq notify-count (1+ notify-count))))
+ ((symbol-function 'chime--current-time-is-day-wide-time)
+ (lambda () nil)))
+ (let* ((valid-event `((times . ((,timestamp-str . ,event-time)))
+ (title . "Valid Event")
+ (intervals . ((10 . medium)))))
+ ;; Invalid event
+ (invalid-event '((invalid . "data")))
+ (events (list valid-event invalid-event)))
+ ;; Should not crash
+ (should-not (condition-case nil
+ (progn (chime--process-notifications events) nil)
+ (error t)))
+ ;; Should process at least the valid event
+ (should (>= notify-count 1)))))))
;;; Day-wide bundling
-(ert-deftest test-chime-process-notifications-day-wide-multiple-events-single-notify ()
+(chime-deftest test-chime-process-notifications-day-wide-multiple-events-single-notify ()
"Multiple day-wide events should produce a single bundled notification,
not one notification per event."
- (test-chime-process-notifications-setup)
- (unwind-protect
- (let* ((now (test-time-today-at 8 0))
- (notify-count 0)
- (notify-messages '()))
- (with-test-time now
- (cl-letf (((symbol-function 'chime--notify)
- (lambda (msg)
- (setq notify-count (1+ notify-count))
- (push msg notify-messages)))
- ((symbol-function 'chime--current-time-is-day-wide-time)
- (lambda () t))
- ((symbol-function 'chime--day-wide-notifications)
- (lambda (events)
- (list (cons "Blake's birthday is today" 'medium)
- (cons "Holiday: Memorial Day is today" 'medium)
- (cons "Submit expense report is due or scheduled today" 'medium)))))
- (chime--process-notifications '())
- ;; Should fire exactly ONE notification for all day-wide events
- (should (= 1 notify-count))
- ;; The single notification body should contain all event messages
- (let ((body (caar notify-messages)))
- (should (string-match-p "Blake's birthday" body))
- (should (string-match-p "Memorial Day" body))
- (should (string-match-p "expense report" body))))))
- (test-chime-process-notifications-teardown)))
-
-(ert-deftest test-chime-process-notifications-day-wide-single-event-no-bundling ()
+ (let* ((now (test-time-today-at 8 0))
+ (notify-count 0)
+ (notify-messages '()))
+ (with-test-time now
+ (cl-letf (((symbol-function 'chime--notify)
+ (lambda (msg)
+ (setq notify-count (1+ notify-count))
+ (push msg notify-messages)))
+ ((symbol-function 'chime--current-time-is-day-wide-time)
+ (lambda () t))
+ ((symbol-function 'chime--day-wide-notifications)
+ (lambda (events)
+ (list (cons "Blake's birthday is today" 'medium)
+ (cons "Holiday: Memorial Day is today" 'medium)
+ (cons "Submit expense report is due or scheduled today" 'medium)))))
+ (chime--process-notifications '())
+ ;; Should fire exactly ONE notification for all day-wide events
+ (should (= 1 notify-count))
+ ;; The single notification body should contain all event messages
+ (let ((body (caar notify-messages)))
+ (should (string-match-p "Blake's birthday" body))
+ (should (string-match-p "Memorial Day" body))
+ (should (string-match-p "expense report" body)))))))
+
+(chime-deftest test-chime-process-notifications-day-wide-single-event-no-bundling ()
"A single day-wide event should produce a normal notification, not bundled."
- (test-chime-process-notifications-setup)
- (unwind-protect
- (let* ((now (test-time-today-at 8 0))
- (notify-count 0)
- (notify-messages '()))
- (with-test-time now
- (cl-letf (((symbol-function 'chime--notify)
- (lambda (msg)
- (setq notify-count (1+ notify-count))
- (push msg notify-messages)))
- ((symbol-function 'chime--current-time-is-day-wide-time)
- (lambda () t))
- ((symbol-function 'chime--day-wide-notifications)
- (lambda (events)
- (list (cons "Blake's birthday is today" 'medium)))))
- (chime--process-notifications '())
- ;; Single event: still one notification
- (should (= 1 notify-count))
- ;; Should be the plain message, not wrapped in a bundle
- (let ((body (caar notify-messages)))
- (should (string= "Blake's birthday is today" body))))))
- (test-chime-process-notifications-teardown)))
+ (let* ((now (test-time-today-at 8 0))
+ (notify-count 0)
+ (notify-messages '()))
+ (with-test-time now
+ (cl-letf (((symbol-function 'chime--notify)
+ (lambda (msg)
+ (setq notify-count (1+ notify-count))
+ (push msg notify-messages)))
+ ((symbol-function 'chime--current-time-is-day-wide-time)
+ (lambda () t))
+ ((symbol-function 'chime--day-wide-notifications)
+ (lambda (events)
+ (list (cons "Blake's birthday is today" 'medium)))))
+ (chime--process-notifications '())
+ ;; Single event: still one notification
+ (should (= 1 notify-count))
+ ;; Should be the plain message, not wrapped in a bundle
+ (let ((body (caar notify-messages)))
+ (should (string= "Blake's birthday is today" body)))))))
(provide 'test-chime-process-notifications)
;;; test-chime-process-notifications.el ends here