Files
selfpost/internal/web/view/cards_order_test.go
T
mixandClaude Opus 5.5 eaa7de0754
test / test (push) Canceled after 0s
audit 4: findings of the two reviews
- Two inbound domains on one upstream could never change its TLS mode,
  each save refused for the other (medium): SetTransportAs changes the
  mode for every domain on the upstream when the one saving may change
  them all; a domain user who may not is refused with the mode, not the
  other tenant's domain name (security F1: the first version named it).
- A deletion's leftover DKIM key is removed by Resync (Reload
  configuration, a restore's first start) for names no domain has.
- The backup's write deadline moves before Check.
- hasUnsavedEdit skips password and file fields and compares a multiple
  select's options; htmx.config.timeout 30 s, so a refresh never answered
  ends and is tried again; a failed refresh's promise is handled.
- An empty filtered Outbound log says no message matches the filters.
- The dummy bcrypt hash is made at start; a DMARC part over 8 MiB is
  refused for its size like the other two limits.
- Health's Configuration box says what Reload writes (design first,
  32dfe4a).
- Docs: CHANGELOG, guide § Inbound, security.md (the shared upstream's
  mode, the profile form's "username taken"), architecture.md (owed to an
  address), the plan's notes corrected.
Tests: the shared upstream (service, handler), the leftover key, all eight
Health boxes ordered, the subject from before migration 0011, the new JS
cases.

Tested on the test server: go vet + go test of 25 packages, make e2e (all
pass, 636 s) on this tree.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 12:46:52 +03:00

72 lines
2.5 KiB
Go

package view
import (
"net/http"
"net/http/httptest"
"os"
"regexp"
"strings"
"testing"
)
// On a phone the cards layout shows its boxes in the order of their numbers,
// whichever stack they stand in: each box of the layout carries its number as
// data-order, and the stylesheet has a rule for it. Before, the stylesheet
// ordered by a box's place in its stack and knew four to a stack; a fifth
// landed out of place with nothing failing (owner, 2026-10-13).
func TestCardsBoxesCarryTheirNumberAsTheirOrder(t *testing.T) {
css, err := os.ReadFile("static/panel.css")
if err != nil {
t.Fatal(err)
}
box := regexp.MustCompile(`<div class="box[^"]*"[^>]*?(?: data-order="(\d+)")?>\s*<div class="sp-box-head"><span class="sp-no">(\d+)</span>`)
rec := httptest.NewRecorder()
kitEngine(t).Render(rec, http.StatusOK, "components", KitPage())
for name, page := range map[string]string{
"health": renderSignedIn(t, "health", healthFixture(false)),
"kit": rec.Body.String(),
} {
start := strings.Index(page, `<div class="columns sp-cards">`)
if start < 0 {
t.Fatalf("%s has no cards layout", name)
}
// The layout runs to the first page part after it that is not a box
// of it; its boxes are the numbered ones up to there.
region := page[start:]
if end := strings.Index(region, `<footer`); end > 0 {
region = region[:end]
}
found := 0
for _, m := range box.FindAllStringSubmatch(region, -1) {
order, no := m[1], strings.TrimLeft(m[2], "0")
if name == "kit" && found == 3 {
break // the kit's cards hold three numbered boxes; the rest of the page is other sections
}
found++
if order != no {
t.Errorf("%s: box %s carries data-order %q", name, m[2], order)
continue
}
if !strings.Contains(string(css), `.sp-cards [data-order="`+order+`"] { order: `+order+`; }`) {
t.Errorf("%s: panel.css has no rule for data-order %s", name, order)
}
}
if want := map[string]int{"health": 8, "kit": 3}[name]; found != want {
t.Errorf("%s: %d numbered boxes found in the cards layout, want %d", name, found, want)
}
}
}
// Outside the cards layout a box has no order: the attribute is the layout's.
func TestABoxOutsideCardsHasNoOrder(t *testing.T) {
if got := (Box{No: "03"}).Order(); got != "" {
t.Errorf("a box outside cards has order %q", got)
}
if got := (Box{No: "03", InCards: true}).Order(); got != "3" {
t.Errorf("a cards box 03 has order %q", got)
}
if got := (Box{Icon: "ti-x", InCards: true}).Order(); got != "" {
t.Errorf("a cards box without a number has order %q", got)
}
}