BlueGit

timfa bluegit

Files

bluegit / internal / server / tooltip_css_test.go

tooltip_css_test.go

tooltip_css_test.go 2.8 KiB Download Raw
1package server
2
3import (
4 "os"
5 "regexp"
6 "strings"
7 "testing"
8)
9
10// ruleBlock geeft de inhoud van de eerste CSS-regel die met sel begint.
11func ruleBlock(css, sel string) string {
12 i := strings.Index(css, sel+" {")
13 if i < 0 {
14 i = strings.Index(css, sel+"{")
15 }
16 if i < 0 {
17 return ""
18 }
19 rest := css[i:]
20 start := strings.Index(rest, "{")
21 end := strings.Index(rest, "}")
22 if start < 0 || end < 0 || end < start {
23 return ""
24 }
25 return rest[start+1 : end]
26}
27
28func TestTooltipCSSWrapsTwoLinesWithoutScrollbar(t *testing.T) {
29 css, err := os.ReadFile("static/style.css")
30 if err != nil {
31 t.Fatal(err)
32 }
33 src := string(css)
34 for _, sel := range []string{".float-tip", ".float-tip:popover-open", ".tip-b"} {
35 body := ruleBlock(src, sel)
36 if body == "" {
37 t.Fatalf("regel %s ontbreekt", sel)
38 }
39 if strings.Contains(body, "white-space: nowrap") {
40 t.Errorf("%s heeft white-space: nowrap; tekst moet wrappen", sel)
41 }
42 if strings.Contains(body, "overflow: auto") || strings.Contains(body, "overflow-x: auto") || strings.Contains(body, "overflow-x: scroll") || strings.Contains(body, "overflow: scroll") {
43 t.Errorf("%s mag geen scrollbar krijgen: %s", sel, body)
44 }
45 }
46 ft := ruleBlock(src, ".float-tip")
47 for _, want := range []string{
48 "white-space: normal",
49 "overflow: hidden",
50 "-webkit-line-clamp: 2",
51 "line-clamp: 2",
52 "overflow-wrap: anywhere",
53 "box-sizing: border-box",
54 "max-width: min(26rem, calc(100vw - 2rem))",
55 } {
56 if !strings.Contains(ft, want) {
57 t.Errorf(".float-tip mist %q", want)
58 }
59 }
60 open := ruleBlock(src, ".float-tip:popover-open")
61 if !strings.Contains(open, "overflow: hidden") || !strings.Contains(open, "display: -webkit-box") {
62 t.Errorf(".float-tip:popover-open moet wrappen zonder scrollbar: %s", open)
63 }
64 tb := ruleBlock(src, ".tip-b")
65 for _, want := range []string{"white-space: normal", "overflow: hidden", "-webkit-line-clamp: 2", "line-clamp: 2", "max-width: min(26rem, calc(100vw - 2rem))"} {
66 if !strings.Contains(tb, want) {
67 t.Errorf(".tip-b mist %q", want)
68 }
69 }
70 shown := ruleBlock(src, ".tip:hover .tip-b, .tip-i:focus + .tip-b, .tip.open .tip-b, .tiphost:focus-within .tip-b")
71 if !strings.Contains(shown, "display: -webkit-box") {
72 t.Errorf("zichtbare .tip-b moet -webkit-box zijn voor line-clamp: %s", shown)
73 }
74 // Geen latere .float-tip-regel die nowrap terugzet.
75 re := regexp.MustCompile(`(?s)\.float-tip[^{]*\{[^}]*white-space:\s*nowrap`)
76 if re.MatchString(src) {
77 t.Fatal("ergens zet een .float-tip-regel white-space weer op nowrap")
78 }
79}
80
81func TestFloatTipSetsFullTitle(t *testing.T) {
82 js, err := os.ReadFile("static/float.js")
83 if err != nil {
84 t.Fatal(err)
85 }
86 src := string(js)
87 if !strings.Contains(src, `tip.setAttribute("title", text)`) {
88 t.Fatal("float-tip moet de volledige tekst in title zetten")
89 }
90 if !strings.Contains(src, `tip.textContent = text`) {
91 t.Fatal("float-tip toont de tekst")
92 }
93}