diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-08-16 13:19:22 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-08-16 13:19:22 +0200 |
| commit | be78280c669a04c112afaf1801f22ed2eec7c55a (patch) | |
| tree | 0d630af1d0502aae12b1a8cf4ee609a9cba9e4e3 /web/server_test.go | |
| parent | e7bd55d20974f4ee5b892cd2e81c62b5c5408920 (diff) | |
refactor(web): establish JavaScript module tooling
Diffstat (limited to 'web/server_test.go')
| -rw-r--r-- | web/server_test.go | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/web/server_test.go b/web/server_test.go index a4ee0b7..654d6d5 100644 --- a/web/server_test.go +++ b/web/server_test.go @@ -134,10 +134,10 @@ func TestHandlerRendersRideDetailWithEmbeddedRoute(t *testing.T) { assert.Contains(t, body, `class="ride-detail-columns`) 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.Contains(t, body, `<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>`) + assert.Contains(t, body, `<script type="module" src="/static/ride-detail.js"></script>`) + assert.NotContains(t, body, `<script src="/static/official-climb-profile-logic.js"`) + assert.NotContains(t, body, `<script src="/static/official-climb-profile.js"`) staticRequest := httptest.NewRequest(http.MethodGet, "/static/ride-detail.js", nil) staticResponse := httptest.NewRecorder() @@ -168,6 +168,14 @@ func TestHandlerRendersRideDetailWithEmbeddedRoute(t *testing.T) { 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()) + + syncStaticRequest := httptest.NewRequest(http.MethodGet, "/static/sync.js", nil) + syncStaticResponse := httptest.NewRecorder() + server.Handler().ServeHTTP(syncStaticResponse, syncStaticRequest) + + assert.Equal(t, http.StatusOK, syncStaticResponse.Code) + assert.Equal(t, "text/javascript; charset=utf-8", syncStaticResponse.Header().Get("Content-Type")) + assert.NotEmpty(t, syncStaticResponse.Body.String()) } func TestBuildRideProfileIncludesClimbsAndCrossings(t *testing.T) { @@ -386,7 +394,16 @@ func TestSyncPageIncludesProgressUIWhenAuthorized(t *testing.T) { assert.Contains(t, body, `id="sync-form"`) assert.Contains(t, body, `id="sync-progress"`) assert.Contains(t, body, `<progress id="sync-progress-bar"`) - assert.Contains(t, body, `text/event-stream`) + assert.Contains(t, body, `<script type="module" src="/static/sync.js"></script>`) + assert.NotContains(t, body, `const consumeEvents = async`) + + syncRequest := httptest.NewRequest(http.MethodGet, "/static/sync.js", nil) + syncResponse := httptest.NewRecorder() + server.Handler().ServeHTTP(syncResponse, syncRequest) + + assert.Equal(t, http.StatusOK, syncResponse.Code) + assert.Equal(t, "text/javascript; charset=utf-8", syncResponse.Header().Get("Content-Type")) + assert.Contains(t, syncResponse.Body.String(), `text/event-stream`) } func TestSyncRedirectsToOAuthWhenUnauthenticated(t *testing.T) { |