This commit is contained in:
2026-05-13 20:40:14 +08:00
parent bd13c842a8
commit c8a75ef2d5
17 changed files with 920 additions and 93 deletions

View File

@@ -0,0 +1,57 @@
package tray
import "testing"
func TestControllerOpensWindowOnTrayDoubleClick(t *testing.T) {
opened := 0
controller := newController(Config{
OnOpen: func() {
opened++
},
})
handled := controller.handleTrayEvent(wmLeftButtonDoubleClick)
if !handled {
t.Fatal("expected tray double-click to be handled")
}
if opened != 1 {
t.Fatalf("expected open callback to run once, got %d", opened)
}
}
func TestControllerOpensWindowWhenTrayEventContainsIconID(t *testing.T) {
opened := 0
controller := newController(Config{
OnOpen: func() {
opened++
},
})
handled := controller.handleTrayEvent(wmLeftButtonDoubleClick | 1<<16)
if !handled {
t.Fatal("expected packed tray double-click event to be handled")
}
if opened != 1 {
t.Fatalf("expected open callback to run once, got %d", opened)
}
}
func TestControllerIgnoresTraySingleClick(t *testing.T) {
opened := 0
controller := newController(Config{
OnOpen: func() {
opened++
},
})
handled := controller.handleTrayEvent(wmLeftButtonUp)
if handled {
t.Fatal("expected single-click to be ignored")
}
if opened != 0 {
t.Fatalf("expected open callback not to run, got %d calls", opened)
}
}