From eaf3848e7893326f2ddaaab23633106e0afe8fd8 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Thu, 30 Apr 2026 08:33:31 -0500 Subject: test(org-noter-config): cover preferred-split, slug, template, predicates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Four new test files for the pure-and-near-pure helpers in org-noter-config.el. The interactive heavyweights (cj/org-noter-start, cj/org-noter-insert-note-dwim, cj/org-noter--toggle-notes-window, cj/org-noter--find-notes-file, cj/org-noter--create-notes-file) are out of scope for this pass — they need org-noter loaded and a real session, or a substantial internal/wrapper split before they can be tested without spinning up real PDFs and EPUBs. - preferred-split: 5 tests walking the 1.4 width-to-height threshold from both sides plus a square-frame boundary. - title-to-slug: 7 tests covering multi-word, single-word, mixed punctuation, leading/trailing junk, collapsed runs, digits, and empty input. - generate-notes-template: 5 tests with org-id-uuid mocked, asserting the rendered template carries the UUID, the dual ROAM_REFS / NOTER_DOCUMENT pointers, the title-and-category lines, the ReadingNotes filetag, and the trailing Notes heading. - predicates: 13 tests covering cj/org-noter--in-document-p, cj/org-noter--in-notes-file-p, cj/org-noter--session-active-p, cj/org-noter--get-document-path, and cj/org-noter--extract-document-title. Mocks derived-mode-p, org-entry-get, and buffer-file-name at the boundary so the suite doesn't require pdf-tools or nov. The require chain in each test file is user-constants → keybindings → org-noter-config because cj/org-noter-notes-directory captures roam-dir from user-constants and the prefix-map binding at the bottom of org-noter-config references cj/custom-keymap. 30 new tests, all passing. Full suite green. --- ...st-org-noter-config--generate-notes-template.el | 62 ++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 tests/test-org-noter-config--generate-notes-template.el (limited to 'tests/test-org-noter-config--generate-notes-template.el') diff --git a/tests/test-org-noter-config--generate-notes-template.el b/tests/test-org-noter-config--generate-notes-template.el new file mode 100644 index 00000000..c4638fa7 --- /dev/null +++ b/tests/test-org-noter-config--generate-notes-template.el @@ -0,0 +1,62 @@ +;;; test-org-noter-config--generate-notes-template.el --- Tests for cj/org-noter--generate-notes-template -*- lexical-binding: t; -*- + +;;; Commentary: +;; Tests for `cj/org-noter--generate-notes-template'. The function +;; produces an org-roam-shaped buffer template with a generated UUID, +;; ROAM_REFS / NOTER_DOCUMENT pointing at the document path, and the +;; title in #+title and #+CATEGORY. `org-id-uuid' is mocked at the +;; boundary so the test is deterministic. + +;;; Code: + +(require 'ert) +(require 'cl-lib) + +(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) +(require 'user-constants) +(require 'keybindings) +(require 'org-noter-config) + +(defmacro test-org-noter-config--with-uuid (uuid &rest body) + "Run BODY with `org-id-uuid' returning UUID." + (declare (indent 1) (debug t)) + `(cl-letf (((symbol-function 'org-id-uuid) (lambda () ,uuid))) + ,@body)) + +(ert-deftest test-org-noter-config-generate-template-includes-id-property () + "Normal: template includes the supplied UUID in the :ID: property." + (test-org-noter-config--with-uuid "deadbeef-1234" + (let ((text (cj/org-noter--generate-notes-template + "The Pragmatic Programmer" "/books/pragmatic.pdf"))) + (should (string-match-p ":ID: deadbeef-1234" text))))) + +(ert-deftest test-org-noter-config-generate-template-roam-refs-and-noter-document () + "Normal: ROAM_REFS and NOTER_DOCUMENT both point at the document path." + (test-org-noter-config--with-uuid "x" + (let ((text (cj/org-noter--generate-notes-template + "Title" "/books/file.pdf"))) + (should (string-match-p ":ROAM_REFS: /books/file\\.pdf" text)) + (should (string-match-p ":NOTER_DOCUMENT: /books/file\\.pdf" text))))) + +(ert-deftest test-org-noter-config-generate-template-title-and-category () + "Normal: #+title shows the title with prefix; #+CATEGORY uses the title." + (test-org-noter-config--with-uuid "x" + (let ((text (cj/org-noter--generate-notes-template + "Anaphora Studies" "/x"))) + (should (string-match-p "^#\\+title: Notes on Anaphora Studies$" text)) + (should (string-match-p "^#\\+CATEGORY: Anaphora Studies$" text))))) + +(ert-deftest test-org-noter-config-generate-template-includes-readingnotes-tag () + "Boundary: the FILETAGS line carries the :ReadingNotes: tag." + (test-org-noter-config--with-uuid "x" + (let ((text (cj/org-noter--generate-notes-template "T" "/x"))) + (should (string-match-p "^#\\+FILETAGS: :ReadingNotes:$" text))))) + +(ert-deftest test-org-noter-config-generate-template-ends-with-notes-heading () + "Boundary: the template ends with a top-level Notes heading." + (test-org-noter-config--with-uuid "x" + (let ((text (cj/org-noter--generate-notes-template "T" "/x"))) + (should (string-match-p "\\* Notes\n\\'" text))))) + +(provide 'test-org-noter-config--generate-notes-template) +;;; test-org-noter-config--generate-notes-template.el ends here -- cgit v1.2.3