-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreport_test.go
More file actions
138 lines (120 loc) · 3.4 KB
/
report_test.go
File metadata and controls
138 lines (120 loc) · 3.4 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package main
import (
"strings"
"testing"
"time"
)
func TestGenerateReport(t *testing.T) {
stats := Stats{
TotalCommits: 50,
TotalFiles: 100,
TotalInsertions: 500,
TotalDeletions: 200,
ActiveDays: 20,
AuthorCommits: map[string]int{"Alice": 30, "Bob": 20},
AuthorLines: map[string]int{"Alice": 400, "Bob": 300},
DailyCommits: map[string]int{},
FirstCommit: makeTime(2024, 12, 1, 10),
LastCommit: makeTime(2024, 12, 30, 15),
}
streaks := StreakInfo{
CurrentStreak: 5,
LongestStreak: 10,
ActivityRate: 66.7,
}
churn := []FileChurn{
{Path: "main.go", Changes: 15, Insertions: 100, Deletions: 50},
{Path: "util.go", Changes: 8, Insertions: 40, Deletions: 20},
}
report := GenerateReport(stats, streaks, churn, 30)
if report.Days != 30 {
t.Errorf("expected 30 days, got %d", report.Days)
}
if report.Stats.TotalCommits != 50 {
t.Errorf("expected 50 commits, got %d", report.Stats.TotalCommits)
}
}
func TestToMarkdown(t *testing.T) {
stats := Stats{
TotalCommits: 25,
TotalFiles: 50,
TotalInsertions: 300,
TotalDeletions: 100,
ActiveDays: 15,
BusiestDay: "2024-12-15",
BusiestDayCount: 8,
AvgCommitsPerDay: 1.67,
AuthorCommits: map[string]int{"Alice": 15, "Bob": 10},
AuthorLines: map[string]int{"Alice": 250, "Bob": 150},
DailyCommits: map[string]int{},
FirstCommit: makeTime(2024, 12, 1, 10),
LastCommit: makeTime(2024, 12, 30, 15),
}
streaks := StreakInfo{
CurrentStreak: 3,
LongestStreak: 7,
LongestStreakStart: makeTime(2024, 12, 5, 0),
LongestStreakEnd: makeTime(2024, 12, 11, 0),
ActivityRate: 50.0,
}
churn := []FileChurn{
{Path: "main.go", Changes: 10, Insertions: 80, Deletions: 30},
}
report := GenerateReport(stats, streaks, churn, 30)
md := report.ToMarkdown()
// Check essential sections exist
checks := []string{
"# Git Activity Report",
"## 📊 Overview",
"## 🔥 Streaks",
"## 🕐 Patterns",
"## 👥 Contributors",
"## 📁 Hottest Files",
"Total Commits | 25",
"+300",
"-100",
"Current Streak:** 3 days",
"Longest Streak:** 7 days",
"`main.go`",
"gitcap",
}
for _, check := range checks {
if !strings.Contains(md, check) {
t.Errorf("markdown report missing %q", check)
}
}
}
func TestToMarkdownSingleAuthor(t *testing.T) {
stats := Stats{
TotalCommits: 10,
ActiveDays: 5,
AuthorCommits: map[string]int{"Solo": 10},
AuthorLines: map[string]int{"Solo": 100},
DailyCommits: map[string]int{},
FirstCommit: time.Now().AddDate(0, 0, -5),
LastCommit: time.Now(),
}
report := GenerateReport(stats, StreakInfo{}, nil, 30)
md := report.ToMarkdown()
// Single author should NOT have Contributors section
if strings.Contains(md, "## 👥 Contributors") {
t.Error("single author report should not have Contributors section")
}
}
func TestToMarkdownNoChurn(t *testing.T) {
stats := Stats{
TotalCommits: 5,
ActiveDays: 3,
AuthorCommits: map[string]int{"Dev": 5},
AuthorLines: map[string]int{"Dev": 50},
DailyCommits: map[string]int{},
FirstCommit: time.Now().AddDate(0, 0, -3),
LastCommit: time.Now(),
}
report := GenerateReport(stats, StreakInfo{}, nil, 30)
md := report.ToMarkdown()
// No churn data should NOT have Hottest Files section
if strings.Contains(md, "## 📁 Hottest Files") {
t.Error("report with no churn should not have Hottest Files section")
}
}