refactor(viewer): consolidate rendering and harden uploads

This commit is contained in:
Mikhail Chusavitin
2026-09-01 12:59:18 +03:00
parent ba751c861d
commit be68069a51
9 changed files with 214 additions and 276 deletions
+21
View File
@@ -101,3 +101,24 @@ func TestStaticJSUsesScriptContentType(t *testing.T) {
t.Fatalf("expected static JS asset body to be served")
}
}
func TestStandaloneHandlerAssetsAndFormWorkUnderPathPrefix(t *testing.T) {
outer := http.NewServeMux()
outer.Handle("/chart/", http.StripPrefix("/chart", NewStandaloneHandler(HandlerOptions{Title: "Reanimator Chart"})))
pageRec := httptest.NewRecorder()
outer.ServeHTTP(pageRec, httptest.NewRequest(http.MethodGet, "/chart/", nil))
if pageRec.Code != http.StatusOK {
t.Fatalf("page status = %d, want %d", pageRec.Code, http.StatusOK)
}
body := pageRec.Body.String()
if !strings.Contains(body, `href="static/view.css"`) || !strings.Contains(body, `action="render"`) {
t.Fatalf("prefixed page contains root-absolute internal URLs: %s", body)
}
staticRec := httptest.NewRecorder()
outer.ServeHTTP(staticRec, httptest.NewRequest(http.MethodGet, "/chart/static/view.js", nil))
if staticRec.Code != http.StatusOK {
t.Fatalf("static asset status = %d, want %d", staticRec.Code, http.StatusOK)
}
}