diff options
| author | Craig Jennings <c@cjennings.net> | 2026-04-05 06:41:03 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-04-05 06:41:03 -0500 |
| commit | 0d562cfbc5daac8a22e6ace8933cd9b69b32c76d (patch) | |
| tree | 42daceb74d2ca1b53baf2c076cd7dfabba21d882 /tests/test-video-audio-recording--select-from-labeled.el | |
| parent | f6ef9b130480be331d7d3d271c60d9a166482957 (diff) | |
| download | dotemacs-0d562cfbc5daac8a22e6ace8933cd9b69b32c76d.tar.gz dotemacs-0d562cfbc5daac8a22e6ace8933cd9b69b32c76d.zip | |
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.
Diffstat (limited to 'tests/test-video-audio-recording--select-from-labeled.el')
| -rw-r--r-- | tests/test-video-audio-recording--select-from-labeled.el | 75 |
1 files changed, 75 insertions, 0 deletions
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 |
