Repository navigation
Expand file tree
/
Copy pathtemplate_render_test.go
More file actions
121 lines (107 loc) · 2.98 KB
/
Copy pathtemplate_render_test.go
File metadata and controls
121 lines (107 loc) · 2.98 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package patchbin
import (
"bytes"
"html/template"
"strings"
"testing"
)
func TestPatchFileTemplateRendersLineDiffOnly(t *testing.T) {
files, _, err := ParsePatch(sampleDiff)
if err != nil {
t.Fatalf("ParsePatch: %v", err)
}
semanticChanges := AnalyzeSemanticChanges(files[0])
for i := range semanticChanges {
semanticChanges[i].HunkAnchor = hunkAnchor(1, "foo.go", semanticChanges[i].HunkIndex)
}
hunks := make([]PatchHunk, 0, len(files[0].TextFragments))
for i, frag := range files[0].TextFragments {
hunks = append(hunks, PatchHunk{
Anchor: hunkAnchor(1, "foo.go", i),
DiffText: template.HTML(frag.String()),
})
}
pf := &PatchFile{
File: files[0],
DisplayName: "foo.go",
FileAnchor: "patch-1-foo.go",
Adds: 5,
Dels: 2,
Hunks: hunks,
SemanticChanges: semanticChanges,
}
tmpl := getTemplate("pr.html")
if tmpl == nil {
t.Fatalf("getTemplate returned nil")
}
patchFileTmpl := tmpl.Lookup("patch-file")
if patchFileTmpl == nil {
t.Fatalf("patch-file template not found")
}
var buf bytes.Buffer
if err := patchFileTmpl.Execute(&buf, pf); err != nil {
t.Fatalf("execute: %v", err)
}
out := buf.String()
t.Logf("rendered output:\n%s", out)
// Per-file details should be pure line-diff now -- the semantic
// breakdown lives only in the patch-level summary, so repeating it
// here would be redundant.
if bytes.Contains(buf.Bytes(), []byte("semantic-diff")) {
t.Errorf("expected no semantic-diff content inside patch-file, semantic breakdown belongs in the summary only")
}
if !bytes.Contains(buf.Bytes(), []byte(`<details class="details-min" open id="patch-1-foo.go">`)) {
t.Errorf("expected patch-file details element to be open by default")
}
if !bytes.Contains(buf.Bytes(), []byte("patch-1-foo.go-hunk-0")) {
t.Errorf("expected hunk anchor in rendered line diff")
}
}
func TestPRTimelineRendersComment(t *testing.T) {
tmpl := getTemplate("pr.html")
if tmpl == nil {
t.Fatalf("getTemplate returned nil")
}
data := PrDetailData{
Page: "pr",
RepoName: "test-repo",
Branch: "main",
Logs: []EventLogData{
{
EventLog: &EventLog{
Event: "pr_commented",
Data: EventData{Comment: "Looks great to me!"},
},
UserData: UserData{
Name: "alice",
},
Date: "2026-10-01",
},
},
Pr: PrData{
ID: 1,
Title: "Test PR",
},
MetaData: MetaData{
URL: "example.com",
},
Patchset: &Patchset{},
Patch: &PatchData{
Patch: &Patch{},
},
}
var buf bytes.Buffer
if err := tmpl.Execute(&buf, data); err != nil {
t.Fatalf("execute: %v", err)
}
out := buf.String()
if !strings.Contains(out, "commented") {
t.Errorf("expected 'commented' in rendered timeline, got:\n%s", out)
}
if !strings.Contains(out, "Looks great to me!") {
t.Errorf("expected comment text in rendered timeline, got:\n%s", out)
}
if !strings.Contains(out, "timeline-comment") {
t.Errorf("expected 'timeline-comment' class in rendered timeline, got:\n%s", out)
}
}