aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
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