1
0
Files
nex/backend/cmd/desktop/dialog_darwin_test.go

47 lines
1.6 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.
//go:build darwin
package main
import (
"strings"
"testing"
)
func TestDarwinStartupChannelsBuildNotificationAndAlert(t *testing.T) {
runner := &fakeCommandRunner{paths: map[string]bool{"osascript": true}}
channels := platformStartupChannels(runner)
if len(channels) != 2 {
t.Fatalf("macOS 应有 notification 和 alert 两级通道,实际: %d", len(channels))
}
req := promptRequest{title: "Nex 启动失败", subtitle: "config", message: "路径 C:\\tmp 包含 \"quote\""}
for _, channel := range channels {
if err := channel.available(); err != nil {
t.Fatalf("通道 %s 应可用: %v", channel.name, err)
}
if err := channel.run(req); err != nil {
t.Fatalf("通道 %s 执行失败: %v", channel.name, err)
}
}
if len(runner.calls) != 2 {
t.Fatalf("应执行两次 osascript实际: %d", len(runner.calls))
}
if runner.calls[0].name != "osascript" || runner.calls[0].args[0] != "-e" {
t.Fatalf("notification 命令参数错误: %#v", runner.calls[0])
}
if script := runner.calls[0].args[1]; !strings.Contains(script, "display notification") || !strings.Contains(script, `\\tmp`) || !strings.Contains(script, `\"quote\"`) {
t.Fatalf("notification AppleScript 未正确构造或转义: %s", script)
}
if script := runner.calls[1].args[1]; !strings.Contains(script, "display alert") || !strings.Contains(script, "as critical") {
t.Fatalf("alert AppleScript 未使用 critical 告警: %s", script)
}
}
func TestEscapeAppleScript(t *testing.T) {
got := escapeAppleScript(`C:\tmp "quote"`)
if !strings.Contains(got, `C:\\tmp`) || !strings.Contains(got, `\"quote\"`) {
t.Fatalf("AppleScript 转义结果错误: %s", got)
}
}