mirror of
https://github.com/go-gitea/gitea.git
synced 2026-02-23 04:18:07 +01:00
Fixes: https://github.com/go-gitea/gitea/issues/21045 - Move heatmap data loading from synchronous server-side rendering to async client-side fetch via dedicated JSON endpoints - Dashboard and user profile pages no longer block on the expensive heatmap DB query during HTML generation - Use compact `[[timestamp,count]]` JSON format instead of `[{"timestamp":N,"contributions":N}]` to reduce payload size - Public API (`/api/v1/users/{username}/heatmap`) remains unchanged - Heatmap rendering is unchanged, still shows a spinner as before, which will now spin a litte bit longer. Signed-off-by: silverwind <me@silverwind.io> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
60 lines
1.6 KiB
Go
60 lines
1.6 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package integration
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
"time"
|
|
|
|
"code.gitea.io/gitea/modules/timeutil"
|
|
"code.gitea.io/gitea/tests"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestHeatmapEndpoints(t *testing.T) {
|
|
defer tests.PrepareTestEnv(t)()
|
|
|
|
// Mock time so fixture actions fall within the heatmap's time window
|
|
timeutil.MockSet(time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC))
|
|
defer timeutil.MockUnset()
|
|
|
|
session := loginUser(t, "user2")
|
|
|
|
t.Run("UserProfile", func(t *testing.T) {
|
|
defer tests.PrintCurrentTest(t)()
|
|
req := NewRequest(t, "GET", "/user2/-/heatmap")
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
var result map[string]any
|
|
DecodeJSON(t, resp, &result)
|
|
assert.Contains(t, result, "heatmapData")
|
|
assert.Contains(t, result, "totalContributions")
|
|
assert.Positive(t, result["totalContributions"])
|
|
})
|
|
|
|
t.Run("OrgDashboard", func(t *testing.T) {
|
|
defer tests.PrintCurrentTest(t)()
|
|
req := NewRequest(t, "GET", "/org/org3/dashboard/-/heatmap")
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
var result map[string]any
|
|
DecodeJSON(t, resp, &result)
|
|
assert.Contains(t, result, "heatmapData")
|
|
assert.Contains(t, result, "totalContributions")
|
|
})
|
|
|
|
t.Run("OrgTeamDashboard", func(t *testing.T) {
|
|
defer tests.PrintCurrentTest(t)()
|
|
req := NewRequest(t, "GET", "/org/org3/dashboard/-/heatmap/team1")
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
var result map[string]any
|
|
DecodeJSON(t, resp, &result)
|
|
assert.Contains(t, result, "heatmapData")
|
|
assert.Contains(t, result, "totalContributions")
|
|
})
|
|
}
|