Files
kefu_cloud/server/internal/handler/quick_reply_test.go
T
yml2213 c6532f2ee3 优化快捷回复 CSV 为中文四列模板,操作列改为单行
导入/导出统一为一级分类、二级分类、输入码、内容;列表操作按钮紧凑并排不换行。
2026-07-19 00:59:53 +08:00

65 lines
1.5 KiB
Go

package handler
import "testing"
func TestNormalizeShortcut(t *testing.T) {
cases := []struct {
in string
want string
wantErr bool
}{
{"", "", false},
{"nh", "nh", false},
{"/NH", "nh", false},
{"hello_1", "hello_1", false},
{"a-b", "a-b", false},
{"中文", "", true},
{"has space", "", true},
}
for _, tc := range cases {
got, err := normalizeShortcut(tc.in)
if tc.wantErr {
if err == nil {
t.Fatalf("normalizeShortcut(%q) 期望错误", tc.in)
}
continue
}
if err != nil {
t.Fatalf("normalizeShortcut(%q): %v", tc.in, err)
}
if got != tc.want {
t.Fatalf("normalizeShortcut(%q)=%q want %q", tc.in, got, tc.want)
}
}
}
func TestParseQuickReplyScopeLabel(t *testing.T) {
cases := []struct {
in string
want string
wantOK bool
}{
{"团队", "team", true},
{"个人", "personal", true},
{"", "", true},
{"team", "", false},
{"personal", "", false},
{"其它", "", false},
}
for _, tc := range cases {
got, ok := parseQuickReplyScopeLabel(tc.in)
if ok != tc.wantOK || got != tc.want {
t.Fatalf("parseQuickReplyScopeLabel(%q)=(%q,%v) want (%q,%v)", tc.in, got, ok, tc.want, tc.wantOK)
}
}
}
func TestIsQuickReplyCSVHeader(t *testing.T) {
if !isQuickReplyCSVHeader([]string{"一级分类", "二级分类", "输入码", "内容"}) {
t.Fatal("expected header match")
}
if isQuickReplyCSVHeader([]string{"title", "content", "shortcut", "group_name"}) {
t.Fatal("legacy english header should not match")
}
}