diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-08-16 11:30:30 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-08-16 11:30:30 +0200 |
| commit | e7bd55d20974f4ee5b892cd2e81c62b5c5408920 (patch) | |
| tree | 4e0aa6c107d7096962beffdd491814805a350a89 /web/server_test.go | |
| parent | 3e1c6f9c0056c488f51dc2e13d6ddf5365adb312 (diff) | |
refactor(web): extract testable profile logic
Diffstat (limited to 'web/server_test.go')
| -rw-r--r-- | web/server_test.go | 27 |
1 files changed, 11 insertions, 16 deletions
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, `<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js" defer></script>`) + assert.Contains(t, body, `<script src="/static/official-climb-profile-logic.js" defer></script>`) assert.Contains(t, body, `<script src="/static/official-climb-profile.js" defer></script>`) assert.Contains(t, body, `<script src="/static/ride-detail.js" defer></script>`) - 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) { |