oficina / fichas Public

LU17 over HTTP: the reader's locale from the browser only, and dates in the reader's locale, mutation-checked

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 781f47c1d901ce3ae908dfe9184ba90f20a51057 parent 7f0f284
1 file changed, +50 −0
  • internal/fichastest/edit_routes_test.go +50 −0
diff --git a/internal/fichastest/edit_routes_test.go b/internal/fichastest/edit_routes_test.go
index c7d294f..5af3cac 100644
--- a/internal/fichastest/edit_routes_test.go
+++ b/internal/fichastest/edit_routes_test.go
@@ -396,3 +396,53 @@ func TestTheFoldIsACookieOnly(t *testing.T) {
t.Fatal("a folded rail is not drawn folded")
}
}
+
+// LU17, which locale (§6.8, as Mapa's build note 85): the browser's
+// Accept-Language among the six offered, a region falling to its
+// language, another English to the team's; no path prefix and no
+// rastrillo cookie.
+//
+// Mutation, 2026-11-17: negotiating with rastrillo's middleware rules
+// (honouring the rastrillo_locale cookie) failed the cookie case.
+func TestTheReadersLocaleComesFromTheBrowserOnly(t *testing.T) {
+ r := newEditRig(t)
+ r.card(t, map[string]string{fichas.FieldName: "Cnoc"})
+ for header, want := range map[string]string{
+ "de-AT,de;q=0.9": "de", "fr-CA": "fr", "en-AU": "en-IE", "en": "en-IE", "en-US,en;q=0.8": "en",
+ "ja,pt-BR": "en-IE", "": "en-IE", "es-MX;q=0.4, en-GB;q=0.9": "en-GB",
+ } {
+ if body := getAs(t, r.h, "/", header).Body.String(); !strings.Contains(body, `<body data-locale="`+want+`">`) {
+ t.Errorf("Accept-Language %q: want the %s format", header, want)
+ }
+ }
+ req := httptest.NewRequest(http.MethodGet, "/", nil)
+ req.Header.Set("Accept-Language", "en-IE")
+ req.AddCookie(&http.Cookie{Name: "rastrillo_locale", Value: "de"})
+ rec := httptest.NewRecorder()
+ r.h.ServeHTTP(rec, req)
+ if !strings.Contains(rec.Body.String(), `<body data-locale="en-IE">`) {
+ t.Error("rastrillo's locale cookie outranked the browser's header")
+ }
+ if got := getAs(t, r.h, "/de/t/t_customer", "de").Code; got != http.StatusNotFound {
+ t.Errorf("a /de/ prefix answered %d; it is no route", got)
+ }
+}
+
+// LU17, dates: a date and a moment are written as the reader's locale
+// writes them, by Mapa's patterns.
+func TestDatesAreWrittenInTheReadersLocale(t *testing.T) {
+ r := newEditRig(t)
+ id := r.card(t, map[string]string{fichas.FieldName: "Cnoc", fichas.FieldNextAction: "2030-03-04"})
+ for lang, want := range map[string]string{
+ "en-IE": "4 March 2030", "en-US": "March 4, 2030", "de": "4. März 2030", "fr": "4 mars 2030", "es": "4 de marzo de 2030",
+ } {
+ list := getAs(t, r.h, "/", lang).Body.String()
+ if !strings.Contains(list, `title="`+want+`">`+want+`</time>`) {
+ t.Errorf("%s: the table does not write the next action as %q", lang, want)
+ }
+ hist := getAs(t, r.h, cardPath(id)+"/history", lang).Body.String()
+ if lang == "en-US" && !strings.Contains(hist, "PM\"") && !strings.Contains(hist, "AM\"") {
+ t.Errorf("en-US: History's times are not 12-hour")
+ }
+ }
+}