2026-06-26 08:37:04 +00:00
|
|
|
package knowledge
|
|
|
|
|
|
2026-07-06 06:13:14 +00:00
|
|
|
import (
|
|
|
|
|
"strings"
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
2026-06-26 08:37:04 +00:00
|
|
|
|
|
|
|
|
func TestPatrolTagFromQuestionPreservesSearchPhrase(t *testing.T) {
|
|
|
|
|
got := PatrolTagFromQuestion("化療後皮膚敏感要換什麼沐浴乳")
|
|
|
|
|
if got != "化療後皮膚敏感要換什麼沐浴乳" {
|
|
|
|
|
t.Fatalf("expected preserved question, got %q", got)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-06 06:13:14 +00:00
|
|
|
func TestAnchorPatrolTagToProductInjectsCategory(t *testing.T) {
|
|
|
|
|
in := PatrolTagInput{
|
|
|
|
|
ProductName: "天然洗衣精",
|
|
|
|
|
MatchTags: []string{"洗衣精", "衣物清潔"},
|
|
|
|
|
}
|
|
|
|
|
got := AnchorPatrolTagToProduct("敏感肌 推薦", in)
|
|
|
|
|
if got == "敏感肌 推薦" {
|
|
|
|
|
t.Fatal("expected product category to be injected into generic tag")
|
|
|
|
|
}
|
|
|
|
|
if !strings.Contains(got, "洗衣") {
|
|
|
|
|
t.Fatalf("expected laundry anchor in %q", got)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestAnchorPatrolTagToProductPrefersValueAnchor(t *testing.T) {
|
|
|
|
|
in := PatrolTagInput{
|
|
|
|
|
ProductName: "抗敏無香洗衣精",
|
|
|
|
|
ProductFeatures: "完全無香、抗敏、適合化療族群",
|
|
|
|
|
MatchTags: []string{"無香", "洗衣精"},
|
|
|
|
|
}
|
|
|
|
|
got := AnchorPatrolTagToProduct("皮膚癢 推薦", in)
|
|
|
|
|
if !strings.Contains(got, "無香") {
|
|
|
|
|
t.Fatalf("expected value anchor in %q", got)
|
|
|
|
|
}
|
|
|
|
|
if !strings.Contains(got, "洗衣精") {
|
|
|
|
|
t.Fatalf("expected product form in %q", got)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-26 08:37:04 +00:00
|
|
|
func TestPatrolTagFromQuestionCompressesGenericLabel(t *testing.T) {
|
|
|
|
|
got := PatrolTagFromQuestion("敏感肌保養")
|
|
|
|
|
if got == "敏感肌保養" {
|
|
|
|
|
t.Fatal("expected compression for generic short label")
|
|
|
|
|
}
|
|
|
|
|
if got == "" {
|
|
|
|
|
t.Fatal("expected non-empty tag")
|
|
|
|
|
}
|
|
|
|
|
}
|