package webui import ( "io" "net/http" "net/http/httptest" "strings" "testing" ) // get drives the handler with a GET for the given path and returns the response. func get(t *testing.T, h http.Handler, target string) *http.Response { t.Helper() rec := httptest.NewRecorder() h.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, target, nil)) return rec.Result() } func TestHandlerServesIndexAndFallsBack(t *testing.T) { h := Handler("") // The embedded placeholder index is served at the root. if resp := get(t, h, "/"); resp.StatusCode != http.StatusOK { t.Fatalf("GET / status = %d, want 200", resp.StatusCode) } // An existing (non-index) file is served directly by the file server. if resp := get(t, h, "/assets/.gitkeep"); resp.StatusCode != http.StatusOK { t.Fatalf("GET /assets/.gitkeep status = %d, want 200 (served file)", resp.StatusCode) } // An unknown deep link falls back to the SPA shell (200, not 404) so the // client-side hash router can take over. resp := get(t, h, "/game/abc/deep") if resp.StatusCode != http.StatusOK { t.Fatalf("GET /game/abc/deep status = %d, want 200 (SPA fallback)", resp.StatusCode) } body, _ := io.ReadAll(resp.Body) if !strings.Contains(string(body), "