summaryrefslogtreecommitdiff
path: root/tests/test-video-audio-recording--device-sort-key.el
blob: 97e67747e6924900b1ca7ee97a217f5574021f81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
;;; test-video-audio-recording--device-sort-key.el --- Tests for device sort key -*- lexical-binding: t; -*-

;;; Commentary:
;; Unit tests for cj/recording--device-sort-key.
;; Verifies numeric sort key assignment: RUNNING=0, IDLE=1, SUSPENDED=2, muted=3.

;;; 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--device-sort-key-normal-running ()
  "RUNNING unmuted device returns 0 (highest priority)."
  (should (= 0 (cj/recording--device-sort-key "RUNNING" "no"))))

(ert-deftest test-video-audio-recording--device-sort-key-normal-idle ()
  "IDLE unmuted device returns 1."
  (should (= 1 (cj/recording--device-sort-key "IDLE" "no"))))

(ert-deftest test-video-audio-recording--device-sort-key-normal-suspended ()
  "SUSPENDED unmuted device returns 2."
  (should (= 2 (cj/recording--device-sort-key "SUSPENDED" "no"))))

(ert-deftest test-video-audio-recording--device-sort-key-normal-muted-overrides-state ()
  "Muted device returns 3 regardless of state."
  (should (= 3 (cj/recording--device-sort-key "RUNNING" "yes")))
  (should (= 3 (cj/recording--device-sort-key "IDLE" "yes")))
  (should (= 3 (cj/recording--device-sort-key "SUSPENDED" "yes"))))

;;; Boundary Cases

(ert-deftest test-video-audio-recording--device-sort-key-boundary-nil-state ()
  "Nil state with unmuted returns 2 (default/available)."
  (should (= 2 (cj/recording--device-sort-key nil "no"))))

(ert-deftest test-video-audio-recording--device-sort-key-boundary-lowercase-state ()
  "Lowercase state is handled via upcase."
  (should (= 0 (cj/recording--device-sort-key "running" "no")))
  (should (= 1 (cj/recording--device-sort-key "idle" "no"))))

(ert-deftest test-video-audio-recording--device-sort-key-boundary-empty-state ()
  "Empty string state returns 2 (default)."
  (should (= 2 (cj/recording--device-sort-key "" "no"))))

;;; Error Cases

(ert-deftest test-video-audio-recording--device-sort-key-error-unknown-state ()
  "Unknown state string returns 2 (falls through to default)."
  (should (= 2 (cj/recording--device-sort-key "BOGUS" "no"))))

(ert-deftest test-video-audio-recording--device-sort-key-error-muted-nil-state ()
  "Muted with nil state still returns 3 (muted check is first)."
  (should (= 3 (cj/recording--device-sort-key nil "yes"))))

(provide 'test-video-audio-recording--device-sort-key)
;;; test-video-audio-recording--device-sort-key.el ends here