summaryrefslogtreecommitdiff
path: root/tests/test-video-audio-recording-quick-setup-for-calls.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-quick-setup-for-calls.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-quick-setup-for-calls.el')
-rw-r--r--tests/test-video-audio-recording-quick-setup-for-calls.el144
1 files changed, 144 insertions, 0 deletions
diff --git a/tests/test-video-audio-recording-quick-setup-for-calls.el b/tests/test-video-audio-recording-quick-setup-for-calls.el
new file mode 100644
index 00000000..0d3fe53a
--- /dev/null
+++ b/tests/test-video-audio-recording-quick-setup-for-calls.el
@@ -0,0 +1,144 @@
+;;; test-video-audio-recording-quick-setup-for-calls.el --- Tests for cj/recording-quick-setup-for-calls -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; Unit tests for cj/recording-quick-setup-for-calls function.
+;; Tests quick device setup workflow for call recording.
+
+;;; Code:
+
+(require 'ert)
+
+;; Stub dependencies before loading the module
+(defvar cj/custom-keymap (make-sparse-keymap)
+ "Stub keymap for testing.")
+
+;; Now load the actual production module
+(require 'video-audio-recording)
+
+;;; Setup and Teardown
+
+(defun test-quick-setup-setup ()
+ "Reset device variables before each test."
+ (setq cj/recording-mic-device nil)
+ (setq cj/recording-system-device nil))
+
+(defun test-quick-setup-teardown ()
+ "Clean up device variables after each test."
+ (setq cj/recording-mic-device nil)
+ (setq cj/recording-system-device nil))
+
+;;; Normal Cases
+
+(ert-deftest test-video-audio-recording-quick-setup-for-calls-normal-sets-both-devices ()
+ "Test that function sets both mic and system device variables."
+ (test-quick-setup-setup)
+ (unwind-protect
+ (let ((grouped-devices '(("Bluetooth Headset" . ("bluez_input.00:1B:66" . "bluez_output.00_1B_66.monitor")))))
+ (cl-letf (((symbol-function 'cj/recording-group-devices-by-hardware)
+ (lambda () grouped-devices))
+ ((symbol-function 'completing-read)
+ (lambda (_prompt _choices &rest _args) "Bluetooth Headset")))
+ (cj/recording-quick-setup-for-calls)
+ (should (equal "bluez_input.00:1B:66" cj/recording-mic-device))
+ (should (equal "bluez_output.00_1B_66.monitor" cj/recording-system-device))))
+ (test-quick-setup-teardown)))
+
+(ert-deftest test-video-audio-recording-quick-setup-for-calls-normal-presents-friendly-names ()
+ "Test that function presents friendly device names to user."
+ (test-quick-setup-setup)
+ (unwind-protect
+ (let ((grouped-devices '(("Jabra SPEAK 510 USB" . ("usb-input" . "usb-monitor"))
+ ("Built-in Laptop Audio" . ("pci-input" . "pci-monitor"))))
+ (presented-choices nil))
+ (cl-letf (((symbol-function 'cj/recording-group-devices-by-hardware)
+ (lambda () grouped-devices))
+ ((symbol-function 'completing-read)
+ (lambda (_prompt choices &rest _args)
+ (setq presented-choices choices)
+ (car choices))))
+ (cj/recording-quick-setup-for-calls)
+ (should (member "Jabra SPEAK 510 USB" presented-choices))
+ (should (member "Built-in Laptop Audio" presented-choices))))
+ (test-quick-setup-teardown)))
+
+(ert-deftest test-video-audio-recording-quick-setup-for-calls-normal-displays-confirmation ()
+ "Test that function displays confirmation message with device details."
+ (test-quick-setup-setup)
+ (unwind-protect
+ (let ((grouped-devices '(("Bluetooth Headset" . ("bluez_input.00:1B:66" . "bluez_output.00_1B_66.monitor"))))
+ (message-text nil))
+ (cl-letf (((symbol-function 'cj/recording-group-devices-by-hardware)
+ (lambda () grouped-devices))
+ ((symbol-function 'completing-read)
+ (lambda (_prompt _choices &rest _args) "Bluetooth Headset"))
+ ((symbol-function 'message)
+ (lambda (fmt &rest args) (setq message-text (apply #'format fmt args)))))
+ (cj/recording-quick-setup-for-calls)
+ (should (string-match-p "Call recording ready" message-text))
+ (should (string-match-p "Bluetooth Headset" message-text))))
+ (test-quick-setup-teardown)))
+
+;;; Boundary Cases
+
+(ert-deftest test-video-audio-recording-quick-setup-for-calls-boundary-single-device-no-prompt ()
+ "Test that with single device, selection still happens."
+ (test-quick-setup-setup)
+ (unwind-protect
+ (let ((grouped-devices '(("Built-in Laptop Audio" . ("pci-input" . "pci-monitor")))))
+ (cl-letf (((symbol-function 'cj/recording-group-devices-by-hardware)
+ (lambda () grouped-devices))
+ ((symbol-function 'completing-read)
+ (lambda (_prompt _choices &rest _args) "Built-in Laptop Audio")))
+ (cj/recording-quick-setup-for-calls)
+ (should (equal "pci-input" cj/recording-mic-device))
+ (should (equal "pci-monitor" cj/recording-system-device))))
+ (test-quick-setup-teardown)))
+
+(ert-deftest test-video-audio-recording-quick-setup-for-calls-boundary-device-name-with-special-chars ()
+ "Test that device names with special characters are handled correctly."
+ (test-quick-setup-setup)
+ (unwind-protect
+ (let ((grouped-devices '(("Device (USB-C)" . ("special-input" . "special-monitor")))))
+ (cl-letf (((symbol-function 'cj/recording-group-devices-by-hardware)
+ (lambda () grouped-devices))
+ ((symbol-function 'completing-read)
+ (lambda (_prompt _choices &rest _args) "Device (USB-C)")))
+ (cj/recording-quick-setup-for-calls)
+ (should (equal "special-input" cj/recording-mic-device))
+ (should (equal "special-monitor" cj/recording-system-device))))
+ (test-quick-setup-teardown)))
+
+;;; Error Cases
+
+(ert-deftest test-video-audio-recording-quick-setup-for-calls-error-no-devices-signals-error ()
+ "Test that function signals user-error when no complete devices are found."
+ (test-quick-setup-setup)
+ (unwind-protect
+ (cl-letf (((symbol-function 'cj/recording-group-devices-by-hardware)
+ (lambda () nil)))
+ (should-error (cj/recording-quick-setup-for-calls) :type 'user-error))
+ (test-quick-setup-teardown)))
+
+(ert-deftest test-video-audio-recording-quick-setup-for-calls-error-message-mentions-both-devices ()
+ "Test that error message mentions need for both mic and monitor."
+ (test-quick-setup-setup)
+ (unwind-protect
+ (cl-letf (((symbol-function 'cj/recording-group-devices-by-hardware)
+ (lambda () nil)))
+ (condition-case err
+ (cj/recording-quick-setup-for-calls)
+ (user-error
+ (should (string-match-p "both mic and monitor" (error-message-string err))))))
+ (test-quick-setup-teardown)))
+
+(ert-deftest test-video-audio-recording-quick-setup-for-calls-error-empty-device-list ()
+ "Test that empty device list from grouping is handled gracefully."
+ (test-quick-setup-setup)
+ (unwind-protect
+ (cl-letf (((symbol-function 'cj/recording-group-devices-by-hardware)
+ (lambda () '())))
+ (should-error (cj/recording-quick-setup-for-calls) :type 'user-error))
+ (test-quick-setup-teardown)))
+
+(provide 'test-video-audio-recording-quick-setup-for-calls)
+;;; test-video-audio-recording-quick-setup-for-calls.el ends here