diff options
Diffstat (limited to 'tests/test-pearl-adhoc.el')
| -rw-r--r-- | tests/test-pearl-adhoc.el | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/tests/test-pearl-adhoc.el b/tests/test-pearl-adhoc.el new file mode 100644 index 0000000..97ac22e --- /dev/null +++ b/tests/test-pearl-adhoc.el @@ -0,0 +1,106 @@ +;;; test-pearl-adhoc.el --- Tests for the ad-hoc filtered command -*- lexical-binding: t; -*- + +;; Copyright (C) 2026 Craig Jennings + +;; Author: Craig Jennings <c@cjennings.net> + +;; This program is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see <http://www.gnu.org/licenses/>. + +;;; Commentary: + +;; Tests for the ad-hoc filter command: the pure `--assemble-filter' that +;; turns chosen dimension values into a filter plist, `--save-query', and +;; `pearl-list-issues-filtered' running and optionally saving. + +;;; Code: + +(require 'test-bootstrap (expand-file-name "test-bootstrap.el")) +(require 'cl-lib) + +;;; --assemble-filter + +(ert-deftest test-pearl-assemble-filter-only-set-keys () + "Only the dimensions that were chosen appear in the filter plist." + (let ((f (pearl--assemble-filter nil t nil nil nil nil))) + (should (eq t (plist-get f :open))) + (should-not (plist-member f :team)) + (should-not (plist-member f :labels)))) + +(ert-deftest test-pearl-assemble-filter-full () + "All chosen dimensions land in the plist." + (let ((f (pearl--assemble-filter "ENG" t "In Progress" "Foo" '("bug" "p1") :me))) + (should (string= "ENG" (plist-get f :team))) + (should (eq t (plist-get f :open))) + (should (string= "In Progress" (plist-get f :state))) + (should (string= "Foo" (plist-get f :project))) + (should (equal '("bug" "p1") (plist-get f :labels))) + (should (eq :me (plist-get f :assignee))))) + +(ert-deftest test-pearl-assemble-filter-empty-labels-omitted () + "An empty label list does not add a :labels key." + (let ((f (pearl--assemble-filter nil nil nil nil '() nil))) + (should-not (plist-member f :labels)))) + +;;; --save-query + +(ert-deftest test-pearl-save-query-adds-entry () + "Saving a query adds it to the saved-queries variable." + (let ((pearl-saved-queries nil)) + (cl-letf (((symbol-function 'customize-save-variable) (lambda (&rest _) nil))) + (pearl--save-query "My filter" '(:open t :labels ("bug"))) + (let ((entry (assoc "My filter" pearl-saved-queries))) + (should entry) + (should (equal '(:open t :labels ("bug")) (plist-get (cdr entry) :filter))))))) + +(ert-deftest test-pearl-save-query-replaces-same-name () + "Saving under an existing name replaces that entry rather than duplicating." + (let ((pearl-saved-queries '(("Dup" :filter (:open t))))) + (cl-letf (((symbol-function 'customize-save-variable) (lambda (&rest _) nil))) + (pearl--save-query "Dup" '(:priority 1)) + (should (= 1 (cl-count "Dup" pearl-saved-queries + :key #'car :test #'string=))) + (should (equal '(:priority 1) + (plist-get (cdr (assoc "Dup" pearl-saved-queries)) :filter)))))) + +;;; pearl-list-issues-filtered + +(ert-deftest test-pearl-list-issues-filtered-runs-with-source () + "Running an ad-hoc filter compiles it and renders with a filter source." + (let ((built nil) (rendered-source nil)) + (cl-letf (((symbol-function 'pearl--build-issue-filter) + (lambda (plist) (setq built plist) '((compiled . t)))) + ((symbol-function 'pearl--query-issues-async) + (lambda (_filter cb &optional _ord) + (funcall cb (pearl--make-query-result 'ok :issues nil)))) + ((symbol-function 'pearl--render-query-result) + (lambda (_result source) (setq rendered-source source)))) + (pearl-list-issues-filtered '(:assignee :me :open t) nil) + (should (equal '(:assignee :me :open t) built)) + (should (eq 'filter (plist-get rendered-source :type))) + (should (equal '(:assignee :me :open t) (plist-get rendered-source :filter)))))) + +(ert-deftest test-pearl-list-issues-filtered-saves-when-named () + "Passing a save name persists the ad-hoc filter as a saved query." + (let ((pearl-saved-queries nil)) + (cl-letf (((symbol-function 'pearl--build-issue-filter) (lambda (_p) nil)) + ((symbol-function 'pearl--query-issues-async) + (lambda (_f cb &optional _o) + (funcall cb (pearl--make-query-result 'empty :issues nil)))) + ((symbol-function 'pearl--render-query-result) (lambda (&rest _) nil)) + ((symbol-function 'customize-save-variable) (lambda (&rest _) nil))) + (pearl-list-issues-filtered '(:open t) "Saved adhoc") + (should (assoc "Saved adhoc" pearl-saved-queries))))) + +(provide 'test-pearl-adhoc) +;;; test-pearl-adhoc.el ends here |
