clone

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

chore/app-model-decomp
puzzletea / app / view_test.go
view_test.go 2.0K
1package app23import (4 "strings"5 "testing"67 tea "charm.land/bubbletea/v2"8 "github.com/FelineStateMachine/puzzletea/store"9 "github.com/FelineStateMachine/puzzletea/ui"10)1112func TestGameViewRequestsMouseCellMotion(t *testing.T) {13 m := model{14 state: gameView,15 session: sessionState{game: &escapeTrackingGame{}},16 }1718 v := m.View()19 if v.MouseMode != tea.MouseModeCellMotion {20 t.Fatalf("MouseMode = %v, want %v", v.MouseMode, tea.MouseModeCellMotion)21 }22 if !v.KeyboardEnhancements.ReportEventTypes {23 t.Fatal("expected keyboard event type reporting to remain enabled")24 }25}2627func TestCreateViewRequestsMouseCellMotion(t *testing.T) {28 m := model{29 state: createView,30 width: 100,31 height: 30,32 }33 m = m.initScreen(createView)3435 v := m.View()36 if v.MouseMode != tea.MouseModeCellMotion {37 t.Fatalf("MouseMode = %v, want %v", v.MouseMode, tea.MouseModeCellMotion)38 }39 if !v.KeyboardEnhancements.ReportEventTypes {40 t.Fatal("expected keyboard event type reporting to remain enabled")41 }42}4344func TestPlayMenuViewIncludesNotice(t *testing.T) {45 m := model{46 state: playMenuView,47 width: 80,48 height: 24,49 nav: navigationState{50 playMenu: ui.NewMainMenu(nil),51 },52 notice: noticeState{level: noticeLevelError, message: "Could not load puzzle"},53 }54 m = m.initScreen(playMenuView)5556 if got := m.viewContent(); !strings.Contains(got, "Could not load puzzle") {57 t.Fatalf("viewContent() missing notice, got %q", got)58 }59}6061func TestContinueViewStaysAtNaturalTableWidth(t *testing.T) {62 s := openAppTestStore(t)63 if err := s.CreateGame(&store.GameRecord{64 Name: "shadow-trail",65 GameType: "Sudoku",66 Mode: "Medium",67 Status: store.StatusInProgress,68 RunKind: store.RunKindNormal,69 }); err != nil {70 t.Fatal(err)71 }72 table, games := ui.InitContinueTable(s, 30)73 m := model{74 state: continueView,75 width: 140,76 height: 30,77 cont: continueState{table: table, games: games},78 }79 m = m.resizeActiveScreen()8081 if got, want := m.cont.table.Width(), ui.ContinueTableWidth(); got != want {82 t.Fatalf("continue table width = %d, want %d", got, want)83 }84}