fix(ui): restore brand across anonymous and error pages
giteabot / giteabot (push) Canceled after 0s
giteabot backport / giteabot (push) Canceled after 0s
release-nightly-snapcraft / build-and-publish (push) Canceled after 0s
release-nightly / nightly-binary (push) Canceled after 0s
release-nightly / nightly-container (push) Canceled after 0s
giteabot / giteabot (push) Canceled after 0s
giteabot backport / giteabot (push) Canceled after 0s
release-nightly-snapcraft / build-and-publish (push) Canceled after 0s
release-nightly / nightly-binary (push) Canceled after 0s
release-nightly / nightly-container (push) Canceled after 0s
Assisted-by: Codex:GPT-5
This commit is contained in:
@@ -24,6 +24,11 @@ import (
|
||||
const tplStatus500 templates.TplName = "status/500"
|
||||
|
||||
func renderServerErrorPage(w http.ResponseWriter, req *http.Request, respCode int, tmpl templates.TplName, ctxData map[string]any, plainMsg string) {
|
||||
if ctxData == nil {
|
||||
ctxData = map[string]any{}
|
||||
}
|
||||
ctxData["ShowNavbarBrand"] = true
|
||||
|
||||
acceptsHTML := false
|
||||
for _, part := range req.Header["Accept"] {
|
||||
if strings.Contains(part, "text/html") {
|
||||
|
||||
@@ -27,12 +27,21 @@ func TestRenderPanicErrorPage(t *testing.T) {
|
||||
assert.Contains(t, respContent, `class="page-content status-page-500"`)
|
||||
assert.Contains(t, respContent, `</html>`)
|
||||
assert.Contains(t, respContent, `lang="en-US"`) // make sure the locale work
|
||||
assertNavbarBrand(t, respContent)
|
||||
|
||||
// the 500 page doesn't have normal pages footer, it makes it easier to distinguish a normal page and a failed page.
|
||||
// especially when a sub-template causes page error, the HTTP response code is still 200,
|
||||
// the different "footer" is the only way to know whether a page is fully rendered without error.
|
||||
assert.False(t, test.IsNormalPageCompleted(respContent))
|
||||
})
|
||||
t.Run("ServiceUnavailableHTML", func(t *testing.T) {
|
||||
w := httptest.NewRecorder()
|
||||
req := &http.Request{URL: &url.URL{}, Header: http.Header{"Accept": []string{"text/html"}}}
|
||||
req = req.WithContext(reqctx.NewRequestContextForTest(t.Context()))
|
||||
renderServiceUnavailable(w, req)
|
||||
assert.Equal(t, http.StatusServiceUnavailable, w.Code)
|
||||
assertNavbarBrand(t, w.Body.String())
|
||||
})
|
||||
t.Run("Plain", func(t *testing.T) {
|
||||
w := httptest.NewRecorder()
|
||||
req := &http.Request{URL: &url.URL{}}
|
||||
@@ -42,6 +51,13 @@ func TestRenderPanicErrorPage(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func assertNavbarBrand(t *testing.T, content string) {
|
||||
t.Helper()
|
||||
assert.Contains(t, content, `class="navbar-brand-copy"`)
|
||||
assert.Contains(t, content, "荣刻科技")
|
||||
assert.Contains(t, content, "RONCARVE TECHNOLOGY")
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
unittest.MainTest(m)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user