summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-12 06:07:20 -0500
committerCraig Jennings <c@cjennings.net>2026-05-12 06:07:20 -0500
commit7f51842c920f708ec8588ae9a178fdbc28d31f46 (patch)
treebfe1837b905431587b4f2e48312db8945817baba /tests
parentfb39fe85378b58b77d2c5a7a6464b1b4aec0b85d (diff)
downloaddotemacs-7f51842c920f708ec8588ae9a178fdbc28d31f46.tar.gz
dotemacs-7f51842c920f708ec8588ae9a178fdbc28d31f46.zip
feat(org): add reveal.js present command and header removal
`C-; p SPC' (`cj/reveal-present') is the new fast path: it inserts reveal.js headers if the buffer doesn't have them (prompting for a title), saves the buffer, exports to self-contained HTML, and opens it in the browser. It's the export-and-open you'd otherwise reach by doing `C-; p h' then `C-; p e'. `C-; p H' (`cj/reveal-remove-headers') strips the header block this module inserts, and `C-; p h' (`cj/reveal-insert-header') now errors instead of duplicating headers when a reveal block is already present. The header logic moved into small helpers (`cj/--reveal-has-header-p', `cj/--reveal-remove-headers', `cj/--reveal-ensure-header', `cj/--reveal-keyword-regexp', and the `cj/--reveal-header-keywords' list), and `test-org-reveal-config-headers.el' drives them directly: detection on a reveal vs. a plain Org buffer, removal of the generated block (and only the leading block), body preservation, and the no-duplicate-headers error.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-org-reveal-config-headers.el64
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/test-org-reveal-config-headers.el b/tests/test-org-reveal-config-headers.el
new file mode 100644
index 00000000..b7152336
--- /dev/null
+++ b/tests/test-org-reveal-config-headers.el
@@ -0,0 +1,64 @@
+;;; test-org-reveal-config-headers.el --- Tests for org-reveal header helpers -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; Tests for detecting and removing reveal.js headers from Org buffers.
+
+;;; Code:
+
+(require 'ert)
+(require 'org)
+
+(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
+
+;; Stub ox-reveal dependency (not available in batch mode)
+(provide 'ox-reveal)
+
+(require 'org-reveal-config)
+
+(defmacro test-org-reveal-headers--with-org-buffer (content &rest body)
+ "Run BODY in a temporary org-mode buffer containing CONTENT."
+ (declare (indent 1))
+ `(with-temp-buffer
+ (insert ,content)
+ (goto-char (point-min))
+ (org-mode)
+ ,@body))
+
+(ert-deftest test-org-reveal-has-header-detects-reveal-header ()
+ "Normal: a reveal metadata line marks the buffer as reveal-enabled."
+ (test-org-reveal-headers--with-org-buffer "#+REVEAL_THEME: black\n* Slide\n"
+ (should (cj/--reveal-has-header-p))))
+
+(ert-deftest test-org-reveal-has-header-ignores-plain-org-header ()
+ "Boundary: ordinary Org metadata alone is not an org-reveal header."
+ (test-org-reveal-headers--with-org-buffer "#+TITLE: Notes\n* Heading\n"
+ (should-not (cj/--reveal-has-header-p))))
+
+(ert-deftest test-org-reveal-remove-headers-removes-generated-metadata ()
+ "Normal: remove generated reveal presentation headers."
+ (let ((template (cj/--reveal-header-template "My Talk")))
+ (test-org-reveal-headers--with-org-buffer (concat template "* Slide 1\nBody\n")
+ (should (= 9 (cj/--reveal-remove-headers)))
+ (should (equal (buffer-string) "* Slide 1\nBody\n")))))
+
+(ert-deftest test-org-reveal-remove-headers-preserves-body-content ()
+ "Normal: non-header body content remains unchanged."
+ (test-org-reveal-headers--with-org-buffer
+ "#+TITLE: Talk\n#+REVEAL_THEME: black\n* Slide\nSome text\n"
+ (cj/--reveal-remove-headers)
+ (should (equal (buffer-string) "* Slide\nSome text\n"))))
+
+(ert-deftest test-org-reveal-remove-headers-only-removes-leading-block ()
+ "Boundary: later Org metadata remains untouched."
+ (test-org-reveal-headers--with-org-buffer
+ "#+TITLE: Talk\n#+REVEAL_THEME: black\n* Slide\n#+TITLE: Nested\n"
+ (cj/--reveal-remove-headers)
+ (should (equal (buffer-string) "* Slide\n#+TITLE: Nested\n"))))
+
+(ert-deftest test-org-reveal-insert-header-errors-when-present ()
+ "Regression: inserting headers should not duplicate an existing reveal block."
+ (test-org-reveal-headers--with-org-buffer "#+REVEAL_THEME: black\n* Slide\n"
+ (should-error (cj/reveal-insert-header) :type 'user-error)))
+
+(provide 'test-org-reveal-config-headers)
+;;; test-org-reveal-config-headers.el ends here