aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-24 15:24:12 -0500
committerCraig Jennings <c@cjennings.net>2026-05-24 15:24:12 -0500
commit11109b45094eaecc1dc87a2e99afab4040732c8f (patch)
treeda484f44f7cff8b4ac76fd56273c2130216cac45 /tests
parent95bd7f4661ec5f43ba2eb7e8545b3cf9287e55c8 (diff)
downloadpearl-11109b45094eaecc1dc87a2e99afab4040732c8f.tar.gz
pearl-11109b45094eaecc1dc87a2e99afab4040732c8f.zip
test: cover comment insertion and extraction boundary cases
Added ERT tests: append targets the current issue's Comments subtree even when a later issue already has its own Comments; add-comment from inside a comment subtree refuses (no issue id at that heading); edit-current-comment refuses a comment missing LINEAR-COMMENT-ID with no network call; and a comment body containing drawer-looking (:note:) text reads back intact. 380 tests green.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-pearl-comment-editing.el28
-rw-r--r--tests/test-pearl-comments.el21
2 files changed, 49 insertions, 0 deletions
diff --git a/tests/test-pearl-comment-editing.el b/tests/test-pearl-comment-editing.el
index 866366f..be65aa3 100644
--- a/tests/test-pearl-comment-editing.el
+++ b/tests/test-pearl-comment-editing.el
@@ -256,5 +256,33 @@
(should (eq 'pearl-editable-comment (face-on "^\\*\\*\\*\\*\\* Me")))
(should (eq 'pearl-readonly-comment (face-on "^\\*\\*\\*\\*\\* Them"))))))
+(ert-deftest test-pearl-add-comment-from-inside-comment-refuses ()
+ "Running add-comment from inside a comment subtree refuses — no issue id there."
+ (test-pearl--in-org (test-pearl--comment-doc "u-me" "stored" "uniquecommentline")
+ (goto-char (point-min))
+ (re-search-forward "uniquecommentline") ; point inside the comment subtree
+ (should-error (pearl-add-comment "hi") :type 'user-error)))
+
+(ert-deftest test-pearl-edit-comment-missing-id-refuses-no-network ()
+ "A comment subtree without LINEAR-COMMENT-ID is refused with no network call."
+ (test-pearl--in-org
+ (concat "** TODO Issue\n:PROPERTIES:\n:LINEAR-ID: a\n:END:\nBody.\n"
+ "*** Comments\n**** Me — ts\n:PROPERTIES:\n:LINEAR-COMMENT-AUTHOR-ID: u-me\n:END:\nedited\n")
+ (let ((net nil))
+ (cl-letf (((symbol-function 'pearl--fetch-comment-body-async) (lambda (&rest _) (setq net t)))
+ ((symbol-function 'pearl--update-comment-async) (lambda (&rest _) (setq net t))))
+ (re-search-forward "edited")
+ (should-error (pearl-edit-current-comment) :type 'user-error)
+ (should-not net)))))
+
+(ert-deftest test-pearl-comment-body-reads-drawer-looking-text ()
+ "A comment body containing a colon-wrapped, drawer-looking line reads back intact."
+ (test-pearl--in-org
+ (concat "** TODO Issue\n:PROPERTIES:\n:LINEAR-ID: a\n:END:\nBody.\n"
+ "*** Comments\n**** Me — ts\n:PROPERTIES:\n:LINEAR-COMMENT-ID: c1\n:END:\n"
+ "see :note: below\nand more text\n")
+ (re-search-forward "see :note:")
+ (should (string= "see :note: below\nand more text" (pearl--issue-body-at-point)))))
+
(provide 'test-pearl-comment-editing)
;;; test-pearl-comment-editing.el ends here
diff --git a/tests/test-pearl-comments.el b/tests/test-pearl-comments.el
index 7fa4482..d335132 100644
--- a/tests/test-pearl-comments.el
+++ b/tests/test-pearl-comments.el
@@ -166,5 +166,26 @@
(test-pearl--in-org "* Plain heading\nno id\n"
(should-error (pearl-add-comment "x") :type 'user-error)))
+(ert-deftest test-pearl-append-comment-targets-current-issue-not-sibling ()
+ "Appending adds under the current issue's Comments, not a later issue's subtree."
+ (test-pearl--in-org
+ (concat "** TODO Issue A\n:PROPERTIES:\n:LINEAR-ID: a\n:END:\nBody A.\n"
+ "*** Comments\n**** X — t\n:PROPERTIES:\n:LINEAR-COMMENT-ID: cx\n:END:\nfirst A\n"
+ "** TODO Issue B\n:PROPERTIES:\n:LINEAR-ID: b\n:END:\nBody B.\n"
+ "*** Comments\n**** Y — t\n:PROPERTIES:\n:LINEAR-COMMENT-ID: cy\n:END:\nfirst B\n")
+ (goto-char (point-min))
+ (re-search-forward "Body A\\.")
+ (pearl--append-comment-to-issue
+ '(:id "cnew" :author "Z" :created-at "2026-05-24T12:00:00.000Z" :body "new on A"))
+ ;; the new comment landed under issue A, before issue B
+ (goto-char (point-min))
+ (let ((new-pos (progn (re-search-forward "new on A") (point)))
+ (b-pos (progn (goto-char (point-min)) (re-search-forward "Issue B") (point))))
+ (should (< new-pos b-pos)))
+ ;; issue B still has exactly one Comments heading (not a second one)
+ (goto-char (point-min))
+ (re-search-forward "Issue B")
+ (should (re-search-forward "^\\*\\*\\* Comments$" nil t))))
+
(provide 'test-pearl-comments)
;;; test-pearl-comments.el ends here