@@ -0,0 +1,68 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"html/template"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNavigationPageUsesDedicatedVerificationAndAnalytics(t *testing.T) {
|
||||
navHTML := renderSEOCommonForTrackingTest(t, true)
|
||||
for _, want := range []string{
|
||||
"UEtS2h9mIjbFSM_VHEciNQ5iWuFPq9d-Q2WO0SFyPAw",
|
||||
"eafd02fb6517fc76",
|
||||
"112390883",
|
||||
"G-SY26Y2MSHS",
|
||||
} {
|
||||
if !strings.Contains(navHTML, want) {
|
||||
t.Fatalf("navigation SEO output does not contain %q", want)
|
||||
}
|
||||
}
|
||||
for _, unwanted := range []string{"112967594", "G-B5KGM8S5J1", "6bb06ed5659790d0"} {
|
||||
if strings.Contains(navHTML, unwanted) {
|
||||
t.Fatalf("navigation SEO output unexpectedly contains main-site id %q", unwanted)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMainSiteKeepsMainVerificationAndAnalytics(t *testing.T) {
|
||||
mainHTML := renderSEOCommonForTrackingTest(t, false)
|
||||
for _, want := range []string{
|
||||
"r7geXn5kBugzOSLZzyw4v3NBDMQwAmzFCVkqp92odh0",
|
||||
"6bb06ed5659790d0",
|
||||
"112967594",
|
||||
"G-B5KGM8S5J1",
|
||||
} {
|
||||
if !strings.Contains(mainHTML, want) {
|
||||
t.Fatalf("main-site SEO output does not contain %q", want)
|
||||
}
|
||||
}
|
||||
for _, unwanted := range []string{"112390883", "G-SY26Y2MSHS", "eafd02fb6517fc76"} {
|
||||
if strings.Contains(mainHTML, unwanted) {
|
||||
t.Fatalf("main-site SEO output unexpectedly contains navigation id %q", unwanted)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func renderSEOCommonForTrackingTest(t *testing.T, isNavPage bool) string {
|
||||
t.Helper()
|
||||
tpl, err := template.New("tracking-test").Funcs(template.FuncMap{
|
||||
"jsonStr": func(any) template.JS { return template.JS(`""`) },
|
||||
}).ParseFiles("../templates/base/seoCommon.html", "../templates/base/analytics.html")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
data := map[string]any{
|
||||
"isNavPage": isNavPage,
|
||||
"seoVerify": map[string]any{"Baidu": ""},
|
||||
"appConfig": map[string]any{
|
||||
"SeoInfo": map[string]any{"WebSiteName": ""},
|
||||
},
|
||||
}
|
||||
var out bytes.Buffer
|
||||
if err := tpl.ExecuteTemplate(&out, "seoCommon", data); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return out.String()
|
||||
}
|
||||
Reference in New Issue
Block a user