diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-24 17:21:29 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-24 17:21:29 -0500 |
| commit | cc599d3e9d37c200d49f723ff8e8ce694acd33f8 (patch) | |
| tree | 6ee899bcd4a0a45c946329859d671ff6825efce7 /tests/test-pearl-comments.el | |
| parent | bb30b0f9146722b279832a991540917c3fa3cb81 (diff) | |
| download | pearl-cc599d3e9d37c200d49f723ff8e8ce694acd33f8.tar.gz pearl-cc599d3e9d37c200d49f723ff8e8ce694acd33f8.zip | |
feat: make comment sort order configurable, newest-first by default
I added pearl-comment-sort-order to choose how an issue's comments render under the Comments heading: newest-first (the default, most recent on top) or oldest-first (chronological, like an email thread). Both the render sort and the add-comment insertion point honor it, so a new comment lands at the top for newest-first and at the bottom for oldest-first.
Diffstat (limited to 'tests/test-pearl-comments.el')
| -rw-r--r-- | tests/test-pearl-comments.el | 65 |
1 files changed, 44 insertions, 21 deletions
diff --git a/tests/test-pearl-comments.el b/tests/test-pearl-comments.el index d335132..85d1c84 100644 --- a/tests/test-pearl-comments.el +++ b/tests/test-pearl-comments.el @@ -20,9 +20,9 @@ ;;; Commentary: ;; Tests for the comment thread: rendering a normalized comment and the -;; oldest-first Comments subtree, including comments in the issue render, the -;; commentCreate helper (stubbed at the HTTP boundary), the in-place append -;; under the Comments subtree (creating it when absent), and the +;; Comments subtree (ordered per `pearl-comment-sort-order'), including comments +;; in the issue render, the commentCreate helper (stubbed at the HTTP boundary), +;; the in-place append under the Comments subtree (creating it when absent), and the ;; `pearl-add-comment' command. ;;; Code: @@ -64,12 +64,22 @@ "No comments renders nothing (no empty Comments subtree)." (should (string= "" (pearl--format-comments nil)))) -(ert-deftest test-pearl-format-comments-oldest-first () - "Comments render under a Comments heading, oldest first regardless of input order." - (let ((out (pearl--format-comments - '((:id "c2" :author "B" :created-at "2026-05-23T12:00:00.000Z" :body "second") - (:id "c1" :author "A" :created-at "2026-05-23T09:00:00.000Z" :body "first"))))) +(defconst test-pearl--two-comments + '((:id "c1" :author "A" :created-at "2026-05-23T09:00:00.000Z" :body "first") + (:id "c2" :author "B" :created-at "2026-05-23T12:00:00.000Z" :body "second")) + "Two comments, c1 older than c2, in input order regardless of render order.") + +(ert-deftest test-pearl-format-comments-newest-first () + "With newest-first order, the most recent comment renders on top." + (let* ((pearl-comment-sort-order 'newest-first) + (out (pearl--format-comments test-pearl--two-comments))) (should (string-match-p "^\\*\\*\\* Comments$" out)) + (should (< (string-match "second" out) (string-match "first" out))))) + +(ert-deftest test-pearl-format-comments-oldest-first () + "With oldest-first order, comments render chronologically, oldest on top." + (let* ((pearl-comment-sort-order 'oldest-first) + (out (pearl--format-comments test-pearl--two-comments))) (should (< (string-match "first" out) (string-match "second" out))))) ;;; comments in the issue render @@ -121,19 +131,32 @@ (should (re-search-forward "^\\*\\*\\* Comments$" nil t)) (should (re-search-forward "first comment" nil t)))) -(ert-deftest test-pearl-append-comment-after-existing () - "A new comment appends after an existing one under the Comments subtree." - (test-pearl--in-org - "** TODO [#B] Title\n:PROPERTIES:\n:LINEAR-ID: a\n:END:\nBody.\n*** Comments\n**** A — 2026-05-23T09:00:00.000Z\nfirst\n" - (pearl--append-comment-to-issue - '(:id "c2" :author "B" :created-at "2026-05-23T12:00:00.000Z" :body "second")) - (goto-char (point-min)) - ;; only one Comments heading, and the new comment follows the first - (should (re-search-forward "^\\*\\*\\* Comments$" nil t)) - (should-not (re-search-forward "^\\*\\*\\* Comments$" nil t)) - (goto-char (point-min)) - (should (< (progn (re-search-forward "first") (point)) - (progn (re-search-forward "second") (point)))))) +(ert-deftest test-pearl-append-comment-newest-first-inserts-at-top () + "With newest-first order, a new comment lands above the existing ones." + (let ((pearl-comment-sort-order 'newest-first)) + (test-pearl--in-org + "** TODO [#B] Title\n:PROPERTIES:\n:LINEAR-ID: a\n:END:\nBody.\n*** Comments\n**** A — 2026-05-23T09:00:00.000Z\nfirst\n" + (pearl--append-comment-to-issue + '(:id "c2" :author "B" :created-at "2026-05-23T12:00:00.000Z" :body "second")) + (goto-char (point-min)) + ;; still exactly one Comments heading + (should (re-search-forward "^\\*\\*\\* Comments$" nil t)) + (should-not (re-search-forward "^\\*\\*\\* Comments$" nil t)) + (goto-char (point-min)) + ;; the new comment is above the existing one + (should (< (progn (re-search-forward "second") (point)) + (progn (re-search-forward "first") (point))))))) + +(ert-deftest test-pearl-append-comment-oldest-first-appends-at-bottom () + "With oldest-first order, a new comment appends after the existing ones." + (let ((pearl-comment-sort-order 'oldest-first)) + (test-pearl--in-org + "** TODO [#B] Title\n:PROPERTIES:\n:LINEAR-ID: a\n:END:\nBody.\n*** Comments\n**** A — 2026-05-23T09:00:00.000Z\nfirst\n" + (pearl--append-comment-to-issue + '(:id "c2" :author "B" :created-at "2026-05-23T12:00:00.000Z" :body "second")) + (goto-char (point-min)) + (should (< (progn (re-search-forward "first") (point)) + (progn (re-search-forward "second") (point))))))) ;;; pearl-add-comment |
