diff options
| author | Craig Jennings <c@cjennings.net> | 2026-06-28 14:47:49 -0400 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-06-28 14:47:49 -0400 |
| commit | 7cdd9a7490e6a3d0725adcf6fea8c678fafc4416 (patch) | |
| tree | 09aa7ce1def09b71548fa991a9ea5c381607c39f /tests | |
| parent | e2577fbad47540eaf031b925d2c08558bbc089bf (diff) | |
| download | dotemacs-7cdd9a7490e6a3d0725adcf6fea8c678fafc4416.tar.gz dotemacs-7cdd9a7490e6a3d0725adcf6fea8c678fafc4416.zip | |
feat(calibre): open calibredb filtered to the in-progress books
Every calibredb launch (the dashboard "b", M-x, anywhere) now opens filtered to the in-progress books rather than the whole library, via an :after advice on calibredb. Clear with L or x to see everything.
The filter scopes to the tag field (calibredb-tag-filter-p), not a bare keyword search. A bare keyword matches any field, which surfaced books that only mention "in-progress" in their description.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test-calibredb-epub-config--open-to-favorites.el | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/test-calibredb-epub-config--open-to-favorites.el b/tests/test-calibredb-epub-config--open-to-favorites.el new file mode 100644 index 000000000..d11618081 --- /dev/null +++ b/tests/test-calibredb-epub-config--open-to-favorites.el @@ -0,0 +1,57 @@ +;;; test-calibredb-epub-config--open-to-favorites.el --- in-progress open filter -*- lexical-binding: t; -*- + +;;; Commentary: +;; `cj/--calibredb-open-to-favorites' advises `calibredb' :after so every launch +;; lands filtered to `calibredb-favorite-keyword' (Craig's "in-progress" books). +;; It scopes the filter to the TAG field (sets `calibredb-tag-filter-p', clears +;; the other filter-p flags) before delegating to `calibredb-search-keyword-filter', +;; so the keyword can't over-match in a book's title or description. It no-ops +;; when no usable keyword is set. + +;;; Code: + +(require 'ert) +(require 'cl-lib) +(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) +(require 'calibredb-epub-config) + +;; calibredb defcustom + internal flags; declared special so `let' binds them +;; dynamically (all unbound under `make test', which never runs the use-package +;; :config or loads calibredb). +(defvar calibredb-favorite-keyword) +(defvar calibredb-tag-filter-p) +(defvar calibredb-favorite-filter-p) +(defvar calibredb-author-filter-p) +(defvar calibredb-date-filter-p) +(defvar calibredb-format-filter-p) + +(ert-deftest test-calibredb-open-to-favorites-applies-keyword-scoped-to-tags () + "Normal: with a favorite keyword set, the filter runs with that keyword and is +scoped to the tag field (so it can't over-match a description); a stale +non-tag filter flag is cleared." + (let ((applied :unset) + (calibredb-favorite-keyword "in-progress") + (calibredb-tag-filter-p nil) + (calibredb-favorite-filter-p t) ; stale, must be cleared + (calibredb-author-filter-p nil) + (calibredb-date-filter-p nil) + (calibredb-format-filter-p nil)) + (cl-letf (((symbol-function 'calibredb-search-keyword-filter) + (lambda (kw) (setq applied kw)))) + (cj/--calibredb-open-to-favorites)) + (should (equal applied "in-progress")) ; keyword applied + (should (eq calibredb-tag-filter-p t)) ; scoped to the tag field + (should-not calibredb-favorite-filter-p))) ; stale flag cleared + +(ert-deftest test-calibredb-open-to-favorites-noop-without-usable-keyword () + "Boundary/Error: nil, empty, or non-string keyword applies no filter." + (dolist (kw (list nil "" 42)) + (let ((applied :unset) + (calibredb-favorite-keyword kw)) + (cl-letf (((symbol-function 'calibredb-search-keyword-filter) + (lambda (k) (setq applied k)))) + (cj/--calibredb-open-to-favorites)) + (should (eq applied :unset))))) + +(provide 'test-calibredb-epub-config--open-to-favorites) +;;; test-calibredb-epub-config--open-to-favorites.el ends here |
