Files
zerorigin-toolbox/internal/action/volume_method_test.go
T
zerorigin2019 0a1c1e82ea chore: 初始化仓库(零源工具箱 0.1.0 基线)
- Go 主进程 cmd/zerorigin(托盘常驻 + 触发器/规则/动作引擎)
- Wails v3 设置进程 cmd/settings(独立 module)
- 监督进程 cmd/watchdog(-supervise 异常重启)
- 构建脚本 build.bat / NSIS 安装包 deploy/、便携版 portable/
- 架构与 MVP 计划文档 docs/、阶段 0-4 验收记录 deploy/acceptance-0-4.md
2026-08-05 00:42:45 +08:00

74 lines
1.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package action
import "testing"
// TestVolumeMethodSelection 验证 method 参数归一化与校验:
// 默认("")→ media;hotkey 为 media 别名;com 保留为精确选项。
func TestVolumeMethodSelection(t *testing.T) {
cases := []struct {
in string
want string
}{
{"", "media"},
{"media", "media"},
{"hotkey", "media"},
{"com", "com"},
{"bogus", "media"}, // Validate 拦截前的兜底
}
for _, c := range cases {
if got := volumeMethod(c.in); got != c.want {
t.Errorf("volumeMethod(%q) = %q, want %q", c.in, got, c.want)
}
}
for _, id := range []string{"volume_up", "volume_down", "toggle_mute"} {
a, err := New(id)
if err != nil {
t.Fatalf("New(%q): %v", id, err)
}
for _, m := range []string{"", "media", "com", "hotkey"} {
if err := a.Validate(map[string]any{"method": m}); err != nil {
t.Errorf("%s method %q should pass: %v", id, m, err)
}
}
if err := a.Validate(map[string]any{"method": "cli"}); err == nil {
t.Errorf("%s invalid method should fail", id)
}
}
}
// TestVolumeStepCount 验证媒体键路径按键次数 = |delta|。
func TestVolumeStepCount(t *testing.T) {
cases := []struct {
delta int32
want int
}{
{1, 1},
{3, 3},
{-1, 1},
{-5, 5},
{0, 0},
}
for _, c := range cases {
if got := volumeStepCount(c.delta); got != c.want {
t.Errorf("volumeStepCount(%d) = %d, want %d", c.delta, got, c.want)
}
}
}
// TestVolumeSchemaDefaultMedia 回归:schema 默认值必须为 media(方案A的落点)。
func TestVolumeSchemaDefaultMedia(t *testing.T) {
up, _ := New("volume_up")
for _, p := range up.Schema().Params {
if p.Name == "method" && p.Default != "media" {
t.Errorf("volume_up method default = %v, want media", p.Default)
}
}
mu, _ := New("toggle_mute")
for _, p := range mu.Schema().Params {
if p.Name == "method" && p.Default != "media" {
t.Errorf("toggle_mute method default = %v, want media", p.Default)
}
}
}