Files
cgalo5758 bbbd529b6b Give the invoice detail and a domain claim's records pages of their own, and refuse a back link
Two member views opened in place of a region and offered "← Back to …"
to return. The invoice detail swapped into the Billing page under the
"Billing" title, and a claim's DNS records swapped into whatever opened
them; on the dashboard, "Back to domains" left the whole claims table
where the pending-domain notice had been.

Both are now member pages with their own trail. An invoice is at
/billing/invoices/{id} ("Home / Billing / Invoice 0042"), and each
number in the Billing list links to it. A claim's records are at
/domains/claims/{id} ("Home / {domain}"), where the status still
refreshes every 5 seconds and Check now and Cancel verification work in
place. The dashboard notice links to it, and in the sites card's claims
table each domain is the link, replacing the DNS records and Details
buttons. A foreign, unknown or malformed id answers the styled 404 page;
a failed read answers the styled 500 and is logged.

On a page below its rail entry, the rail marks that entry as the
section, not as the current page, so screen readers hear one current
page. A long domain wraps in the title and the trail, breaking at its
dots first. In the records table the purpose cell and the status badges
wrap, so the names keep their width at 390px; the table had been about
11,000px tall there. The claim page loads the copy script, whose buttons
had no handler unless the FedWiki card's script was loaded.

The lint gains back-link: "Back to" or a left-pointing mark in any
template's text or attributes fails, and comments are not read. The
operator invoice requirement that still asked for a back affordance now
asks for its trail.

Closes #321.
2026-11-06 01:35:51 -06:00

72 lines
2.9 KiB
Go

// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
// SPDX-FileCopyrightText: 2025-2026 Christian Galo
package server
import (
"strings"
"testing"
"git.coopcloud.tech/wiki-cafe/member-console/internal/testkit/htmltest"
)
// TestEveryLayoutRendersTheSharedToasts pins page-anatomy "Toasts are one
// shared partial on every surface": every layout holds one error toast and
// one success toast, from partials/shell_toasts.html.
func TestEveryLayoutRendersTheSharedToasts(t *testing.T) {
for _, r := range []struct {
name string
html func(t *testing.T) string
}{
{"dashboard", func(t *testing.T) string { return Render(t, MemberSet(t), "index.html", IndexPageData{}) }},
{"products", func(t *testing.T) string { return Render(t, MemberSet(t), "products.html", ProductsPageData{}) }},
{"billing", func(t *testing.T) string { return Render(t, MemberSet(t), "billing.html", BillingPageData{}) }},
{"invoice page", func(t *testing.T) string {
return Render(t, MemberSet(t), "billing_invoice.html", MemberInvoicePageData{})
}},
{"claim page", func(t *testing.T) string {
return Render(t, MemberSet(t), "domain_claim.html", MemberDomainClaimPageData{Claim: MemberDomainClaimData{Domain: "wiki.example.org"}})
}},
{"operator page", func(t *testing.T) string { return Render(t, OperatorSet(t), "operator.html", OperatorPageData{}) }},
} {
t.Run(r.name, func(t *testing.T) {
page := htmltest.Parse(t, r.html(t))
if e, s := page.Count("#errorToast"), page.Count("#successToast"); e != 1 || s != 1 {
t.Errorf("%s: %d error toasts and %d success toasts, want one each", r.name, e, s)
}
})
}
}
// TestMemberPageFlashesOnLoad pins that Shell.Flash is the load-time success
// message on both surfaces: a non-empty one is pre-rendered into
// #successToast with data-show-on-load, an empty one leaves the toast unshown.
func TestMemberPageFlashesOnLoad(t *testing.T) {
for _, r := range []struct {
name string
html func(t *testing.T) string
marked bool
text string
}{
{"dashboard with a flash", func(t *testing.T) string {
return Render(t, MemberSet(t), "index.html", IndexPageData{Shell: Shell{Surface: ShellMember, Flash: "Saved."}})
}, true, "Saved."},
{"dashboard without a flash", func(t *testing.T) string {
return Render(t, MemberSet(t), "index.html", IndexPageData{Shell: Shell{Surface: ShellMember}})
}, false, "Done."},
{"operator page with a flash", func(t *testing.T) string {
return Render(t, OperatorSet(t), "operator.html", OperatorPageData{FlashSuccess: "Saved."})
}, true, "Saved."},
} {
t.Run(r.name, func(t *testing.T) {
body := r.html(t)
toast := htmltest.Parse(t, body).One(t, "#successToast")
_, marked := toast.Attr("data-show-on-load")
text := strings.TrimSpace(toast.One(t, "#successToastBody").Text())
if marked != r.marked || text != r.text {
t.Errorf("%s: the success toast reads %q with data-show-on-load %t:\n%s", r.name, text, marked, toast.HTML())
}
})
}
}