aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-04-19 07:15:29 -0500
committerCraig Jennings <c@cjennings.net>2026-04-19 07:15:29 -0500
commite7e7b91a983f375057a05e9e9cdeeb2ddf5039a6 (patch)
tree13635c1b36df11b1c18d4e7ee3f7e76f4f6d4180 /tests
parentcd66870c142555b28bc8b73e91047506ce80c119 (diff)
downloaddotemacs-e7e7b91a983f375057a05e9e9cdeeb2ddf5039a6.tar.gz
dotemacs-e7e7b91a983f375057a05e9e9cdeeb2ddf5039a6.zip
refactor(transcription): extract running-transcriptions and format-entry
Two cleanups round out the transcription-config refactor: - cj/--running-transcriptions: the 'status = running' filter used by cleanup and count helpers is now one function. Existing counter tests cover both callers. - cj/--format-transcription-entry: the 13-line dolist body inside cj/transcriptions-buffer becomes a testable pure function. 6 tests cover status-face mapping, basename-only rendering, duration format, trailing newline.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-transcription-format-entry.el66
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/test-transcription-format-entry.el b/tests/test-transcription-format-entry.el
new file mode 100644
index 000000000..a91b531b7
--- /dev/null
+++ b/tests/test-transcription-format-entry.el
@@ -0,0 +1,66 @@
+;;; test-transcription-format-entry.el --- Tests for format-transcription-entry -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; Tests for `cj/--format-transcription-entry', which renders a single
+;; transcription entry for display in the *Transcriptions* buffer.
+
+;;; Code:
+
+(require 'ert)
+
+(defvar cj/custom-keymap (make-sparse-keymap))
+
+(unless (fboundp 'notifications-notify)
+ (defun notifications-notify (&rest _args) nil))
+
+(require 'transcription-config)
+
+(defun test-format-entry-face-at (string needle)
+ "Return the `face' property at the start of NEEDLE within STRING."
+ (let ((pos (string-match-p (regexp-quote needle) string)))
+ (and pos (get-text-property pos 'face string))))
+
+;;; Normal Cases
+
+(ert-deftest test-format-entry-normal-running-uses-warning-face ()
+ "Running status renders with the `warning' face."
+ (let* ((entry '(proc "/tmp/a.m4a" (0 0 0 0) running))
+ (s (cj/--format-transcription-entry entry)))
+ (should (string-match-p "running" s))
+ (should (eq 'warning (test-format-entry-face-at s "running")))))
+
+(ert-deftest test-format-entry-normal-complete-uses-success-face ()
+ "Complete status renders with the `success' face."
+ (let* ((entry '(proc "/tmp/a.m4a" (0 0 0 0) complete))
+ (s (cj/--format-transcription-entry entry)))
+ (should (string-match-p "complete" s))
+ (should (eq 'success (test-format-entry-face-at s "complete")))))
+
+(ert-deftest test-format-entry-normal-error-uses-error-face ()
+ "Error status renders with the `error' face."
+ (let* ((entry '(proc "/tmp/a.m4a" (0 0 0 0) error))
+ (s (cj/--format-transcription-entry entry)))
+ (should (string-match-p "error" s))
+ (should (eq 'error (test-format-entry-face-at s "error")))))
+
+(ert-deftest test-format-entry-normal-shows-basename-only ()
+ "Only the file's basename appears; the directory path is stripped."
+ (let* ((entry '(proc "/deep/nested/path/track.m4a" (0 0 0 0) running))
+ (s (cj/--format-transcription-entry entry)))
+ (should (string-match-p "track\\.m4a" s))
+ (should-not (string-match-p "/deep/nested" s))))
+
+(ert-deftest test-format-entry-normal-includes-duration-in-parens ()
+ "Rendering includes a parenthesised duration."
+ (let* ((entry '(proc "/a.m4a" (0 0 0 0) running))
+ (s (cj/--format-transcription-entry entry)))
+ (should (string-match-p "([0-9]+:[0-9][0-9])" s))))
+
+(ert-deftest test-format-entry-normal-ends-with-newline ()
+ "Each rendered entry terminates with a newline for buffer concatenation."
+ (let* ((entry '(proc "/a.m4a" (0 0 0 0) running))
+ (s (cj/--format-transcription-entry entry)))
+ (should (string-suffix-p "\n" s))))
+
+(provide 'test-transcription-format-entry)
+;;; test-transcription-format-entry.el ends here