Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
84 lines
3.1 KiB
Go
84 lines
3.1 KiB
Go
package translationser
|
|
|
|
import "testing"
|
|
|
|
func TestResolveNavigationActiveKey(t *testing.T) {
|
|
tests := map[string]string{
|
|
"/": "home",
|
|
"/list/ai-short-play": "aiShortPlay",
|
|
"/list/ai-series/2/page/3": "aiSeries",
|
|
"/series/original/page/3": "aiSeries",
|
|
"/tag/urban/page/2": "tagList",
|
|
"/tag-list/urban/page/2": "tagList",
|
|
"/topic/editor-picks/page/2": "topic",
|
|
"/rank/2/page/3": "rank",
|
|
"/category/latest-video/": "category",
|
|
"/application": "application",
|
|
"/home-road": "homeRoad",
|
|
"/detail/example-playlet": "list",
|
|
"/play/example-playlet/chapter-1": "list",
|
|
}
|
|
for path, want := range tests {
|
|
if got := ResolveNavigationActiveKey("", path); got != want {
|
|
t.Fatalf("ResolveNavigationActiveKey(%q) = %q, want %q", path, got, want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestMarkHeaderNavActiveRequiresExactPath(t *testing.T) {
|
|
items := []HeaderNavItemVM{
|
|
{Name: "首页", Href: "/", Key: "home"},
|
|
{Name: "AI成人短剧", Href: "/category/today", Key: "list"},
|
|
{Name: "专题", Href: "/topic", Key: "topic"},
|
|
{Name: "排行榜", Href: "/rank", Key: "rank"},
|
|
}
|
|
|
|
marked := MarkHeaderNavActive(items, "/category/today/")
|
|
for i, item := range marked {
|
|
want := i == 1
|
|
if item.IsActive != want {
|
|
t.Fatalf("item %q active = %v, want %v", item.Name, item.IsActive, want)
|
|
}
|
|
}
|
|
|
|
marked = MarkHeaderNavActive(items, "/search/keyword")
|
|
for _, item := range marked {
|
|
if item.IsActive {
|
|
t.Fatalf("non-navigation path unexpectedly activated %q", item.Name)
|
|
}
|
|
}
|
|
|
|
for _, item := range items {
|
|
if item.IsActive {
|
|
t.Fatalf("source navigation cache was mutated: %#v", items)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestNormalizeNavURLKeepsConfiguredURL(t *testing.T) {
|
|
href, external, download := normalizeNavURL("/tag-list/fantasy/page/2", "专题")
|
|
if href != "/tag-list/fantasy/page/2" || external || download {
|
|
t.Fatalf("normalizeNavURL configured tag path = (%q, %v, %v)", href, external, download)
|
|
}
|
|
href, external, download = normalizeNavURL("/", "专题")
|
|
if href != "/" || external || download {
|
|
t.Fatalf("normalizeNavURL configured root = (%q, %v, %v)", href, external, download)
|
|
}
|
|
href, external, download = normalizeNavURL("/tag", "专题")
|
|
if href != "/tag" || external || download {
|
|
t.Fatalf("normalizeNavURL configured topic nav = (%q, %v, %v)", href, external, download)
|
|
}
|
|
href, external, download = normalizeNavURL("series", "AI成人剧集")
|
|
if href != "series" || external || download {
|
|
t.Fatalf("normalizeNavURL configured relative path = (%q, %v, %v)", href, external, download)
|
|
}
|
|
href, external, download = normalizeNavURL("https://old.example.com/home.pdf", "回家的路")
|
|
if href != "https://old.example.com/home.pdf" || !external || download {
|
|
t.Fatalf("normalizeNavURL configured external URL = (%q, %v, %v)", href, external, download)
|
|
}
|
|
href, external, download = normalizeNavURL("/download-app", "下载APP")
|
|
if href != "/download-app" || external || download {
|
|
t.Fatalf("normalizeNavURL configured download URL = (%q, %v, %v)", href, external, download)
|
|
}
|
|
}
|