From b3b537fb74de7950ccd58d0f09cd7f5fbf39f546 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Mon, 11 May 2026 17:17:54 -0500 Subject: 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. --- tests/test-calibredb-epub-config.el | 52 +++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 tests/test-calibredb-epub-config.el (limited to 'tests') 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 -- cgit v1.2.3