aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-06-06 16:49:03 -0500
committerCraig Jennings <c@cjennings.net>2026-06-06 16:49:03 -0500
commita0765206144f49a845c8628d53111dd3d04f0e49 (patch)
treeba69afdab6b155722e1c1c0a8cfb30e5484c1334 /tests
parent47940f707aceea6066f8c9860207724c5d30f9e0 (diff)
downloaddotemacs-a0765206144f49a845c8628d53111dd3d04f0e49.tar.gz
dotemacs-a0765206144f49a845c8628d53111dd3d04f0e49.zip
feat(calibredb): curated ? menu, docked description, filter-preserving sort
Three things in the calibredb search buffer. A curated transient on ? exposes just my frequent workflows (switch library, filter by format or author, sort by author/title/pubdate/format, open, describe) instead of leaving me to remember calibredb's top-level single keys. calibredb's own full dispatch moves to H. which-key can't help here: these are mode-map single keys, not a prefix. So a curated menu on ? is the discoverable entry point. The transient is defined in :config rather than top-level: its macro expands against the elpa transient, but a batch Emacs loads the older built-in transient and breaks the load. The book-detail view (d, or v) now docks to the bottom 30% and q dismisses it. calibredb-show-entry-switch goes to pop-to-buffer so a display-buffer-alist rule applies. The default switch-to-buffer-other-window ignores it. It's the same bottom-dock pattern as the signal chat buffer. Sorting kept dropping the active filter. calibredb's macro-generated sort commands all end in calibredb-search-refresh-and-clear-filter, which nulls every filter flag. I override each to refresh via calibredb-search-refresh-or-resume, which re-applies the filter, so a sort over a filtered list keeps it. I used named advice, so reloading the module doesn't stack it. Tests cover the describe command and the sort helper. The transient, bindings, dock, and advice wiring need the elpa transient and a live calibredb, so they're verified in the running daemon.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-calibredb-epub-config--menu.el52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/test-calibredb-epub-config--menu.el b/tests/test-calibredb-epub-config--menu.el
new file mode 100644
index 00000000..4860efc3
--- /dev/null
+++ b/tests/test-calibredb-epub-config--menu.el
@@ -0,0 +1,52 @@
+;;; test-calibredb-epub-config--menu.el --- calibredb curated-menu tests -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; Tests for the docked book-description command bound into the curated calibredb
+;; menu. The transient itself, its `?'/`H' keybindings, and the
+;; display-buffer-alist dock live in calibredb's deferred `use-package' config
+;; (they need the elpa transient, which batch does not load) and are verified
+;; live in the daemon; here we cover the describe command, which has no transient
+;; dependency.
+
+;;; Code:
+
+(require 'ert)
+(require 'cl-lib)
+(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
+(require 'calibredb-epub-config)
+
+;; calibredb vars (defvar'd here so the tests' `let' bindings are dynamic; the
+;; module's bare defvars are file-local to its own compilation unit).
+(defvar calibredb-sort-by)
+(defvar calibredb-search-filter)
+(defvar calibredb-format-filter-p)
+
+(ert-deftest test-calibredb-describe-at-point-shows-entry-without-switch ()
+ "Normal: describe calls `calibredb-show-entry' on the entry at point with no
+switch argument, so the entry lands in the docked window with focus (q quits)."
+ (let (call)
+ (cl-letf (((symbol-function 'calibredb-find-candidate-at-point)
+ (lambda () '(the-entry extra)))
+ ((symbol-function 'calibredb-show-entry)
+ (lambda (&rest args) (setq call args))))
+ (cj/calibredb-describe-at-point)
+ ;; one argument only -- the entry -- and switch is therefore nil
+ (should (equal call '(the-entry))))))
+
+(ert-deftest test-calibredb-sort-preserving-filter-keeps-filter ()
+ "Normal: the filter-preserving sort sets the field and refreshes via
+`calibredb-search-refresh-or-resume' without touching the active filter."
+ (let ((calibredb-sort-by 'id)
+ (calibredb-search-filter "epub")
+ (calibredb-format-filter-p t)
+ (refreshed nil))
+ (cl-letf (((symbol-function 'calibredb-search-refresh-or-resume)
+ (lambda (&rest _) (setq refreshed t))))
+ (cj/--calibredb-sort-preserving-filter 'author)
+ (should (eq calibredb-sort-by 'author)) ; field updated
+ (should refreshed) ; refreshed
+ (should (equal calibredb-search-filter "epub")) ; filter kept
+ (should calibredb-format-filter-p)))) ; filter flag kept
+
+(provide 'test-calibredb-epub-config--menu)
+;;; test-calibredb-epub-config--menu.el ends here