;;; 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