Show reactions to threads

This commit is contained in:
2026-07-28 12:02:33 +02:00
parent f93c2c517a
commit 72e1eb1fda
6 changed files with 175 additions and 4 deletions

View File

@@ -926,6 +926,61 @@ func TestReviewAnchorUsesCommentSnapshotCoordinates(t *testing.T) {
}
}
func TestThreadDetailShowsCommentReactions(t *testing.T) {
m := NewApp(nil, "o", "r", false, 50, 10*time.Second)
m.width = 80
m.details = PRDetails{Threads: []ReviewThread{{
ID: "thread", Path: "main.go", Comments: []ReviewComment{{
ID: "comment", Author: "reviewer", Body: "Please change this.",
Reactions: []ReactionSummary{
{Content: "THUMBS_UP", Count: 3, ViewerHasReacted: true},
{Content: "EYES", Count: 1},
{Content: "HEART", Count: 2},
},
}},
}}}
var rendered strings.Builder
reactionLines := 0
for _, line := range m.detailLines(50) {
rendered.WriteString(ansi.Strip(line.rail + line.text))
rendered.WriteByte('\n')
if strings.Contains(line.anchor, ":reactions:") {
reactionLines++
if ansi.StringWidth(line.text) > 46 {
t.Fatalf("reaction line exceeds detail width: %q", ansi.Strip(line.text))
}
}
}
plain := rendered.String()
for _, wanted := range []string{"Please change this.", "👍 3", "👀 1", "❤️ 2"} {
if !strings.Contains(plain, wanted) {
t.Fatalf("thread detail is missing %q:\n%s", wanted, plain)
}
}
if reactionLines == 0 {
t.Fatalf("reactions were not attached to their comment:\n%s", plain)
}
}
func TestReactionSummaryWrapsBetweenBadges(t *testing.T) {
reactions := []ReactionSummary{
{Content: "THUMBS_UP", Count: 10},
{Content: "THUMBS_DOWN", Count: 2},
{Content: "LAUGH", Count: 4},
{Content: "HOORAY", Count: 7},
}
lines := renderReactionSummary(reactions, 12)
if len(lines) < 2 {
t.Fatalf("reaction badges did not wrap: %#v", lines)
}
for _, line := range lines {
if width := ansi.StringWidth(line); width > 12 {
t.Fatalf("reaction line width = %d: %q", width, ansi.Strip(line))
}
}
}
func TestOutdatedDetailHighlightsOriginalCodeRange(t *testing.T) {
m := NewApp(nil, "o", "r", false, 50, 10*time.Second)
m.width = 100