package server import ( "os" "regexp" "strings" "testing" ) // ruleBlock geeft de inhoud van de eerste CSS-regel die met sel begint. func ruleBlock(css, sel string) string { i := strings.Index(css, sel+" {") if i < 0 { i = strings.Index(css, sel+"{") } if i < 0 { return "" } rest := css[i:] start := strings.Index(rest, "{") end := strings.Index(rest, "}") if start < 0 || end < 0 || end < start { return "" } return rest[start+1 : end] } func TestTooltipCSSShowsFullTextWithoutScrollbar(t *testing.T) { css, err := os.ReadFile("static/style.css") if err != nil { t.Fatal(err) } src := string(css) wantMax := "max-width: min(32rem, calc(100vw - 2rem))" for _, sel := range []string{".float-tip", ".float-tip:popover-open", ".tip-b"} { body := ruleBlock(src, sel) if body == "" { t.Fatalf("regel %s ontbreekt", sel) } if strings.Contains(body, "white-space: nowrap") { t.Errorf("%s heeft white-space: nowrap; tekst moet wrappen", sel) } if strings.Contains(body, "overflow: auto") || strings.Contains(body, "overflow-x: auto") || strings.Contains(body, "overflow-x: scroll") || strings.Contains(body, "overflow: scroll") || strings.Contains(body, "overflow-y: auto") || strings.Contains(body, "overflow-y: scroll") { t.Errorf("%s mag geen scrollbar krijgen: %s", sel, body) } for _, bad := range []string{"line-clamp:", "text-overflow: ellipsis", "-webkit-box", "max-height:"} { if strings.Contains(body, bad) { t.Errorf("%s kapt tekst af (%q): %s", sel, bad, body) } } if !strings.Contains(body, "white-space: normal") && sel != ".float-tip:popover-open" { t.Errorf("%s mist white-space: normal", sel) } if !strings.Contains(body, wantMax) { t.Errorf("%s mist %s", sel, wantMax) } if !strings.Contains(body, "overflow: hidden") { t.Errorf("%s mist overflow: hidden (voorkomt UA-scrollbars, zonder hoogte blijft alles zichtbaar)", sel) } } shown := ruleBlock(src, ".tip:hover .tip-b, .tip-i:focus + .tip-b, .tip.open .tip-b, .tiphost:focus-within .tip-b") if !strings.Contains(shown, "display: block") || strings.Contains(shown, "-webkit-box") { t.Errorf("zichtbare .tip-b moet display:block zijn, geen line-clamp-box: %s", shown) } re := regexp.MustCompile(`(?s)\.float-tip[^{]*\{[^}]*white-space:\s*nowrap`) if re.MatchString(src) { t.Fatal("ergens zet een .float-tip-regel white-space weer op nowrap") } clamp := regexp.MustCompile(`(?s)\.(float-tip|tip-b)[^{]*\{[^}]*(line-clamp|text-overflow:\s*ellipsis)`) if clamp.MatchString(src) { t.Fatal("float-tip of tip-b mag tekst niet afkappen met line-clamp of ellipsis") } } func TestFloatTipHasNoTitleAndKeepsViewport(t *testing.T) { js, err := os.ReadFile("static/float.js") if err != nil { t.Fatal(err) } src := string(js) if strings.Contains(src, `tip.setAttribute("title"`) { t.Fatal("float-tip heeft geen title: je kunt er niet over hoveren") } if !strings.Contains(src, `tip.textContent = text`) { t.Fatal("float-tip toont de tekst") } for _, want := range []string{`vw - GAP`, `vh - GAP`, `above-center`} { if !strings.Contains(src, want) { t.Errorf("place() moet in het viewport blijven (%q ontbreekt)", want) } } } func TestInfoTipStaysInViewport(t *testing.T) { js, err := os.ReadFile("static/tip.js") if err != nil { t.Fatal(err) } src := string(js) for _, want := range []string{"position = \"fixed\"", "placeBody", "vw - GAP", "vh - GAP", "classList.toggle(\"above\""} { if !strings.Contains(src, want) { t.Errorf("tip.js moet .tip-b in het viewport plaatsen (%q ontbreekt)", want) } } }