aboutsummaryrefslogtreecommitdiff
path: root/web/climbs_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'web/climbs_test.go')
-rw-r--r--web/climbs_test.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/web/climbs_test.go b/web/climbs_test.go
index 3b30c07..d79f1d8 100644
--- a/web/climbs_test.go
+++ b/web/climbs_test.go
@@ -8,6 +8,7 @@ import (
"path/filepath"
"testing"
+ "github.com/martinlehoux/biking_home/internal/ridetest"
"github.com/martinlehoux/biking_home/official_climb"
"github.com/martinlehoux/biking_home/ride"
"github.com/martinlehoux/biking_home/rideanalysis"
@@ -49,6 +50,42 @@ func TestHandleClimbRendersAttemptsAndProfile(t *testing.T) {
assert.Contains(t, body, "Col de Test")
assert.Contains(t, body, "climb-profile-data")
assert.Contains(t, body, "Test Ride")
+ // A ride without a power meter renders a dash, not a fabricated value.
+ assert.Contains(t, body, `<td class="numeric">-</td>`)
+}
+
+func TestHandleClimbRendersAttemptPoints(t *testing.T) {
+ server, db := newWebTestServer(t)
+ parsed := ridetest.MustRide("1km at 14.7% w=250 | 1km at -6.7% w=150", ridetest.StartCoord(43.61, 5.42), ridetest.StartElevation(300), ridetest.Sampling(1000), ridetest.StartTime(testRideStart))
+ created, err := official_climb.Create(db, official_climb.OfficialClimb{Name: "Col de Test", StartCoord: parsed.Coords[0], EndCoord: parsed.Coords[1], Sample: parsed.Sample(0, 1)})
+ require.NoError(t, err)
+ rideID := insertTestRide(t, db)
+ analysis := rideanalysis.Analyze(parsed, nil, []official_climb.OfficialClimb{created}, official_climb.DefaultMatchPolicy())
+ server.recordOfficialClimbAttempts(rideID, parsed, analysis)
+
+ recorder := httptest.NewRecorder()
+ server.Handler().ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, climbDetailURL(created.ID), nil))
+ require.Equal(t, http.StatusOK, recorder.Code)
+ body := recorder.Body.String()
+ assert.Contains(t, body, `id="climb-attempt-points"`)
+ // Mean of the climb interval power samples: 250, 250 W.
+ assert.Contains(t, body, `"averagePowerW":250`)
+ assert.Contains(t, body, `"url":"/rides/`)
+ assert.Contains(t, body, "Avg power")
+ assert.Contains(t, body, "250 W")
+}
+
+func TestClimbAttemptPointsSkipAttemptsWithoutPower(t *testing.T) {
+ power := 235.5
+ views := []ClimbAttemptView{
+ {RideID: 7, RideName: "Powered", Date: "01 Sep 2026, 10:00", DurationS: 1110, AveragePowerW: &power},
+ {RideID: 8, RideName: "No meter", Date: "02 Sep 2026, 10:00", DurationS: 1200},
+ }
+
+ points := climbAttemptPoints(views)
+
+ require.Len(t, points, 1)
+ assert.Equal(t, ClimbAttemptPoint{DurationS: 1110, AveragePowerW: 235.5, Date: "01 Sep 2026, 10:00", RideName: "Powered", URL: "/rides/7"}, points[0])
}
func TestHandleClimbNotFound(t *testing.T) {