diff options
| -rw-r--r-- | pearl.el | 8 | ||||
| -rw-r--r-- | tests/test-pearl-sort.el | 66 |
2 files changed, 74 insertions, 0 deletions
@@ -6973,6 +6973,10 @@ buffer doesn't show." (let ((ranks (pearl--issue-id-ranks result source))) (pearl--merge-query-result result source) (pearl--reorder-issue-subtrees nil 'asc ranks)) + ;; The reorder rewrites the issue block with delete+insert, which + ;; drops the fold overlays and leaves every subtree expanded. + ;; Re-fold so the page stays the scannable outline it was. + (pearl--restore-page-visibility) (pearl--write-linear-source-header source) (message "Refetched %s ordered by %s %sending" (pearl--source-name source) sort @@ -7002,6 +7006,10 @@ Returns `client', `server', `grouped', or `no-issues'." (message "No issues to sort in this buffer") 'no-issues) (_ + ;; The reorder rewrites the issue block with delete+insert, which + ;; drops the fold overlays and leaves every subtree expanded. Re-fold + ;; so the page stays the scannable outline it was before the sort. + (pearl--restore-page-visibility) (pearl--write-linear-source-header updated) (message "Sorted current buffer by %s %sending" sort (if (eq order 'asc) "asc" "desc")) diff --git a/tests/test-pearl-sort.el b/tests/test-pearl-sort.el index 8833675..ffa15e8 100644 --- a/tests/test-pearl-sort.el +++ b/tests/test-pearl-sort.el @@ -312,5 +312,71 @@ would persist an unreadable #+LINEAR-SOURCE and break refresh/sort." 'updated 'asc) (should (null (plist-get (pearl--read-active-source) :sort)))))) +;;; fold restoration after a reorder + +;; The reorder rewrites the issue block with delete+insert, which drops the +;; fold/visibility overlays so every subtree comes back expanded. Both sort +;; paths must re-fold afterward (pearl--restore-page-visibility) so the page +;; stays the scannable, folded outline it was before the sort. A refusal +;; (grouped buffer, failed refetch) moves nothing and must not re-fold. + +(ert-deftest test-pearl-apply-sort-client-restores-fold () + "A successful client reorder re-folds the page." + (test-pearl-sort--in-org test-pearl-sort--flat + (let (restored) + (cl-letf (((symbol-function 'pearl--restore-page-visibility) + (lambda () (setq restored t)))) + (should (eq (pearl--apply-sort + '(:type filter :name "My open issues" :filter (:open t)) + 'priority 'asc) + 'client)) + (should restored))))) + +(ert-deftest test-pearl-apply-sort-grouped-skips-fold-restore () + "A grouped refusal moves nothing, so it does not re-fold." + (test-pearl-sort--in-org + (concat + "#+LINEAR-SOURCE: (:type filter :name \"x\" :filter nil)\n\n" + "* x\n" + "** Group\n" + "*** TODO [#A] SE-1: Alpha\n:PROPERTIES:\n:LINEAR-ID: i1\n:END:\n") + (let (restored) + (cl-letf (((symbol-function 'pearl--restore-page-visibility) + (lambda () (setq restored t)))) + (pearl--apply-sort '(:type filter :name "x" :filter nil) 'priority 'asc) + (should-not restored))))) + +(ert-deftest test-pearl-apply-server-sort-ok-restores-fold () + "A successful server refetch re-folds the reordered page." + (test-pearl-sort--in-org test-pearl-sort--flat + (let (restored) + (cl-letf (((symbol-function 'pearl--query-issues-async) + (lambda (_filter callback &optional _order-by) + (funcall callback '(:status ok :issues nil :truncated nil)))) + ((symbol-function 'pearl--merge-query-result) (lambda (&rest _) nil)) + ((symbol-function 'pearl--progress) (lambda (&rest _) nil)) + ((symbol-function 'pearl--restore-page-visibility) + (lambda () (setq restored t)))) + (pearl--apply-server-sort + '(:type filter :name "My open issues" :filter (:open t) :sort updated :order asc) + 'updated 'asc) + (should restored))))) + +(ert-deftest test-pearl-apply-server-sort-failure-skips-fold-restore () + "A failed server refetch moves nothing, so it does not re-fold." + (test-pearl-sort--in-org test-pearl-sort--flat + (let (restored) + (cl-letf (((symbol-function 'pearl--query-issues-async) + (lambda (_filter callback &optional _order-by) + (funcall callback '(:status error :message "boom")))) + ((symbol-function 'pearl--merge-query-result) (lambda (&rest _) nil)) + ((symbol-function 'pearl--progress) (lambda (&rest _) nil)) + ((symbol-function 'pearl--restore-page-visibility) + (lambda () (setq restored t)))) + (pearl--apply-server-sort + '(:type filter :name "My open issues" :filter (:open t) :sort updated :order asc) + 'updated 'asc) + (should-not restored))))) + (provide 'test-pearl-sort) ;;; test-pearl-sort.el ends here |
