clone

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

bug/architecture-test-trim-path
puzzletea / app / help_layout_test.go
help_layout_test.go 3.3K
1package app23import (4 "strings"5 "testing"67 "github.com/FelineStateMachine/puzzletea/stats"8 "github.com/FelineStateMachine/puzzletea/ui"910 "charm.land/lipgloss/v2"11)1213func TestHelpViewportSizeKeepsPanelWithinWindowBounds(t *testing.T) {14 const (15 windowWidth = 12016 windowHeight = 4017 )1819 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")2324 if got := lipgloss.Width(panel); got > windowWidth {25 t.Fatalf("panel width = %d, want <= %d", got, windowWidth)26 }27 if got := lipgloss.Height(panel); got > windowHeight {28 t.Fatalf("panel height = %d, want <= %d", got, windowHeight)29 }30}3132func 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}4142func TestHelpSelectListSizeKeepsPanelWithinWindowBounds(t *testing.T) {43 const (44 windowWidth = 12045 windowHeight = 2046 )4748 helpList := ui.InitList(gameCategoryItems, "How to Play")49 listWidth, listHeight := helpSelectListSize(windowWidth, windowHeight, helpList)50 helpList.SetSize(listWidth, listHeight)5152 panel := ui.Panel(53 "How to Play",54 helpList.View(),55 "↑/↓ navigate • enter select • esc back",56 )5758 if got := lipgloss.Width(panel); got > windowWidth {59 t.Fatalf("panel width = %d, want <= %d", got, windowWidth)60 }61 if got := lipgloss.Height(panel); got > windowHeight {62 t.Fatalf("panel height = %d, want <= %d", got, windowHeight)63 }64}6566func TestStatsViewportSizeMatchesHelpWidth(t *testing.T) {67 helpWidth, _ := helpViewportSize(120, 40)68 statsWidth, _ := statsViewportSize(120, 40, nil)69 if statsWidth != helpWidth {70 t.Fatalf("stats width = %d, want %d", statsWidth, helpWidth)71 }72}7374func TestStatsViewportSizeReservesBannerHeight(t *testing.T) {75 _, helpHeight := helpViewportSize(120, 40)76 cards := []stats.Card{{GameType: "Nurikabe"}}77 _, statsHeight := statsViewportSize(120, 40, cards)78 if statsHeight != helpHeight-5 {79 t.Fatalf("stats height = %d, want %d", statsHeight, helpHeight-5)80 }81}8283func TestGameSelectViewContentSizeIsStableAcrossCategories(t *testing.T) {84 l := ui.InitCategoryList(GameCategories, "Select Category")85 m := model{86 state: gameSelectView,87 width: 120,88 height: 40,89 nav: navigationState{90 gameSelectList: l,91 },92 }93 m = m.updateCategoryDetailViewport()9495 wantWidth := lipgloss.Width(gameSelectViewContent(m.width, m.height, m.nav.gameSelectList, m.nav.categoryDetail, m.notice))96 wantHeight := lipgloss.Height(gameSelectViewContent(m.width, m.height, m.nav.gameSelectList, m.nav.categoryDetail, m.notice))9798 for i := range m.nav.gameSelectList.Items() {99 m.nav.gameSelectList.Select(i)100 m = m.updateCategoryDetailViewport()101102 if got := lipgloss.Width(gameSelectViewContent(m.width, m.height, m.nav.gameSelectList, m.nav.categoryDetail, m.notice)); got != wantWidth {103 t.Fatalf("selection %d width = %d, want %d", i, got, wantWidth)104 }105 if got := lipgloss.Height(gameSelectViewContent(m.width, m.height, m.nav.gameSelectList, m.nav.categoryDetail, m.notice)); got != wantHeight {106 t.Fatalf("selection %d height = %d, want %d", i, got, wantHeight)107 }108 }109}