BlueGit

timfa bluegit

Files

bluegit / internal / server / tooltip_css_test.go

tooltip_css_test.go

tooltip_css_test.go 3.5 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 TestTooltipCSSShowsFullTextWithoutScrollbar(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 wantMax := "max-width: min(32rem, calc(100vw - 2rem))"
35 for _, sel := range []string{".float-tip", ".float-tip:popover-open", ".tip-b"} {
36 body := ruleBlock(src, sel)
37 if body == "" {
38 t.Fatalf("regel %s ontbreekt", sel)
39 }
40 if strings.Contains(body, "white-space: nowrap") {
41 t.Errorf("%s heeft white-space: nowrap; tekst moet wrappen", sel)
42 }
43 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") {
44 t.Errorf("%s mag geen scrollbar krijgen: %s", sel, body)
45 }
46 for _, bad := range []string{"line-clamp:", "text-overflow: ellipsis", "-webkit-box", "max-height:"} {
47 if strings.Contains(body, bad) {
48 t.Errorf("%s kapt tekst af (%q): %s", sel, bad, body)
49 }
50 }
51 if !strings.Contains(body, "white-space: normal") && sel != ".float-tip:popover-open" {
52 t.Errorf("%s mist white-space: normal", sel)
53 }
54 if !strings.Contains(body, wantMax) {
55 t.Errorf("%s mist %s", sel, wantMax)
56 }
57 if !strings.Contains(body, "overflow: hidden") {
58 t.Errorf("%s mist overflow: hidden (voorkomt UA-scrollbars, zonder hoogte blijft alles zichtbaar)", sel)
59 }
60 }
61 shown := ruleBlock(src, ".tip:hover .tip-b, .tip-i:focus + .tip-b, .tip.open .tip-b, .tiphost:focus-within .tip-b")
62 if !strings.Contains(shown, "display: block") || strings.Contains(shown, "-webkit-box") {
63 t.Errorf("zichtbare .tip-b moet display:block zijn, geen line-clamp-box: %s", shown)
64 }
65 re := regexp.MustCompile(`(?s)\.float-tip[^{]*\{[^}]*white-space:\s*nowrap`)
66 if re.MatchString(src) {
67 t.Fatal("ergens zet een .float-tip-regel white-space weer op nowrap")
68 }
69 clamp := regexp.MustCompile(`(?s)\.(float-tip|tip-b)[^{]*\{[^}]*(line-clamp|text-overflow:\s*ellipsis)`)
70 if clamp.MatchString(src) {
71 t.Fatal("float-tip of tip-b mag tekst niet afkappen met line-clamp of ellipsis")
72 }
73}
74
75func TestFloatTipHasNoTitleAndKeepsViewport(t *testing.T) {
76 js, err := os.ReadFile("static/float.js")
77 if err != nil {
78 t.Fatal(err)
79 }
80 src := string(js)
81 if strings.Contains(src, `tip.setAttribute("title"`) {
82 t.Fatal("float-tip heeft geen title: je kunt er niet over hoveren")
83 }
84 if !strings.Contains(src, `tip.textContent = text`) {
85 t.Fatal("float-tip toont de tekst")
86 }
87 for _, want := range []string{`vw - GAP`, `vh - GAP`, `above-center`} {
88 if !strings.Contains(src, want) {
89 t.Errorf("place() moet in het viewport blijven (%q ontbreekt)", want)
90 }
91 }
92}
93
94func TestInfoTipStaysInViewport(t *testing.T) {
95 js, err := os.ReadFile("static/tip.js")
96 if err != nil {
97 t.Fatal(err)
98 }
99 src := string(js)
100 for _, want := range []string{"position = \"fixed\"", "placeBody", "vw - GAP", "vh - GAP", "classList.toggle(\"above\""} {
101 if !strings.Contains(src, want) {
102 t.Errorf("tip.js moet .tip-b in het viewport plaatsen (%q ontbreekt)", want)
103 }
104 }
105}