aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-06-06 15:14:45 -0500
committerCraig Jennings <c@cjennings.net>2026-06-06 15:14:45 -0500
commit23c741c4dc8a3e5a753b3c42389b8c673052d2ce (patch)
tree3fed12b20d86005595f83b85ff259578e4975775 /tests
parent690faf7538bb7fcd47367b4801923beea40a0ff1 (diff)
downloadpearl-23c741c4dc8a3e5a753b3c42389b8c673052d2ce.tar.gz
pearl-23c741c4dc8a3e5a753b3c42389b8c673052d2ce.zip
feat(views): pearl-set-grouping command
Phase 3 of the interactive-grouping spec: the command that ties phases 1 and 2 together. pearl-set-grouping completing-reads a dimension (status/project/assignee/priority/none), coerces and validates it, regroups the buffer, then persists the choice on the source. M-x only for now, like pearl-set-sort. The transient and keymap entries come later. pearl--apply-grouping is the non-interactive core, shaped like pearl--apply-sort. On a successful regroup it re-folds the page and writes :client-group into the header. On an empty buffer it reports no-issues and writes nothing, so a failed grouping never advertises a layout the buffer doesn't show. none ungroups and clears the override. 4 tests cover persistence, the none-clears path, the re-fold, and the no-issues skip.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-pearl-grouping.el41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/test-pearl-grouping.el b/tests/test-pearl-grouping.el
index af9c969..13a84d5 100644
--- a/tests/test-pearl-grouping.el
+++ b/tests/test-pearl-grouping.el
@@ -286,5 +286,46 @@ SE-1 has a comment subtree; SE-2 has no assignee.")
"#+LINEAR-SOURCE: (:type filter :name \"F\" :filter nil)\n\n* F\n"
(should (eq (pearl--regroup-issue-subtrees "workflowState") 'no-issues))))
+;;; command core (phase 3)
+
+(ert-deftest test-pearl-apply-grouping-groups-and-persists ()
+ "Applying a grouping regroups the buffer and writes :client-group to the header."
+ (test-pearl-grouping--in-org test-pearl-grouping--flat
+ (cl-letf (((symbol-function 'pearl--restore-page-visibility) (lambda () nil)))
+ (should (eq (pearl--apply-grouping
+ '(:type filter :name "F" :filter (:open t)) "workflowState")
+ 'grouped)))
+ (should (equal (plist-get (pearl--read-active-source) :client-group) "workflowState"))
+ (should (= (test-pearl-grouping--issue-level "i1") 3))))
+
+(ert-deftest test-pearl-apply-grouping-none-clears-and-flattens ()
+ "Applying none flattens the buffer and leaves no :client-group in the header."
+ (test-pearl-grouping--in-org test-pearl-grouping--flat
+ (cl-letf (((symbol-function 'pearl--restore-page-visibility) (lambda () nil)))
+ (pearl--apply-grouping
+ '(:type view :name "v" :id "vid" :client-group "workflowState") "workflowState")
+ (should (eq (pearl--apply-grouping (pearl--read-active-source) nil) 'grouped)))
+ (should-not (plist-member (pearl--read-active-source) :client-group))
+ (should (= (test-pearl-grouping--issue-level "i1") 2))))
+
+(ert-deftest test-pearl-apply-grouping-refolds-on-success ()
+ "A successful regroup re-folds the page."
+ (test-pearl-grouping--in-org test-pearl-grouping--flat
+ (let (folded)
+ (cl-letf (((symbol-function 'pearl--restore-page-visibility)
+ (lambda () (setq folded t))))
+ (pearl--apply-grouping '(:type filter :name "F" :filter (:open t)) "workflowState"))
+ (should folded))))
+
+(ert-deftest test-pearl-apply-grouping-no-issues-skips-fold-and-header ()
+ "An issue-free buffer reports no-issues without folding or writing the header."
+ (test-pearl-grouping--in-org
+ "#+LINEAR-SOURCE: (:type filter :name \"F\" :filter nil)\n\n* F\n"
+ (cl-letf (((symbol-function 'pearl--restore-page-visibility)
+ (lambda () (error "should not re-fold a no-issues buffer"))))
+ (should (eq (pearl--apply-grouping '(:type filter :name "F" :filter nil) "workflowState")
+ 'no-issues)))
+ (should-not (plist-get (pearl--read-active-source) :client-group))))
+
(provide 'test-pearl-grouping)
;;; test-pearl-grouping.el ends here