Skip to content

Commit

Permalink
dashboard/app: looking for the unique coverage, hide record with zero…
Browse files Browse the repository at this point in the history
… hitcount
  • Loading branch information
tarasmadan committed Jan 25, 2025
1 parent 13354c7 commit fcbb1bc
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 11 deletions.
25 changes: 18 additions & 7 deletions pkg/cover/heatmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,19 @@ func (thm *templateHeatmapRow) addParts(depth int, pathLeft []string, filePath s
thm.builder[nextElement].addParts(depth+1, pathLeft[1:], filePath, instrumented, covered, timePeriod)
}

func (thm *templateHeatmapRow) prepareDataFor(pageColumns []pageColumnTarget) {
thm.Items = maps.Values(thm.builder)
func (thm *templateHeatmapRow) prepareDataFor(pageColumns []pageColumnTarget, skipEmpty bool) {
for _, item := range thm.builder {
if !skipEmpty {
thm.Items = append(thm.Items, item)
continue
}
for _, hitCount := range item.covered {
if hitCount > 0 {
thm.Items = append(thm.Items, item)
break
}
}
}
sort.Slice(thm.Items, func(i, j int) bool {
if thm.Items[i].IsDir != thm.Items[j].IsDir {
return thm.Items[i].IsDir
Expand Down Expand Up @@ -102,7 +113,7 @@ func (thm *templateHeatmapRow) prepareDataFor(pageColumns []pageColumnTarget) {
thm.LastDayInstrumented = thm.instrumented[lastDate]
}
for _, item := range thm.builder {
item.prepareDataFor(pageColumns)
item.prepareDataFor(pageColumns, skipEmpty)
}
}

Expand Down Expand Up @@ -131,7 +142,7 @@ type pageColumnTarget struct {
Commit string
}

func filesCoverageToTemplateData(fCov []*fileCoverageWithDetails) *templateHeatmap {
func filesCoverageToTemplateData(fCov []*fileCoverageWithDetails, hideEmpty bool) *templateHeatmap {
res := templateHeatmap{
Root: &templateHeatmapRow{
IsDir: true,
Expand Down Expand Up @@ -164,7 +175,7 @@ func filesCoverageToTemplateData(fCov []*fileCoverageWithDetails) *templateHeatm
res.Periods = append(res.Periods, fmt.Sprintf("%s(%d)", tp.DateTo.String(), tp.Days))
}

res.Root.prepareDataFor(targetDateAndCommits)
res.Root.prepareDataFor(targetDateAndCommits, hideEmpty)
return &res
}

Expand Down Expand Up @@ -403,7 +414,7 @@ func DoHeatMapStyleBodyJS(
if err != nil {
return "", "", "", fmt.Errorf("failed to filesCoverageWithDetails: %w", err)
}
templData := filesCoverageToTemplateData(covAndDates)
templData := filesCoverageToTemplateData(covAndDates, onlyUnique)
templData.Subsystems = sss
templData.Managers = managers
return stylesBodyJSTemplate(templData)
Expand All @@ -430,7 +441,7 @@ func DoSubsystemsHeatMapStyleBodyJS(
ssCovAndDates = append(ssCovAndDates, &newRecord)
}
}
templData := filesCoverageToTemplateData(ssCovAndDates)
templData := filesCoverageToTemplateData(ssCovAndDates, onlyUnique)
templData.Managers = managers
return stylesBodyJSTemplate(templData)
}
Expand Down
31 changes: 27 additions & 4 deletions pkg/cover/heatmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,10 @@ func newRowIteratorMock(t *testing.T, events []*FileCoverageWithLineInfo,

func TestFilesCoverageToTemplateData(t *testing.T) {
tests := []struct {
name string
input []*fileCoverageWithDetails
want *templateHeatmap
name string
input []*fileCoverageWithDetails
hideEmpty bool
want *templateHeatmap
}{
{
name: "empty input",
Expand Down Expand Up @@ -385,10 +386,32 @@ func TestFilesCoverageToTemplateData(t *testing.T) {
Periods: []string{"2024-07-01(1)", "2024-07-02(1)"},
},
},
{
name: "hide empty",
hideEmpty: true,
input: []*fileCoverageWithDetails{
{
Filepath: "file1",
Instrumented: 1,
Covered: 0,
TimePeriod: makeTimePeriod(t, civil.Date{Year: 2024, Month: time.July, Day: 1}, coveragedb.DayPeriod),
Commit: "commit1",
},
},
want: &templateHeatmap{
Root: &templateHeatmapRow{
Coverage: []int64{0},
IsDir: true,
LastDayInstrumented: 1,
Tooltips: []string{"Instrumented:\t1 blocks\nCovered:\t0 blocks"},
},
Periods: []string{"2024-07-01(1)"},
},
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got := filesCoverageToTemplateData(test.input)
got := filesCoverageToTemplateData(test.input, test.hideEmpty)
assert.EqualExportedValues(t, test.want, got)
})
}
Expand Down

0 comments on commit fcbb1bc

Please sign in to comment.