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 TestTooltipCSSWrapsTwoLinesWithoutScrollbar(t *testing.T) { css, err := os.ReadFile("static/style.css") if err != nil { t.Fatal(err) } src := string(css) 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") { t.Errorf("%s mag geen scrollbar krijgen: %s", sel, body) } } ft := ruleBlock(src, ".float-tip") for _, want := range []string{ "white-space: normal", "overflow: hidden", "-webkit-line-clamp: 2", "line-clamp: 2", "overflow-wrap: anywhere", "box-sizing: border-box", "max-width: min(26rem, calc(100vw - 2rem))", } { if !strings.Contains(ft, want) { t.Errorf(".float-tip mist %q", want) } } open := ruleBlock(src, ".float-tip:popover-open") if !strings.Contains(open, "overflow: hidden") || !strings.Contains(open, "display: -webkit-box") { t.Errorf(".float-tip:popover-open moet wrappen zonder scrollbar: %s", open) } tb := ruleBlock(src, ".tip-b") for _, want := range []string{"white-space: normal", "overflow: hidden", "-webkit-line-clamp: 2", "line-clamp: 2", "max-width: min(26rem, calc(100vw - 2rem))"} { if !strings.Contains(tb, want) { t.Errorf(".tip-b mist %q", want) } } 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: -webkit-box") { t.Errorf("zichtbare .tip-b moet -webkit-box zijn voor line-clamp: %s", shown) } // Geen latere .float-tip-regel die nowrap terugzet. 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") } } func TestFloatTipSetsFullTitle(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", text)`) { t.Fatal("float-tip moet de volledige tekst in title zetten") } if !strings.Contains(src, `tip.textContent = text`) { t.Fatal("float-tip toont de tekst") } }