From 89467f19b929b742c35ae14d89abb3ca816ec435 Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Tue, 11 Aug 2026 20:36:48 +0200 Subject: feat: add interactive ride profile --- web/server_test.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'web/server_test.go') diff --git a/web/server_test.go b/web/server_test.go index 5964c5a..8e4c568 100644 --- a/web/server_test.go +++ b/web/server_test.go @@ -14,7 +14,10 @@ import ( "testing" "time" + "github.com/jftuga/geodist" "github.com/martinlehoux/biking_home/config" + "github.com/martinlehoux/biking_home/mountain_pass" + "github.com/martinlehoux/biking_home/ride" "github.com/martinlehoux/biking_home/rides" "github.com/martinlehoux/biking_home/strava" _ "github.com/mattn/go-sqlite3" @@ -47,6 +50,19 @@ func newWebTestServer(t *testing.T) (*Server, *sql.DB) { ) `) require.NoError(t, err) + _, err = db.Exec(` + create table mountain_passes ( + id integer primary key, + external_id text unique not null, + name text not null, + country_code text not null, + department_code text not null, + elevation integer not null, + latitude real, + longitude real + ) + `) + require.NoError(t, err) configPath := filepath.Join(t.TempDir(), "config.yaml") appConfig := config.Default() appConfig.Strava.ClientID = "123" @@ -142,7 +158,13 @@ func TestHandlerRendersRideDetailWithEmbeddedRoute(t *testing.T) { assert.Equal(t, http.StatusOK, response.Code) assert.Contains(t, body, "Detailed Ride") assert.Contains(t, body, `id="ride-route"`) + assert.Contains(t, body, `id="ride-profile"`) + assert.Contains(t, body, `id="ride-profile-chart"`) assert.Contains(t, body, `id="ride-map"`) + assert.Contains(t, body, "pointermove") + assert.Contains(t, body, "circleMarker") + assert.Contains(t, body, "crossing.passElevationM") + assert.Contains(t, body, "const labelY = plot.top - 6") assert.Contains(t, body, "leaflet@1.9.4/dist/leaflet.js") assert.Contains(t, body, "tile.openstreetmap.org/{z}/{x}/{y}.png") assert.Contains(t, body, `"type":"FeatureCollection"`) @@ -150,6 +172,32 @@ func TestHandlerRendersRideDetailWithEmbeddedRoute(t *testing.T) { assert.Contains(t, body, `"coordinates":[[5,43]`) } +func TestBuildRideProfileIncludesClimbsAndCrossings(t *testing.T) { + parsed := ride.FromColumns( + []float64{0, 1000, 2000}, + []float64{300, 447, 380}, + []geodist.Coord{{Lat: 43.61, Lon: 5.42}, {Lat: 43.62, Lon: 5.43}, {Lat: 43.63, Lon: 5.44}}, + make([]time.Time, 3), + ) + passes := []mountain_pass.MountainPass{{ + Name: "Pas de Magnan", + Elevation: 440, + Coord: &geodist.Coord{Lat: 43.62, Lon: 5.43}, + }} + + profile := buildRideProfile(parsed, passes) + + require.Len(t, profile.Points, 3) + assert.Equal(t, 1.0, profile.Points[1].DistanceKm) + assert.Equal(t, 447.0, profile.Points[1].ElevationM) + require.Len(t, profile.Climbs, 1) + assert.Equal(t, "Pas de Magnan", profile.Climbs[0].Name) + assert.Equal(t, 1.0, profile.Climbs[0].TopKm) + require.Len(t, profile.Crossings, 1) + assert.Equal(t, "Pas de Magnan", profile.Crossings[0].Name) + assert.Equal(t, 1.0, profile.Crossings[0].DistanceKm) +} + func TestHandlerRendersRideDetailWithoutRoute(t *testing.T) { server, db := newWebTestServer(t) item := rides.Ride{ -- cgit v1.2.3