aboutsummaryrefslogtreecommitdiff
path: root/tests/test-chime-jump-to-event.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-11 04:50:45 -0500
committerCraig Jennings <c@cjennings.net>2026-05-11 04:50:45 -0500
commit21ec114def7df9aa61e43e8f2cee484ded772e72 (patch)
treebcce37275249879f5fb32d879e19126efdacf2d4 /tests/test-chime-jump-to-event.el
parenta11f554fd533f2139cf6b9e592388a5385d4462b (diff)
downloadchime-21ec114def7df9aa61e43e8f2cee484ded772e72.tar.gz
chime-21ec114def7df9aa61e43e8f2cee484ded772e72.zip
test: close coverage gaps to 99.88% line coverage
Five new test files cover branches the per-function suites missed: the day-wide notification pipeline, the jump-to-event navigation path (including the org-show-entry fallback for Org < 9.6), chime--stop's process-interrupt branch, chime--start's debug log, and the two async error branches in chime--fetch-and-process. The edge-coverage file mops up scattered one-line fallbacks: the day-wide-notification "today" path, the tooltip placeholder pass-through, timestamp-parse's no-context error message, log-silently's mid-line newline insert, the validation :error count, and record-async-failure's chime-debug hook. Line coverage on chime.el goes from 97.1% to 99.88%, 823 of 824 coverable lines. The one remaining line is a pcase _ fallback the preceding regex can't reach.
Diffstat (limited to 'tests/test-chime-jump-to-event.el')
-rw-r--r--tests/test-chime-jump-to-event.el125
1 files changed, 125 insertions, 0 deletions
diff --git a/tests/test-chime-jump-to-event.el b/tests/test-chime-jump-to-event.el
new file mode 100644
index 0000000..6db885b
--- /dev/null
+++ b/tests/test-chime-jump-to-event.el
@@ -0,0 +1,125 @@
+;;; test-chime-jump-to-event.el --- Tests for chime--jump-to-event navigation -*- 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:
+
+;; Unit tests for `chime--jump-to-event'. The function reconstructs an
+;; org buffer position from the serialized marker-file + marker-pos pair
+;; that survives the async boundary, opens the file, moves point, and
+;; reveals the entry.
+
+;;; Code:
+
+(require 'test-bootstrap (expand-file-name "test-bootstrap.el"))
+(require 'testutil-general (expand-file-name "testutil-general.el"))
+
+(defun test-chime-jump-to-event--make-temp-org-file (content)
+ "Write CONTENT to a temp .org file under the test base dir and return its path."
+ (let* ((base (chime-create-test-base-dir))
+ (path (expand-file-name
+ (concat (make-temp-name "jump-to-event-") ".org")
+ base)))
+ (with-temp-file path
+ (insert content))
+ path))
+
+(ert-deftest test-chime-jump-to-event-normal-opens-file-and-moves-point ()
+ "Normal: opens the event's file and moves point to the recorded position."
+ (unwind-protect
+ (let* ((content "* First heading
+some body
+
+* Target heading
+target body
+")
+ (file (test-chime-jump-to-event--make-temp-org-file content))
+ (target-pos (with-temp-buffer
+ (insert-file-contents file)
+ (goto-char (point-min))
+ (search-forward "* Target heading")
+ (line-beginning-position)))
+ (event (chime--make-event
+ '(("<2026-05-10 Sun 09:30>" . (26760 32460)))
+ "Target heading"
+ '((0 . medium))
+ file
+ target-pos))
+ (buffer-before-jump nil))
+ (unwind-protect
+ (progn
+ (setq buffer-before-jump (current-buffer))
+ (chime--jump-to-event event)
+ (should (string= file (buffer-file-name)))
+ (should (= target-pos (point))))
+ (when (and (get-file-buffer file))
+ (kill-buffer (get-file-buffer file)))
+ (when (buffer-live-p buffer-before-jump)
+ (switch-to-buffer buffer-before-jump))))
+ (chime-delete-test-base-dir)))
+
+(ert-deftest test-chime-jump-to-event-boundary-nil-marker-file-no-op ()
+ "Boundary: an event with nil marker-file does nothing (no error, no jump)."
+ (let* ((event (chime--make-event
+ '(("<2026-05-10 Sun 09:30>" . (26760 32460)))
+ "No File"
+ '((0 . medium))
+ nil
+ 123))
+ (buffer-before (current-buffer)))
+ (chime--jump-to-event event)
+ (should (eq buffer-before (current-buffer)))))
+
+(ert-deftest test-chime-jump-to-event-boundary-missing-file-no-op ()
+ "Boundary: when the recorded file no longer exists, the jump is a no-op."
+ (let* ((event (chime--make-event
+ '(("<2026-05-10 Sun 09:30>" . (26760 32460)))
+ "Missing File"
+ '((0 . medium))
+ "/tmp/chime-this-path-does-not-exist-xyz.org"
+ 42))
+ (buffer-before (current-buffer)))
+ (chime--jump-to-event event)
+ (should (eq buffer-before (current-buffer)))))
+
+(ert-deftest test-chime-jump-to-event-boundary-uses-org-show-entry-fallback ()
+ "Boundary: when `org-fold-show-entry' is unbound, falls back to `org-show-entry'."
+ (unwind-protect
+ (let* ((content "* Heading
+body
+")
+ (file (test-chime-jump-to-event--make-temp-org-file content))
+ (event (chime--make-event
+ '(("<2026-05-10 Sun 09:30>" . (26760 32460)))
+ "Heading"
+ '((0 . medium))
+ file
+ 1))
+ (fallback-called nil)
+ (orig-fboundp (symbol-function 'fboundp))
+ (buffer-before-jump (current-buffer)))
+ (unwind-protect
+ (cl-letf (((symbol-function 'fboundp)
+ (lambda (sym)
+ (and (not (eq sym 'org-fold-show-entry))
+ (funcall orig-fboundp sym))))
+ ((symbol-function 'org-show-entry)
+ (lambda () (setq fallback-called t))))
+ (chime--jump-to-event event)
+ (should fallback-called)
+ (should (string= file (buffer-file-name))))
+ (when (get-file-buffer file)
+ (kill-buffer (get-file-buffer file)))
+ (when (buffer-live-p buffer-before-jump)
+ (switch-to-buffer buffer-before-jump))))
+ (chime-delete-test-base-dir)))
+
+(provide 'test-chime-jump-to-event)
+;;; test-chime-jump-to-event.el ends here