A notice is now a closed Go value, notice.Notice, in a package that imports nothing of the console, rendered by one template part. It carries one of five tones named by meaning (Problem, Warning, Done, Information, Preview), its words as escaped runs (plain, strong, code), an optional link, an optional action that posts, a body only the console's own templates fill, and an optional close route. The part sets the glyph, the hidden "Error: " or "Warning: " a screen reader hears, and the role: alert for a Problem, status for the rest. A box takes its size from where it sits, full on a page and compact inside a card, a modal or a form's box; a line has no box. The preview tone is a pale fill with a 1px dashed edge, worn only by the form part's preview box and the Rows tray. Every alert at HEAD renders through the part: 83 in 49 files, plus the status lines and the checkout refusals. The 29 visible "Error:" prefixes go. A notice is closable only when its owner records the closing on its own row; the organization types error loses the close button that recorded nothing. The raw-notice lint refuses alert markup and alert roles outside the part, in templates and Go strings. The toasts move into one shared partial on every layout, member pages gain the load-time flash, the error toast stays until it is closed, the filler-copy lint reads the console's own scripts, and three toast strings drop "Please". The no-JS lookup's no-match answered 500 and now renders its notice. The organization type card showed a refused default change twice and now shows it once, in the form. The tier reorder preview's failed read moves to the form's own slot, outside the preview's status region. Closes #167 and #22.
45 lines
1.4 KiB
Go
45 lines
1.4 KiB
Go
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
|
|
// SPDX-FileCopyrightText: 2025-2026 Christian Galo
|
|
|
|
package server
|
|
|
|
import (
|
|
"log/slog"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.coopcloud.tech/wiki-cafe/member-console/internal/testkit/htmltest"
|
|
)
|
|
|
|
// TestRenderFailureAnswersAProblemNotice pins that a template that fails
|
|
// answers 500 with the Problem notice, not a hand-written alert.
|
|
func TestRenderFailureAnswersAProblemNotice(t *testing.T) {
|
|
set, err := OperatorSet(t).Clone()
|
|
if err != nil {
|
|
t.Fatalf("Clone: %v", err)
|
|
}
|
|
if _, err := set.Parse(`{{ define "failing" }}{{ .NoSuchField }}{{ end }}`); err != nil {
|
|
t.Fatalf("Parse: %v", err)
|
|
}
|
|
st := NewSafeTemplates(set, slog.New(slog.DiscardHandler))
|
|
rec := httptest.NewRecorder()
|
|
st.Render(rec, "failing", struct{}{})
|
|
|
|
body := rec.Body.String()
|
|
page := htmltest.Parse(t, body)
|
|
notices := page.All(`[role="alert"]`)
|
|
if rec.Code != http.StatusInternalServerError || len(notices) != 1 || !strings.Contains(notices[0].Text(), "Failed to render content. Try again.") {
|
|
t.Fatalf("the failed render answered %d:\n%s", rec.Code, body)
|
|
}
|
|
hidden := notices[0].All(".visually-hidden")
|
|
visible := notices[0].Text()
|
|
for _, h := range hidden {
|
|
visible = strings.Replace(visible, h.Text(), "", 1)
|
|
}
|
|
if strings.Contains(visible, "Error:") {
|
|
t.Errorf("the failed render answered %d:\n%s", rec.Code, body)
|
|
}
|
|
}
|