oficina / mapa Public

Clone
git clone https://amadan.net/oficina/mapa

Plain git — no account needed to clone.

Download

Download this file

1package mapa
2
3import (
4 "strings"
5 "testing"
6
7 "amadan.net/oficina/mapa/internal/mapa/locale"
8)
9
10// Every count the panel shows goes through rastrillo's number function
11// with the reader's locale (build note 85): the templates are cloned
12// per locale, each bound to its own localizer.
13func TestPanelCountsAreInTheReadersLocale(t *testing.T) {
14 items := make([]Linked, 1234)
15 for at := range items {
16 items[at] = Linked{Label: "A page", Href: "/p/x", Kind: KindPage}
17 }
18 data := map[string]any{"ID": "x", "Heading": "Linked from",
19 "Items": items, "Empty": "", "Target": ""}
20 for code, want := range map[string]string{"en-IE": "1,234",
21 "en-US": "1,234", "de": "1.234", "fr": "1\u202f234"} {
22 drawn, err := fragment(pagesIn[code]["page"], "mapa-panel-linked",
23 data)
24 if err != nil {
25 t.Fatal(err)
26 }
27 if !strings.Contains(string(drawn), "<small>"+want+"</small>") {
28 t.Errorf("%s: the count is not %q: %.200s", code, want, drawn)
29 }
30 }
31}
32
33// Every offered locale has its own templates, and a request outside
34// the router (a panic's error page) gets the default's.
35func TestEveryOfferedLocaleHasItsTemplates(t *testing.T) {
36 for _, code := range locale.Offered() {
37 if len(pagesIn[code]) != len(pages) {
38 t.Errorf("%s has %d pages of %d", code, len(pagesIn[code]),
39 len(pages))
40 }
41 }
42}
43
44// A stored format Mapa no longer offers is no choice: the field says
45// the browser's applies, as ownLocale does (review round 8, diff check).
46func TestAFormatNoLongerOfferedReadsAsUnset(t *testing.T) {
47 field := formatFor(Viewer{OwnLocale: "pt-PT"}, locale.Get("en-US"),
48 "2026-11-17")
49 if field.Hint != "until you choose, your browser's" ||
50 !field.Options[0].Selected {
51 t.Fatalf("a stale code reads as chosen: %+v", field)
52 }
53 for _, option := range field.Options[1:] {
54 if option.Selected {
55 t.Fatalf("%s is selected", option.Value)
56 }
57 }
58 if got := formatNotice(Viewer{OwnLocale: "pt-PT"}); got !=
59 "Saved. Dates, times and numbers follow your browser again." {
60 t.Fatalf("notice %q", got)
61 }
62}
63