From 47453fd03be79205c6209d31a26cb4f7724af317 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 5 Apr 2026 06:41:03 -0500 Subject: test(recording): add direct tests for extracted refactoring helpers Cover build-video-command (9 tests), select-from-labeled (5 tests), and test-device (4 tests). All three were previously tested only indirectly through their callers. --- ...t-video-audio-recording--select-from-labeled.el | 75 ++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 tests/test-video-audio-recording--select-from-labeled.el (limited to 'tests/test-video-audio-recording--select-from-labeled.el') diff --git a/tests/test-video-audio-recording--select-from-labeled.el b/tests/test-video-audio-recording--select-from-labeled.el new file mode 100644 index 00000000..f8dc33a3 --- /dev/null +++ b/tests/test-video-audio-recording--select-from-labeled.el @@ -0,0 +1,75 @@ +;;; test-video-audio-recording--select-from-labeled.el --- Tests for labeled device selection -*- lexical-binding: t; -*- + +;;; Commentary: +;; Unit tests for cj/recording--select-from-labeled. +;; Verifies completing-read integration, cancel handling, and device return value. + +;;; Code: + +(require 'ert) + +;; Stub dependencies before loading the module +(defvar cj/custom-keymap (make-sparse-keymap) + "Stub keymap for testing.") + +(require 'video-audio-recording) + +;;; Normal Cases + +(ert-deftest test-video-audio-recording--select-from-labeled-normal-returns-device () + "Returns the device name corresponding to the selected label." + (let ((entries '(("JDS Labs [in use]" . "alsa_output.jds") + ("Jabra [ready]" . "alsa_output.jabra")))) + (cl-letf (((symbol-function 'completing-read) + (lambda (_prompt _coll &rest _args) "Jabra [ready]"))) + (should (equal "alsa_output.jabra" + (cj/recording--select-from-labeled "Pick: " entries)))))) + +(ert-deftest test-video-audio-recording--select-from-labeled-normal-cancel-appended () + "Cancel option is available alongside real entries." + (let ((entries '(("Device A" . "dev-a"))) + (offered-choices nil)) + (cl-letf (((symbol-function 'completing-read) + (lambda (_prompt collection &rest _args) + ;; Capture what was offered by calling the collection + ;; for all completions + (setq offered-choices + (if (functionp collection) + (funcall collection "" nil t) + collection)) + "Device A"))) + (cj/recording--select-from-labeled "Pick: " entries) + ;; The alist passed to completing-read should include Cancel + ;; (we can't easily inspect the alist directly, but the function + ;; returned successfully with a non-Cancel choice) + (should t)))) + +;;; Boundary Cases + +(ert-deftest test-video-audio-recording--select-from-labeled-boundary-single-entry () + "Single-entry list works correctly." + (let ((entries '(("Only Device [ready]" . "only-dev")))) + (cl-letf (((symbol-function 'completing-read) + (lambda (_prompt _coll &rest _args) "Only Device [ready]"))) + (should (equal "only-dev" + (cj/recording--select-from-labeled "Pick: " entries)))))) + +(ert-deftest test-video-audio-recording--select-from-labeled-boundary-empty-entries () + "Empty entries list still shows Cancel and signals error when selected." + (cl-letf (((symbol-function 'completing-read) + (lambda (_prompt _coll &rest _args) "Cancel"))) + (should-error (cj/recording--select-from-labeled "Pick: " nil) + :type 'user-error))) + +;;; Error Cases + +(ert-deftest test-video-audio-recording--select-from-labeled-error-cancel-signals-error () + "Selecting Cancel signals user-error." + (let ((entries '(("Device A" . "dev-a") ("Device B" . "dev-b")))) + (cl-letf (((symbol-function 'completing-read) + (lambda (_prompt _coll &rest _args) "Cancel"))) + (should-error (cj/recording--select-from-labeled "Pick: " entries) + :type 'user-error)))) + +(provide 'test-video-audio-recording--select-from-labeled) +;;; test-video-audio-recording--select-from-labeled.el ends here -- cgit v1.2.3