package web
import (
"strings"
"testing"
)
// The diagram's sizing rules reach the diagram only. Written against
// .pikchr-fig svg, they also caught the bar's icons, and each Copy and
// studio icon was drawn as wide as the diagram.
func TestDiagramSizingSkipsTheBarsIcons(t *testing.T) {
for _, bad := range []string{".pikchr-fig svg {", ".pikchr-fig:target svg {"} {
if strings.Contains(sheet, bad) {
t.Errorf("FAIL: %q sizes every svg in the frame, the bar's icons included", bad)
}
}
if !strings.Contains(sheet, ".pikchr-view svg {") {
t.Error("FAIL: the diagram lost its sizing rule")
}
t.Log("ok: sizing is scoped to the diagram")
}
// A diagram wider than its column scales to it; a floor on how far it
// may shrink made it scroll sideways inside its frame on a phone.
func TestDiagramShrinksToItsColumn(t *testing.T) {
i := strings.Index(sheet, ".pikchr-view svg {")
if i < 0 {
t.Fatal("FAIL: the diagram lost its sizing rule")
}
rule := sheet[i : i+strings.Index(sheet[i:], "}")]
if strings.Contains(rule, "min-width") {
t.Errorf("FAIL: the diagram has a width floor: %s", rule)
}
for _, want := range []string{"max-width:100%", "height:auto"} {
if !strings.Contains(strings.ReplaceAll(rule, " ", ""), want) {
t.Errorf("FAIL: the diagram's rule lacks %s", want)
}
}
}