summaryrefslogtreecommitdiff
path: root/tests/test-video-audio-recording-get-devices.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2025-11-11 17:43:34 -0600
committerCraig Jennings <c@cjennings.net>2025-11-11 17:43:34 -0600
commitb07f8fe248db0c9916eccbc249f24d7a9107a3ce (patch)
treef6336d009b589f1840fadac901bf2758563af9aa /tests/test-video-audio-recording-get-devices.el
parent23b3df60eb619351fada7b83c9646c86e1addbd2 (diff)
a/v recording: fix setup, add test functionality and indicatorlkg
Integrates a modeline indicator to display active recording status in Emacs. The indicator shows "🔴Audio", "🔴Video", or "🔴A+V" based on the active recording processes. Includes functions for starting and stopping audio/video recordings, with sentinel processes ensuring timely updates to the modeline. Also adds extensive integration tests to validate modeline synchronization.
Diffstat (limited to 'tests/test-video-audio-recording-get-devices.el')
-rw-r--r--tests/test-video-audio-recording-get-devices.el194
1 files changed, 121 insertions, 73 deletions
diff --git a/tests/test-video-audio-recording-get-devices.el b/tests/test-video-audio-recording-get-devices.el
index b1b8470b..ba7d95b9 100644
--- a/tests/test-video-audio-recording-get-devices.el
+++ b/tests/test-video-audio-recording-get-devices.el
@@ -2,13 +2,11 @@
;;; Commentary:
;; Unit tests for cj/recording-get-devices function.
-;; Tests device auto-detection fallback logic.
+;; Tests device prompting and validation workflow.
;;
-;; Note: This function has interactive prompts, but we test the core logic paths
-;; without mocking y-or-n-p. We focus on testing:
-;; - Already-set devices (no auto-detection needed)
-;; - Successful auto-detection
-;; - Failed auto-detection → error
+;; NOTE: This function was refactored to use interactive prompts instead of
+;; auto-detection. It now prompts the user with y-or-n-p and calls either
+;; cj/recording-quick-setup-for-calls or cj/recording-select-devices.
;;; Code:
@@ -35,107 +33,157 @@
;;; Normal Cases
-(ert-deftest test-video-audio-recording-get-devices-normal-already-set-returns-devices ()
- "Test that already-set devices are returned without auto-detection."
+(ert-deftest test-video-audio-recording-get-devices-normal-returns-preset-devices ()
+ "Test that already-configured devices are returned without prompting."
(test-get-devices-setup)
(unwind-protect
(progn
- (setq cj/recording-mic-device "test-mic")
- (setq cj/recording-system-device "test-monitor")
+ (setq cj/recording-mic-device "preset-mic")
+ (setq cj/recording-system-device "preset-monitor")
(let ((result (cj/recording-get-devices)))
(should (consp result))
- (should (equal "test-mic" (car result)))
- (should (equal "test-monitor" (cdr result)))))
+ (should (equal "preset-mic" (car result)))
+ (should (equal "preset-monitor" (cdr result)))))
(test-get-devices-teardown)))
-(ert-deftest test-video-audio-recording-get-devices-normal-auto-detect-success ()
- "Test that auto-detection succeeds and returns devices."
+(ert-deftest test-video-audio-recording-get-devices-normal-prompts-when-not-configured ()
+ "Test that function prompts user when devices not configured."
(test-get-devices-setup)
(unwind-protect
- (cl-letf (((symbol-function 'cj/recording-detect-mic-device)
- (lambda () "auto-detected-mic"))
- ((symbol-function 'cj/recording-detect-system-device)
- (lambda () "auto-detected-monitor")))
- (let ((result (cj/recording-get-devices)))
- (should (consp result))
- (should (equal "auto-detected-mic" (car result)))
- (should (equal "auto-detected-monitor" (cdr result)))
- ;; Verify variables were set
- (should (equal "auto-detected-mic" cj/recording-mic-device))
- (should (equal "auto-detected-monitor" cj/recording-system-device))))
+ (let ((prompt-called nil))
+ (cl-letf (((symbol-function 'y-or-n-p)
+ (lambda (_prompt) (setq prompt-called t) t))
+ ((symbol-function 'cj/recording-quick-setup-for-calls)
+ (lambda ()
+ (setq cj/recording-mic-device "quick-mic")
+ (setq cj/recording-system-device "quick-monitor"))))
+ (cj/recording-get-devices)
+ (should prompt-called)))
(test-get-devices-teardown)))
-(ert-deftest test-video-audio-recording-get-devices-normal-partial-auto-detect ()
- "Test when only one device is already set, only the other is auto-detected."
+(ert-deftest test-video-audio-recording-get-devices-normal-calls-quick-setup-on-yes ()
+ "Test that function calls quick setup when user answers yes."
(test-get-devices-setup)
(unwind-protect
- (progn
- (setq cj/recording-mic-device "preset-mic")
- (cl-letf (((symbol-function 'cj/recording-detect-system-device)
- (lambda () "auto-detected-monitor")))
- (let ((result (cj/recording-get-devices)))
- (should (consp result))
- (should (equal "preset-mic" (car result)))
- (should (equal "auto-detected-monitor" (cdr result))))))
+ (let ((quick-setup-called nil))
+ (cl-letf (((symbol-function 'y-or-n-p)
+ (lambda (_prompt) t))
+ ((symbol-function 'cj/recording-quick-setup-for-calls)
+ (lambda ()
+ (setq quick-setup-called t)
+ (setq cj/recording-mic-device "quick-mic")
+ (setq cj/recording-system-device "quick-monitor"))))
+ (cj/recording-get-devices)
+ (should quick-setup-called)))
(test-get-devices-teardown)))
-;;; Error Cases
+(ert-deftest test-video-audio-recording-get-devices-normal-calls-select-devices-on-no ()
+ "Test that function calls manual selection when user answers no."
+ (test-get-devices-setup)
+ (unwind-protect
+ (let ((select-called nil))
+ (cl-letf (((symbol-function 'y-or-n-p)
+ (lambda (_prompt) nil))
+ ((symbol-function 'cj/recording-select-devices)
+ (lambda ()
+ (setq select-called t)
+ (setq cj/recording-mic-device "manual-mic")
+ (setq cj/recording-system-device "manual-monitor"))))
+ (cj/recording-get-devices)
+ (should select-called)))
+ (test-get-devices-teardown)))
-(ert-deftest test-video-audio-recording-get-devices-error-auto-detect-fails-signals-error ()
- "Test that failed auto-detection signals user-error.
-When auto-detection fails and user doesn't manually select, function errors."
+(ert-deftest test-video-audio-recording-get-devices-normal-returns-cons-cell ()
+ "Test that function returns (mic . monitor) cons cell."
(test-get-devices-setup)
(unwind-protect
- (cl-letf (((symbol-function 'cj/recording-detect-mic-device)
- (lambda () nil))
- ((symbol-function 'cj/recording-detect-system-device)
- (lambda () nil))
- ;; Mock y-or-n-p to say no to manual selection
- ((symbol-function 'y-or-n-p)
- (lambda (_prompt) nil)))
- (should-error (cj/recording-get-devices) :type 'user-error))
+ (cl-letf (((symbol-function 'y-or-n-p)
+ (lambda (_prompt) t))
+ ((symbol-function 'cj/recording-quick-setup-for-calls)
+ (lambda ()
+ (setq cj/recording-mic-device "test-mic")
+ (setq cj/recording-system-device "test-monitor"))))
+ (let ((result (cj/recording-get-devices)))
+ (should (consp result))
+ (should (equal "test-mic" (car result)))
+ (should (equal "test-monitor" (cdr result)))))
+ (test-get-devices-teardown)))
+
+;;; Boundary Cases
+
+(ert-deftest test-video-audio-recording-get-devices-boundary-only-mic-set-prompts ()
+ "Test that function prompts even when only mic is set."
+ (test-get-devices-setup)
+ (unwind-protect
+ (progn
+ (setq cj/recording-mic-device "preset-mic")
+ (setq cj/recording-system-device nil)
+ (let ((prompt-called nil))
+ (cl-letf (((symbol-function 'y-or-n-p)
+ (lambda (_prompt) (setq prompt-called t) t))
+ ((symbol-function 'cj/recording-quick-setup-for-calls)
+ (lambda ()
+ (setq cj/recording-mic-device "new-mic")
+ (setq cj/recording-system-device "new-monitor"))))
+ (cj/recording-get-devices)
+ (should prompt-called))))
(test-get-devices-teardown)))
-(ert-deftest test-video-audio-recording-get-devices-error-only-mic-detected-signals-error ()
- "Test that detecting only mic (no monitor) signals error."
+(ert-deftest test-video-audio-recording-get-devices-boundary-only-monitor-set-prompts ()
+ "Test that function prompts even when only monitor is set."
(test-get-devices-setup)
(unwind-protect
- (cl-letf (((symbol-function 'cj/recording-detect-mic-device)
- (lambda () "detected-mic"))
- ((symbol-function 'cj/recording-detect-system-device)
- (lambda () nil))
- ((symbol-function 'y-or-n-p)
- (lambda (_prompt) nil)))
- (should-error (cj/recording-get-devices) :type 'user-error))
+ (progn
+ (setq cj/recording-mic-device nil)
+ (setq cj/recording-system-device "preset-monitor")
+ (let ((prompt-called nil))
+ (cl-letf (((symbol-function 'y-or-n-p)
+ (lambda (_prompt) (setq prompt-called t) t))
+ ((symbol-function 'cj/recording-quick-setup-for-calls)
+ (lambda ()
+ (setq cj/recording-mic-device "new-mic")
+ (setq cj/recording-system-device "new-monitor"))))
+ (cj/recording-get-devices)
+ (should prompt-called))))
(test-get-devices-teardown)))
-(ert-deftest test-video-audio-recording-get-devices-error-only-monitor-detected-signals-error ()
- "Test that detecting only monitor (no mic) signals error."
+;;; Error Cases
+
+(ert-deftest test-video-audio-recording-get-devices-error-setup-fails-signals-error ()
+ "Test that function signals error when setup fails to set devices."
(test-get-devices-setup)
(unwind-protect
- (cl-letf (((symbol-function 'cj/recording-detect-mic-device)
- (lambda () nil))
- ((symbol-function 'cj/recording-detect-system-device)
- (lambda () "detected-monitor"))
- ((symbol-function 'y-or-n-p)
- (lambda (_prompt) nil)))
+ (cl-letf (((symbol-function 'y-or-n-p)
+ (lambda (_prompt) t))
+ ((symbol-function 'cj/recording-quick-setup-for-calls)
+ (lambda () nil))) ;; Setup fails - doesn't set devices
(should-error (cj/recording-get-devices) :type 'user-error))
(test-get-devices-teardown)))
-(ert-deftest test-video-audio-recording-get-devices-error-message-mentions-select-devices ()
- "Test that error message guides user to manual selection command."
+(ert-deftest test-video-audio-recording-get-devices-error-message-mentions-setup-commands ()
+ "Test that error message guides user to setup commands."
(test-get-devices-setup)
(unwind-protect
- (cl-letf (((symbol-function 'cj/recording-detect-mic-device)
- (lambda () nil))
- ((symbol-function 'cj/recording-detect-system-device)
- (lambda () nil))
- ((symbol-function 'y-or-n-p)
- (lambda (_prompt) nil)))
+ (cl-letf (((symbol-function 'y-or-n-p)
+ (lambda (_prompt) t))
+ ((symbol-function 'cj/recording-quick-setup-for-calls)
+ (lambda () nil)))
(condition-case err
(cj/recording-get-devices)
(user-error
- (should (string-match-p "cj/recording-select-devices" (error-message-string err))))))
+ (should (string-match-p "C-; r c" (error-message-string err)))
+ (should (string-match-p "C-; r s" (error-message-string err))))))
+ (test-get-devices-teardown)))
+
+(ert-deftest test-video-audio-recording-get-devices-error-select-devices-fails ()
+ "Test that function signals error when manual selection fails."
+ (test-get-devices-setup)
+ (unwind-protect
+ (cl-letf (((symbol-function 'y-or-n-p)
+ (lambda (_prompt) nil))
+ ((symbol-function 'cj/recording-select-devices)
+ (lambda () nil))) ;; Manual selection fails
+ (should-error (cj/recording-get-devices) :type 'user-error))
(test-get-devices-teardown)))
(provide 'test-video-audio-recording-get-devices)