clone

fifteen puzzle games for the terminal, with daily puzzles, weekly ladders and xp, built on bubble tea

add tests

Dami committed fd26c81
commit
fd26c81dd315d4afababdcbfa3398d5732fa47b1
parent
cf9edafd50ce1054bc316a6dab8326f014c6e1a1
author
Dami <dami.etoile@gmail.com>
1 file changed, +57 -0
Aapp/help_layout_test.go57++++++++++++++++++++++++++++++
A app/help_layout_test.go +57 -0
@@ -0,0 +1,57 @@
1+package app2+3+import (4+ "strings"5+ "testing"6+7+ "github.com/FelineStateMachine/puzzletea/stats"8+ "github.com/FelineStateMachine/puzzletea/ui"9+10+ "charm.land/lipgloss/v2"11+)12+13+func TestHelpViewportSizeKeepsPanelInsideInsetBounds(t *testing.T) {14+ const (15+ windowWidth = 12016+ windowHeight = 4017+ )18+19+ helpWidth, helpHeight := helpViewportSize(windowWidth, windowHeight)20+ line := strings.Repeat("x", helpWidth)21+ content := strings.TrimSuffix(strings.Repeat(line+"\n", helpHeight), "\n")22+ panel := ui.Panel("Guide", content, "esc back")23+24+ if got := lipgloss.Width(panel); got > windowWidth-(helpPanelInsetX*2) {25+ t.Fatalf("panel width = %d, want <= %d", got, windowWidth-(helpPanelInsetX*2))26+ }27+ if got := lipgloss.Height(panel); got > windowHeight-(helpPanelInsetY*2) {28+ t.Fatalf("panel height = %d, want <= %d", got, windowHeight-(helpPanelInsetY*2))29+ }30+}31+32+func TestHelpViewportSizeNeverFallsBelowOne(t *testing.T) {33+ helpWidth, helpHeight := helpViewportSize(1, 1)34+ if helpWidth != 1 {35+ t.Fatalf("help width = %d, want 1", helpWidth)36+ }37+ if helpHeight != 1 {38+ t.Fatalf("help height = %d, want 1", helpHeight)39+ }40+}41+42+func TestStatsViewportSizeMatchesHelpWidth(t *testing.T) {43+ helpWidth, _ := helpViewportSize(120, 40)44+ statsWidth, _ := statsViewportSize(120, 40, nil)45+ if statsWidth != helpWidth {46+ t.Fatalf("stats width = %d, want %d", statsWidth, helpWidth)47+ }48+}49+50+func TestStatsViewportSizeReservesBannerHeight(t *testing.T) {51+ _, helpHeight := helpViewportSize(120, 40)52+ cards := []stats.Card{{GameType: "Nurikabe"}}53+ _, statsHeight := statsViewportSize(120, 40, cards)54+ if statsHeight != helpHeight-5 {55+ t.Fatalf("stats height = %d, want %d", statsHeight, helpHeight-5)56+ }57+}