package ui import ( "strings" "testing" "github.com/humdrum-tiv/sportsball/internal/model" ) func mlbLiveGame() model.Game { return model.Game{ ID: "g1", League: model.MLB, State: model.StateLive, Detail: "Top 7th", Home: model.Team{ID: "22", Abbr: "PHI", Name: "Phillies", Score: 8}, Away: model.Team{ID: "28", Abbr: "MIA", Name: "Marlins", Score: 0}, Situation: &model.Situation{ Balls: 1, Strikes: 2, Outs: 2, OnFirst: true, OnThird: true, Pitcher: "Jesus Luzardo", PitcherLine: "6.0 IP, 0 ER", Batter: "Leo Jimenez", BatterLine: "0-2, K", }, } } func TestSituationBlockShowsCountOutsPlayers(t *testing.T) { out := situationBlock(mlbLiveGame(), 72) for _, want := range []string{"1-2", "2 outs", "Jesus Luzardo", "Leo Jimenez"} { if !strings.Contains(out, want) { t.Errorf("situation missing %q in:\n%s", want, out) } } } func TestSituationBlockNilWhenNoSituation(t *testing.T) { g := mlbLiveGame() g.Situation = nil if out := situationBlock(g, 72); out != "" { t.Errorf("expected empty, got %q", out) } } func TestBaseballDetailShowsScoringPlaysAboveBox(t *testing.T) { g := mlbLiveGame() a := App{width: 100, height: 60, mode: viewDetail, detail: g, games: map[model.LeagueID][]model.Game{model.MLB: {g}}, detailData: map[string]model.GameDetail{g.ID: { Events: []model.MatchEvent{ {Clock: "▼1", TeamID: "22", Type: "Single", Text: "Bohm singled, Harper scored.", Scoring: true}, {Clock: "▼4", TeamID: "22", Type: "Home Run", Text: "Schwarber homered to right.", Scoring: true}, }, BoxScore: []model.TeamBox{{Abbr: "PHI", Name: "Phillies", Groups: []model.StatGroup{ {Name: "batting", Labels: []string{"AB", "H"}, Rows: []model.PlayerRow{{Athlete: "Bohm", Stats: []string{"4", "2"}}}}, }}}, }}, } out := a.detailView() si := strings.Index(out, "SCORING PLAYS") bi := strings.Index(out, "BATTING") if si < 0 || bi < 0 { t.Fatalf("missing sections: scoring=%d batting=%d", si, bi) } if si > bi { t.Errorf("scoring plays should render above box score") } }