diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-11 17:17:54 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-11 17:17:54 -0500 |
| commit | b3b537fb74de7950ccd58d0f09cd7f5fbf39f546 (patch) | |
| tree | 4389257d81b8c536cc3cf10313e90c38d834ad5e /tests/test-calibredb-epub-config.el | |
| parent | 1f4c69218cc56a1cd8f670bd9cff34eb5f19d406 (diff) | |
| download | dotemacs-b3b537fb74de7950ccd58d0f09cd7f5fbf39f546.tar.gz dotemacs-b3b537fb74de7950ccd58d0f09cd7f5fbf39f546.zip | |
refactor(epub): clean up calibredb-epub-config.el
Dropped the 1-second `:defer' from the calibredb use-package and the redundant explicit `nov-render-document' call in `cj/nov-apply-preferences'. Nov / visual-fill-column text width now recalculates on `window-configuration-change-hook'. `cj/nov--text-width-for-window' computes the (clamped, minimum-readable) width and `cj/nov-update-layout' installs it buffer-locally. Lowered `calibredb-search-page-max-rows' from 20000 to 500 (pagination was effectively disabled). Replaced the anonymous zathura keybinding with `cj/nov-open-external'. Tests cover the width computation and the external-open binding.
Diffstat (limited to 'tests/test-calibredb-epub-config.el')
| -rw-r--r-- | tests/test-calibredb-epub-config.el | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/test-calibredb-epub-config.el b/tests/test-calibredb-epub-config.el new file mode 100644 index 00000000..5b578b7d --- /dev/null +++ b/tests/test-calibredb-epub-config.el @@ -0,0 +1,52 @@ +;;; test-calibredb-epub-config.el --- Tests for ebook config helpers -*- lexical-binding: t; -*- + +;;; Commentary: +;; Focuses on project-owned helpers in calibredb-epub-config rather than +;; CalibreDB/Nov internals. + +;;; Code: + +(require 'ert) +(require 'cl-lib) + +(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) +(require 'calibredb-epub-config) + +(ert-deftest test-calibredb-epub-nov-text-width-default-window () + "Normal: text width uses the configured margins against the current window." + (let ((cj/nov-margin-percent 25) + (cj/nov-min-text-width 40)) + (cl-letf (((symbol-function 'get-buffer-window) + (lambda (&rest _) 'window)) + ((symbol-function 'window-body-width) + (lambda (_) 120))) + (should (= 60 (cj/nov--text-width-for-window)))))) + +(ert-deftest test-calibredb-epub-nov-text-width-clamps-large-margin () + "Boundary: excessive margins are clamped to keep a readable text column." + (let ((cj/nov-margin-percent 80) + (cj/nov-min-text-width 40)) + (cl-letf (((symbol-function 'get-buffer-window) + (lambda (&rest _) 'window)) + ((symbol-function 'window-body-width) + (lambda (_) 120))) + (should (= 40 (cj/nov--text-width-for-window)))))) + +(ert-deftest test-calibredb-epub-nov-text-width-fallback-without-window () + "Boundary: a buffer without a visible window still gets a usable width." + (let ((cj/nov-margin-percent 25) + (cj/nov-min-text-width 40)) + (cl-letf (((symbol-function 'get-buffer-window) + (lambda (&rest _) nil))) + (should (= 40 (cj/nov--text-width-for-window)))))) + +(ert-deftest test-calibredb-epub-open-external-uses-zathura () + "Normal: named Nov external-open command delegates to zathura." + (let (command) + (cl-letf (((symbol-function 'cj/open-file-with-command) + (lambda (cmd) (setq command cmd)))) + (cj/nov-open-external) + (should (equal command "zathura"))))) + +(provide 'test-calibredb-epub-config) +;;; test-calibredb-epub-config.el ends here |
