2026-04-08 07:18:00 +00:00
|
|
|
package web
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"strings"
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestLoginTemplateRebuildsTurnstileAfterTabSwitch(t *testing.T) {
|
|
|
|
|
content, err := htmlFS.ReadFile("html/login.html")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("read login template: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
source := string(content)
|
|
|
|
|
|
|
|
|
|
checks := []string{
|
|
|
|
|
"turnstileContainer = null;",
|
|
|
|
|
"turnstile.remove(turnstileWidgetId);",
|
|
|
|
|
"turnstileContainer !== container",
|
|
|
|
|
"turnstileToken = '';",
|
2026-04-08 07:34:50 +00:00
|
|
|
"this.activeTab === 'register'",
|
|
|
|
|
"!this.isTurnstileContainerVisible(container)",
|
|
|
|
|
"if (key !== 'register') {",
|
|
|
|
|
"this.destroyTurnstile();",
|
2026-04-08 07:18:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, check := range checks {
|
|
|
|
|
if !strings.Contains(source, check) {
|
|
|
|
|
t.Fatalf("expected login template to contain %q so turnstile can be rebuilt after tab switches", check)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|