package webutil import ( "strings" "testing" ) func TestBuildPageScrollByJS_TargetsViewportCenterInsteadOfActiveElement(t *testing.T) { js := BuildPageScrollByJS(0, 80) if !strings.Contains(js, "doc.elementFromPoint(window.innerWidth/2,window.innerHeight/2)") { t.Fatalf("page scroll must resolve its initial target from the viewport center, got: %s", js) } if strings.Contains(js, "activeElement") { t.Fatalf("page scroll must not use the legacy active-element target, got: %s", js) } } func TestBuildPageScrollByJS_ContainsRequiredOperations(t *testing.T) { tests := []struct { name string dx int dy int }{ {"down", 0, 80}, {"up", 0, -80}, {"left", -80, 0}, {"right", 80, 0}, {"upFast", 0, -320}, {"downFast", 0, 320}, } required := []struct { message string snippets []string }{ {"JS must resolve the viewport-center element", []string{"elementFromPoint", "window.innerWidth/2", "window.innerHeight/2"}}, {"JS must walk parentElement in a loop", []string{"parentElement"}}, {"JS must reference document.scrollingElement", []string{"scrollingElement"}}, {"JS must fall back to window.scrollBy", []string{"window.scrollBy"}}, {"JS must use getComputedStyle", []string{"getComputedStyle"}}, {"JS must check overflowY", []string{"overflowY"}}, {"JS must check overflowX", []string{"overflowX"}}, {"JS must use direct element scroll offsets", []string{"scrollLeft=beforeLeft+dx", "scrollTop=beforeTop+dy"}}, {"JS must check vertical direction-specific remaining scroll", []string{"dy<0&&el.scrollTop>0", "dy>0&&el.scrollTop0", "dx>0&&el.scrollLeft