summaryrefslogtreecommitdiff
path: root/tests/test-video-audio-recording-modeline-indicator.el
blob: f7f3bbff3d9860e1b5e5764936f24888d241d1d4 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
;;; test-video-audio-recording-modeline-indicator.el --- Tests for cj/recording-modeline-indicator -*- lexical-binding: t; -*-

;;; Commentary:
;; Unit tests for cj/recording-modeline-indicator function.
;; Tests modeline indicator display based on active recording processes.

;;; 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-modeline-indicator-setup ()
  "Reset process variables before each test."
  (setq cj/audio-recording-ffmpeg-process nil)
  (setq cj/video-recording-ffmpeg-process nil))

(defun test-modeline-indicator-teardown ()
  "Clean up process variables after each test."
  (setq cj/audio-recording-ffmpeg-process nil)
  (setq cj/video-recording-ffmpeg-process nil))

;;; Normal Cases

(ert-deftest test-video-audio-recording-modeline-indicator-normal-no-processes-returns-empty ()
  "Test that indicator returns empty string when no processes are active."
  (test-modeline-indicator-setup)
  (unwind-protect
      (let ((result (cj/recording-modeline-indicator)))
        (should (stringp result))
        (should (equal "" result)))
    (test-modeline-indicator-teardown)))

(ert-deftest test-video-audio-recording-modeline-indicator-normal-audio-only-shows-audio ()
  "Test that indicator shows audio when only audio process is active."
  (test-modeline-indicator-setup)
  (unwind-protect
      (let ((fake-process (make-process :name "test-audio" :command '("sleep" "1000"))))
        (setq cj/audio-recording-ffmpeg-process fake-process)
        (let ((result (cj/recording-modeline-indicator)))
          (should (equal " 🔴Audio " result)))
        (delete-process fake-process))
    (test-modeline-indicator-teardown)))

(ert-deftest test-video-audio-recording-modeline-indicator-normal-video-only-shows-video ()
  "Test that indicator shows video when only video process is active."
  (test-modeline-indicator-setup)
  (unwind-protect
      (let ((fake-process (make-process :name "test-video" :command '("sleep" "1000"))))
        (setq cj/video-recording-ffmpeg-process fake-process)
        (let ((result (cj/recording-modeline-indicator)))
          (should (equal " 🔴Video " result)))
        (delete-process fake-process))
    (test-modeline-indicator-teardown)))

(ert-deftest test-video-audio-recording-modeline-indicator-normal-both-shows-combined ()
  "Test that indicator shows A+V when both processes are active."
  (test-modeline-indicator-setup)
  (unwind-protect
      (let ((audio-proc (make-process :name "test-audio" :command '("sleep" "1000")))
            (video-proc (make-process :name "test-video" :command '("sleep" "1000"))))
        (setq cj/audio-recording-ffmpeg-process audio-proc)
        (setq cj/video-recording-ffmpeg-process video-proc)
        (let ((result (cj/recording-modeline-indicator)))
          (should (equal " 🔴A+V " result)))
        (delete-process audio-proc)
        (delete-process video-proc))
    (test-modeline-indicator-teardown)))

;;; Boundary Cases

(ert-deftest test-video-audio-recording-modeline-indicator-boundary-dead-audio-process-returns-empty ()
  "Test that indicator returns empty string when audio process variable is set but process is dead."
  (test-modeline-indicator-setup)
  (unwind-protect
      (let ((fake-process (make-process :name "test-audio" :command '("sleep" "1000"))))
        (setq cj/audio-recording-ffmpeg-process fake-process)
        ;; Kill the process
        (delete-process fake-process)
        ;; Wait for process to be fully dead
        (sit-for 0.1)
        (let ((result (cj/recording-modeline-indicator)))
          (should (equal "" result))))
    (test-modeline-indicator-teardown)))

(ert-deftest test-video-audio-recording-modeline-indicator-boundary-dead-video-process-returns-empty ()
  "Test that indicator returns empty string when video process variable is set but process is dead."
  (test-modeline-indicator-setup)
  (unwind-protect
      (let ((fake-process (make-process :name "test-video" :command '("sleep" "1000"))))
        (setq cj/video-recording-ffmpeg-process fake-process)
        ;; Kill the process
        (delete-process fake-process)
        ;; Wait for process to be fully dead
        (sit-for 0.1)
        (let ((result (cj/recording-modeline-indicator)))
          (should (equal "" result))))
    (test-modeline-indicator-teardown)))

(ert-deftest test-video-audio-recording-modeline-indicator-boundary-one-dead-one-alive-shows-alive ()
  "Test that only the alive process shows when one is dead and one is alive."
  (test-modeline-indicator-setup)
  (unwind-protect
      (let ((dead-proc (make-process :name "test-dead" :command '("sleep" "1000")))
            (alive-proc (make-process :name "test-alive" :command '("sleep" "1000"))))
        (setq cj/audio-recording-ffmpeg-process dead-proc)
        (setq cj/video-recording-ffmpeg-process alive-proc)
        (delete-process dead-proc)
        (sit-for 0.1)
        (let ((result (cj/recording-modeline-indicator)))
          (should (equal " 🔴Video " result)))
        (delete-process alive-proc))
    (test-modeline-indicator-teardown)))

(ert-deftest test-video-audio-recording-modeline-indicator-boundary-nil-process-variables ()
  "Test that nil process variables are handled gracefully."
  (test-modeline-indicator-setup)
  (unwind-protect
      (progn
        (setq cj/audio-recording-ffmpeg-process nil)
        (setq cj/video-recording-ffmpeg-process nil)
        (let ((result (cj/recording-modeline-indicator)))
          (should (equal "" result))))
    (test-modeline-indicator-teardown)))

(provide 'test-video-audio-recording-modeline-indicator)
;;; test-video-audio-recording-modeline-indicator.el ends here