Files
nebara-tui/internal/ui/layout/responsive_test.go
T
2026-10-13 19:36:58 +07:00

74 lines
2.0 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package layout_test
import (
"testing"
"github.com/nebara/nebara-os/internal/ui/layout"
)
func TestCalculate_Normal(t *testing.T) {
c := layout.Calculate(120, 40)
if c.IsMinimum {
t.Error("120×40 should not be minimum")
}
if c.ContentWidth <= 0 {
t.Error("ContentWidth should be positive")
}
if c.MarginH <= 0 {
t.Error("MarginH should be positive")
}
if c.ContentWidth != c.TermWidth-c.MarginH*2 {
t.Errorf("ContentWidth mismatch: got %d, expected %d", c.ContentWidth, c.TermWidth-c.MarginH*2)
}
}
func TestCalculate_TooSmall(t *testing.T) {
c := layout.Calculate(40, 10)
if !c.IsMinimum {
t.Error("40×10 should be flagged as minimum/too-small")
}
}
func TestCalculate_BoundaryMinWidth(t *testing.T) {
c := layout.Calculate(layout.MinWidth, layout.MinHeight)
if c.IsMinimum {
t.Errorf("exact minimum %dx%d should not be flagged as too small", layout.MinWidth, layout.MinHeight)
}
}
func TestCalculate_MarginClamps(t *testing.T) {
// Very wide terminal: margin should not exceed 12.
cWide := layout.Calculate(400, 80)
if cWide.MarginH > 12 {
t.Errorf("MarginH should not exceed 12 on very wide terminal, got %d", cWide.MarginH)
}
// Narrow but valid terminal: margin should not go below 4.
cNarrow := layout.Calculate(60, 20)
if cNarrow.MarginH < 4 {
t.Errorf("MarginH should be at least 4 on narrow terminal, got %d", cNarrow.MarginH)
}
}
func TestCalculate_MessageVisibility(t *testing.T) {
cCompact := layout.Calculate(80, 23)
if cCompact.MessageVisible {
t.Error("message should be hidden on terminals shorter than 24 rows")
}
cNormal := layout.Calculate(80, 24)
if !cNormal.MessageVisible {
t.Error("message should be visible at 24 rows")
}
}
func TestCalculate_MenuInnerPad(t *testing.T) {
cNarrow := layout.Calculate(80, 24)
if cNarrow.MenuInnerPad != 1 {
t.Errorf("expected menu inner pad 1 for narrow terminal, got %d", cNarrow.MenuInnerPad)
}
cWide := layout.Calculate(120, 40)
if cWide.MenuInnerPad != 2 {
t.Errorf("expected menu inner pad 2 for wide terminal, got %d", cWide.MenuInnerPad)
}
}