Files
HomeDash/history-server/main_test.go
JianFeeeee 24b2e6ab75 fix(history): 历史条目不再显示裸 URL
浏览器没给标题(或标题本身就是 URL)时,改为显示去掉 www. 的域名,
例如 https://www.docker.com/ -> docker.com。
2026-09-11 16:25:26 +08:00

23 lines
887 B
Go

package main
import "testing"
func TestFriendlyHistoryTitle(t *testing.T) {
cases := []struct {
name, title, rawURL, want string
}{
{name: "real title", title: "Docker Documentation", rawURL: "https://www.docker.com/docs/", want: "Docker Documentation"},
{name: "missing title", rawURL: "https://www.docker.com/", want: "docker.com"},
{name: "url title", title: "https://www.docker.com/", rawURL: "https://www.docker.com/", want: "docker.com"},
{name: "http url title", title: "http://example.org/a", rawURL: "http://example.org/a", want: "example.org"},
{name: "invalid fallback", rawURL: "://", want: "历史站点"},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
if got := friendlyHistoryTitle(tc.title, tc.rawURL); got != tc.want {
t.Fatalf("friendlyHistoryTitle(%q, %q) = %q; want %q", tc.title, tc.rawURL, got, tc.want)
}
})
}
}