diff options
Diffstat (limited to 'internal/web/server_test.go')
| -rw-r--r-- | internal/web/server_test.go | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/internal/web/server_test.go b/internal/web/server_test.go index 25d21f4..32ee412 100644 --- a/internal/web/server_test.go +++ b/internal/web/server_test.go @@ -227,6 +227,53 @@ func TestServer(t *testing.T) { }) } +// TestRenderOrErrorNoSectionsLang checks the "no readings at all for this +// day" fragment (finding §1) follows lang instead of always being Polish. +func TestRenderOrErrorNoSectionsLang(t *testing.T) { + html := string(renderOrError(nil, nil, "new", "horizontal", "en", nil)) + if !strings.Contains(html, "no readings for this day") { + t.Errorf("en renderOrError(no secs) = %q, want it to contain %q", html, "no readings for this day") + } + if strings.Contains(html, "czyta") { + t.Errorf("en renderOrError(no secs) should not carry Polish wording: %q", html) + } + + html = string(renderOrError(nil, nil, "new", "horizontal", "pl", nil)) + if !strings.Contains(html, "brak czytań na ten dzień") { + t.Errorf("pl renderOrError(no secs) = %q, want it to contain %q", html, "brak czytań na ten dzień") + } +} + +// TestIndexHTMLLangAttribute checks index.html's <html lang="..."> follows +// cfg.UILanguage (finding §6) instead of being hardcoded "pl". +func TestIndexHTMLLangAttribute(t *testing.T) { + html, err := os.ReadFile("../liturgy/testdata/2026-07-22.html") + if err != nil { + t.Fatal(err) + } + fixtureServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Write(html) + })) + defer fixtureServer.Close() + liturgy.SetBaseURL(fixtureServer.URL + "/liturgia/%s/Ewangelia") + t.Setenv("XDG_CACHE_HOME", t.TempDir()) + + cfg := config.Default() + cfg.UILanguage = "en" + rec := httptest.NewRecorder() + NewServer(cfg).ServeHTTP(rec, httptest.NewRequest("GET", "/?date=2026-07-22&v=wuj", nil)) + if !strings.Contains(rec.Body.String(), `<html lang="en">`) { + t.Errorf(`en index page missing <html lang="en">: %q`, rec.Body.String()[:min(400, rec.Body.Len())]) + } + + cfg.UILanguage = "pl" + rec = httptest.NewRecorder() + NewServer(cfg).ServeHTTP(rec, httptest.NewRequest("GET", "/?date=2026-07-22&v=wuj", nil)) + if !strings.Contains(rec.Body.String(), `<html lang="pl">`) { + t.Errorf(`pl index page missing <html lang="pl">: %q`, rec.Body.String()[:min(400, rec.Body.Len())]) + } +} + // TestChooseListener exercises chooseListener's port-selection logic // directly (no HTTP serving): port==0 prefers defaultWebPort (1099) and // falls back to a free OS port when 1099 is taken, and a non-zero port is |
