From e7bd55d20974f4ee5b892cd2e81c62b5c5408920 Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Sun, 16 Aug 2026 11:30:30 +0200 Subject: refactor(web): extract testable profile logic --- web/server_test.go | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'web/server_test.go') diff --git a/web/server_test.go b/web/server_test.go index 281f46a..a4ee0b7 100644 --- a/web/server_test.go +++ b/web/server_test.go @@ -135,9 +135,9 @@ func TestHandlerRendersRideDetailWithEmbeddedRoute(t *testing.T) { assert.NotContains(t, body, "Climbs to match") assert.Contains(t, body, `class="ride-detail-main"`) assert.Contains(t, body, ``) + assert.Contains(t, body, ``) assert.Contains(t, body, ``) assert.Contains(t, body, ``) - assert.NotContains(t, body, "pointermove") staticRequest := httptest.NewRequest(http.MethodGet, "/static/ride-detail.js", nil) staticResponse := httptest.NewRecorder() @@ -146,17 +146,8 @@ func TestHandlerRendersRideDetailWithEmbeddedRoute(t *testing.T) { script := staticResponse.Body.String() assert.Equal(t, http.StatusOK, staticResponse.Code) assert.Equal(t, "text/javascript; charset=utf-8", staticResponse.Header().Get("Content-Type")) - assert.Contains(t, script, "pointermove") - assert.Contains(t, script, "circleMarker") - assert.Contains(t, script, "crossing.passElevationM") - assert.Contains(t, script, "climbRoute") - assert.Contains(t, script, "L.polyline") - assert.Contains(t, script, "zoomToClimb") - assert.Contains(t, script, "Cotacol") - assert.Contains(t, script, "cotacolForClimb") - assert.Contains(t, script, "const labelY = plot.top - 6") + assert.NotEmpty(t, script) assert.Contains(t, body, "leaflet@1.9.4/dist/leaflet.js") - assert.Contains(t, script, "tile.openstreetmap.org/{z}/{x}/{y}.png") assert.Contains(t, body, `"type":"FeatureCollection"`) assert.Contains(t, body, `"type":"LineString"`) assert.Contains(t, body, `"coordinates":[[5,43]`) @@ -168,11 +159,15 @@ func TestHandlerRendersRideDetailWithEmbeddedRoute(t *testing.T) { profileScript := profileStaticResponse.Body.String() assert.Equal(t, http.StatusOK, profileStaticResponse.Code) assert.Equal(t, "text/javascript; charset=utf-8", profileStaticResponse.Header().Get("Content-Type")) - assert.Contains(t, profileScript, "officialProfileSections") - assert.Contains(t, profileScript, "profileStepSizesM = [100, 200, 500, 1000]") - assert.Contains(t, profileScript, "displayStepForLength") - assert.Contains(t, profileScript, "profileBandForSlope") - assert.Contains(t, profileScript, "section.slopePercent.toFixed(1)") + assert.NotEmpty(t, profileScript) + + logicStaticRequest := httptest.NewRequest(http.MethodGet, "/static/official-climb-profile-logic.js", nil) + logicStaticResponse := httptest.NewRecorder() + server.Handler().ServeHTTP(logicStaticResponse, logicStaticRequest) + + assert.Equal(t, http.StatusOK, logicStaticResponse.Code) + assert.Equal(t, "text/javascript; charset=utf-8", logicStaticResponse.Header().Get("Content-Type")) + assert.NotEmpty(t, logicStaticResponse.Body.String()) } func TestBuildRideProfileIncludesClimbsAndCrossings(t *testing.T) { -- cgit v1.2.3