-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain_test.go
More file actions
80 lines (66 loc) · 1.8 KB
/
main_test.go
File metadata and controls
80 lines (66 loc) · 1.8 KB
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
package main
import (
"testing"
"time"
"zee/hotkey"
)
func TestListenHotkey_TrayStopNoStaleSignal(t *testing.T) {
hk := hotkey.NewFake()
sessions := make(chan recSession, 3)
longPress := 100 * time.Millisecond
go listenHotkey(hk, longPress, sessions)
// 1. Short tap → enters toggle mode
isRecording.Store(false)
hk.SimKeydown()
sess1 := <-sessions
isRecording.Store(true)
time.Sleep(10 * time.Millisecond)
hk.SimKeyup()
// 2. Tray stop ends the recording externally
requestStop()
isRecording.Store(false)
select {
case <-sess1.Stop:
case <-time.After(time.Second):
t.Fatal("tray stop did not end session")
}
// 3. Still in toggleRecording — this tap transitions back to idle
hk.SimKeydown()
hk.SimKeyup()
time.Sleep(20 * time.Millisecond) // let state machine settle
// 4. New tap should start a session that stays alive
hk.SimKeydown()
sess2 := <-sessions
isRecording.Store(true)
time.Sleep(10 * time.Millisecond)
hk.SimKeyup()
select {
case <-sess2.Stop:
t.Fatal("new session immediately stopped by stale stopCh signal")
case <-time.After(300 * time.Millisecond):
// session stayed alive — fix works
}
}
func TestListenHotkey_StopsTrayRecording(t *testing.T) {
hk := hotkey.NewFake()
sessions := make(chan recSession, 3)
longPress := 100 * time.Millisecond
go listenHotkey(hk, longPress, sessions)
// Simulate tray-initiated recording
stop := resetStop()
isRecording.Store(true)
// Hotkey press should stop it, not start a new one
hk.SimKeydown()
hk.SimKeyup()
select {
case <-stop:
case <-time.After(time.Second):
t.Fatal("hotkey did not stop tray-initiated recording")
}
// Should not have queued a new session
select {
case <-sessions:
t.Fatal("hotkey started a new session while recording was active")
case <-time.After(100 * time.Millisecond):
}
}