▍ humdrum codex / sportsball v0.1.0
license AGPL-3.0
2.0 KB raw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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")
	}
}