;;; test-org-reveal-config-sizing.el --- Tests for reveal.js slide sizing and auto-fit -*- lexical-binding: t; -*- ;;; Commentary: ;; Dense slides overflowed reveal.js's 960x700 canvas at the theme's 42px ;; base font and were clipped with no way to scroll. The module now ships ;; a 16:9 canvas with a smaller base font (via the head preamble) and a ;; script, spliced in after Reveal.initialize, that shrinks any slide whose ;; content still overflows. These tests pin the three builders and run the ;; fit algorithm under node against a stub Reveal API. ;;; Code: (require 'ert) (require 'cl-lib) (require 'json) (add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) (require 'keybindings) (require 'org-reveal-config) (defun test-org-reveal-config--count (regexp string) "Return how many times REGEXP matches in STRING." (let ((n 0) (start 0)) (while (string-match regexp string start) (setq n (1+ n) start (match-end 0))) n)) ;; ------------------------------ Init options ------------------------------- (ert-deftest test-org-reveal-config-init-options-normal-has-behaviour-and-canvas () "Normal: the shared init options carry slide numbers, hash, transition and the canvas size." (let ((opts (cj/--reveal-init-options))) (should (string-match-p "slideNumber:true" opts)) (should (string-match-p "hash:true" opts)) (should (string-match-p (format "transition:'%s'" cj/reveal-default-transition) opts)) (should (string-match-p (format "width:%d" cj/reveal-canvas-width) opts)) (should (string-match-p (format "height:%d" cj/reveal-canvas-height) opts)))) (ert-deftest test-org-reveal-config-init-options-boundary-splices-into-initialize () "Boundary: one line, no trailing comma, so it splices into Reveal.initialize({...})." (let ((opts (cj/--reveal-init-options))) (should-not (string-match-p "\n" opts)) (should-not (string-suffix-p "," (string-trim opts))))) (ert-deftest test-org-reveal-config-init-options-normal-canvas-is-16-9 () "Normal: the canvas is a 16:9 frame, the shape of every projector and monitor the slides land on." (should (= (* 9 cj/reveal-canvas-width) (* 16 cj/reveal-canvas-height)))) (ert-deftest test-org-reveal-config-header-template-normal-uses-shared-init-options () "Normal: the header template emits the same init options as the global default, so a file never drifts from the module." (let ((result (cj/--reveal-header-template "Sizing"))) (should (string-match-p (format "^#\\+REVEAL_INIT_OPTIONS: %s$" (regexp-quote (cj/--reveal-init-options))) result)))) ;; ------------------------------ Head preamble ------------------------------ (ert-deftest test-org-reveal-config-head-preamble-normal-sets-font-sizes () "Normal: the preamble lowers the theme's base font and heading sizes through the theme variables." (let ((css (cj/--reveal-head-preamble))) (should (string-match-p (format "--r-main-font-size: *%s" (regexp-quote cj/reveal-base-font-size)) css)) (should (string-match-p "--r-heading1-size" css)) (should (string-match-p "--r-heading2-size" css)))) (ert-deftest test-org-reveal-config-head-preamble-normal-keeps-no-caps-rule () "Normal: the rule that stops the theme upper-casing headings survives the rewrite." (should (string-match-p "text-transform: *none" (cj/--reveal-head-preamble)))) (ert-deftest test-org-reveal-config-head-preamble-normal-left-aligns-slide-content () "Normal: slide text is left-aligned by default; the title slide and standalone images keep reveal's centering." (let ((css (cj/--reveal-head-preamble))) (should (string-match-p "\\.reveal \\.slides section {[^}]*text-align: *left" css)) (should (string-match-p "#sec-title-slide {[^}]*text-align: *center" css)) (should (string-match-p "section \\.figure {[^}]*text-align: *center" css)))) (ert-deftest test-org-reveal-config-head-preamble-boundary-one-style-element () "Boundary: exactly one " css))))) ;; -------------------------------- Fit script ------------------------------- (ert-deftest test-org-reveal-config-fit-script-normal-hooks-reveal-events () "Normal: the script fits every slide once reveal is ready and refits on each slide change." (let ((js (cj/--reveal-fit-script))) (should (string-match-p "Reveal\\.on('ready'" js)) (should (string-match-p "Reveal\\.on('slidechanged'" js)) (should (string-match-p "Reveal\\.on('overviewhidden'" js)) (should (string-match-p "isOverview" js)) (should (string-match-p "scrollHeight" js)) (should (string-match-p "getConfig()\\.height" js)))) (ert-deftest test-org-reveal-config-fit-script-boundary-no-script-tags () "Boundary: ox-reveal splices the text inside its own