package web
import (
"regexp"
"strings"
"testing"
)
// A strip that runs edge to edge subtracts the page's gutter back out of
// its own margin. Written as a literal it is a second copy of a number
// declared somewhere else, and the two silently disagreed: main halves
// its gutter at phone width and the rail's -1rem did not, so the rail
// hung 8px past the screen on exactly the screens it was written for.
//
// The fix is that there is one number. This guard keeps it that way.
func TestFullBleedUsesTheGutterVariable(t *testing.T) {
if !strings.Contains(sheetLiteral, "--gutter:") {
t.Fatal("FAIL: the sheet declares no --gutter to bleed against")
}
lit := regexp.MustCompile(`margin(-left|-right)?: *0? *-(0\.5|1)rem`)
if m := lit.FindString(sheetLiteral); m != "" {
t.Errorf("FAIL: %q is a hand-copied gutter; write calc(-1 * var(--gutter))", m)
} else {
t.Log("ok: no hand-copied gutter in a full-bleed margin")
}
}
// overflow on a TABLE box is ignored by the layout, so a wide table can
// only be held in by a block wrapper. The notification matrix had none
// and its timing column was clipped off the side of every phone.
func TestNotificationMatrixScrollsInItsOwnWrapper(t *testing.T) {
var b strings.Builder
if err := notifyBase.ExecuteTemplate(&b, "notify-matrix", prefsView{}); err != nil {
t.Fatalf("FAIL: render: %v", err)
}
out := b.String()
i := strings.Index(out, `<table class="pref-matrix"`)
if i < 0 {
t.Fatal("FAIL: no pref-matrix rendered")
}
if !strings.HasSuffix(strings.TrimSpace(out[:i]), `<div class="pref-wrap">`) {
t.Errorf("FAIL: the matrix is not wrapped: %q", tail(out[:i], 60))
} else {
t.Log("ok: the matrix sits in a scroll container")
}
if !strings.Contains(sheetLiteral, ".pref-wrap{overflow-x:auto") {
t.Error("FAIL: .pref-wrap does not scroll")
} else {
t.Log("ok: .pref-wrap scrolls sideways")
}
}
func tail(s string, n int) string {
s = strings.TrimSpace(s)
if len(s) > n {
return s[len(s)-n:]
}
return s
}