fix mascot

This commit is contained in:
2026-07-30 11:09:25 +02:00
parent 28e418abd6
commit bcad515698
3 changed files with 256 additions and 16 deletions

View File

@@ -196,6 +196,173 @@ func TestDiffletDisabledPreservesViewExactly(t *testing.T) {
}
}
func TestDiffletDashboardIsCenteredBesideMetadata(t *testing.T) {
app := NewAppWithSettings(
&recordingService{}, "owner", "repository", false, 10, 10,
AppSettings{Mascot: true},
)
app.screen = dashboardScreen
app.loading = false
app.details = PRDetails{
PullRequest: PullRequest{
RepoWithOwner: "owner/repository", Number: 42,
Title: "A useful title", Author: "alice",
},
HeadRef: "feature", BaseRef: "main",
}
updated, _ := app.Update(tea.WindowSizeMsg{Width: 80, Height: 24})
app = updated.(App)
rendered := strings.Split(app.View(), "\n")
headerHeight := len(app.dashboardHeaderLines())
if strings.TrimSpace(ansi.Strip(rendered[headerHeight])) == "" {
t.Fatal("dashboard left a blank row between its title and metadata")
}
for row, mascotLine := range (DiffletFrame{Expression: DiffletIdle}).lines() {
plain := ansi.Strip(rendered[headerHeight+row])
mascotText := strings.TrimRight(mascotLine, " ")
mascotIndex := strings.Index(plain, mascotText)
left := -1
if mascotIndex >= 0 {
left = lipgloss.Width(plain[:mascotIndex])
}
if left != (app.width-diffletWidth)/2 {
t.Fatalf("row %d mascot starts at %d, want centered position %d: %q",
row, left, (app.width-diffletWidth)/2, plain)
}
}
for row, label := range []string{"author", "branches", "review"} {
if !strings.Contains(ansi.Strip(rendered[headerHeight+row]), label) {
t.Fatalf("dashboard row %d does not place %q beside mascot: %q",
row, label, ansi.Strip(rendered[headerHeight+row]))
}
}
}
func TestDiffletIsHiddenInEditorAndPopups(t *testing.T) {
app := NewAppWithSettings(
&recordingService{}, "owner", "repository", false, 10, 10,
AppSettings{Mascot: true},
)
app.screen = dashboardScreen
app.loading = false
app.details = PRDetails{PullRequest: PullRequest{
RepoWithOwner: "owner/repository", Number: 42, Title: "Title",
}}
updated, _ := app.Update(tea.WindowSizeMsg{Width: 80, Height: 24})
app = updated.(App)
for _, mode := range []writeMode{writePREdit, writeReplyConfirm} {
app.writeMode = mode
if got, want := app.View(), app.viewContent(); got != want {
t.Fatalf("write mode %d changed by enabled mascot:\ngot:\n%q\nwant:\n%q",
mode, got, want)
}
if strings.Contains(ansi.Strip(app.View()), "▄███████▄") {
t.Fatalf("write mode %d displayed the mascot", mode)
}
}
app.writeMode = writeNone
app.helpVisible = true
if got, want := app.View(), app.viewContent(); got != want {
t.Fatalf("help popup changed by enabled mascot:\ngot:\n%q\nwant:\n%q", got, want)
}
}
func TestDiffletEnabledEditorCanRevealLastDescriptionRow(t *testing.T) {
app := NewAppWithSettings(
&recordingPRService{}, "owner", "repository", false, 10, 10,
AppSettings{Mascot: true},
)
app.screen = dashboardScreen
app.loading = false
app.width, app.height = 50, 12
app.details = PRDetails{
PullRequest: PullRequest{
ID: "pr", RepoWithOwner: "owner/repository", Number: 42,
Title: "Title",
},
BaseRef: "main",
Body: strings.Repeat("description row\n", 20) + "LAST DESCRIPTION ROW",
Permissions: ViewerPermissions{
CanUpdatePR: true,
},
}
app.startPREdit()
app.prEditEditors[prEditBodyField].Cursor =
len([]rune(app.prEditEditors[prEditBodyField].Text))
app.ensurePREditCursorVisible()
rendered := ansi.Strip(app.View())
if !strings.Contains(rendered, "LAST DESCRIPTION ROW") {
t.Fatalf("last description row is outside the editor viewport:\n%s", rendered)
}
if strings.Contains(rendered, "▄███████▄") {
t.Fatal("editor displayed the mascot instead of using its full height")
}
}
func TestDashboardDiffletRemainsCenteredAtNarrowWidths(t *testing.T) {
mascot := (DiffletFrame{Expression: DiffletIdle}).lines()
metadata := []string{"author", "branches", "review", "checks"}
for width := diffletWidth; width < 20; width++ {
rendered := renderDashboardMetadataWithDifflet(metadata, mascot, width)
for row, mascotLine := range mascot {
mascotText := strings.TrimRight(mascotLine, " ")
var mascotRow string
for _, line := range rendered {
if strings.Contains(line, mascotText) {
mascotRow = line
break
}
}
index := strings.Index(mascotRow, mascotText)
left := -1
if index >= 0 {
left = lipgloss.Width(mascotRow[:index])
}
if want := max(0, (width-diffletWidth)/2); left != want {
t.Fatalf("width %d row %d mascot starts at %d, want %d: %q",
width, row, left, want, mascotRow)
}
}
}
}
func TestDashboardLoadingDiffletIsCentered(t *testing.T) {
app := NewAppWithSettings(
&recordingService{}, "owner", "repository", false, 10, 10,
AppSettings{Mascot: true},
)
app.screen = dashboardScreen
app.loading = true
app.details = PRDetails{PullRequest: PullRequest{
RepoWithOwner: "owner/repository", Number: 42, Title: "Title",
}}
updated, _ := app.Update(tea.WindowSizeMsg{Width: 80, Height: 24})
app = updated.(App)
rendered := strings.Split(app.View(), "\n")
mascotLine := strings.TrimRight((DiffletFrame{Expression: DiffletIdle}).lines()[0], " ")
for row, line := range rendered {
plain := ansi.Strip(line)
index := strings.Index(plain, mascotLine)
if index < 0 {
continue
}
if left := lipgloss.Width(plain[:index]); left != (app.width-diffletWidth)/2 {
t.Fatalf("loading mascot starts at %d, want %d: %q",
left, (app.width-diffletWidth)/2, plain)
}
if row != len(app.dashboardHeaderLines()) {
t.Fatalf("loading mascot begins on row %d, want %d",
row, len(app.dashboardHeaderLines()))
}
return
}
t.Fatal("loading dashboard did not display the mascot")
}
func TestDiffletHeaderMeasurementMatchesRenderedHeader(t *testing.T) {
tests := []struct {
name string