diff options
Diffstat (limited to 'internal/cli/cli_test.go')
| -rw-r--r-- | internal/cli/cli_test.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/internal/cli/cli_test.go b/internal/cli/cli_test.go index 5004af4..6fc5e0e 100644 --- a/internal/cli/cli_test.go +++ b/internal/cli/cli_test.go @@ -2,10 +2,14 @@ package cli import ( "bytes" + "net/http" + "net/http/httptest" "os" "path/filepath" "strings" "testing" + + "github.com/lukaszkasprzak/lectio/internal/liturgy" ) func TestHelp(t *testing.T) { @@ -189,6 +193,42 @@ func TestCleanPreferredOverUpdate(t *testing.T) { } } +// TestDayInfoHeaderShown exercises fetchAndPrint's day-info header end to +// end (via Run against a fixture server, matching internal/readings' +// TestLoadModernRoutes): the day's celebration name appears above the +// banner for the default (non-raw) render, and is entirely absent from +// --raw output, which stays text-only for piping. +func TestDayInfoHeaderShown(t *testing.T) { + html, err := os.ReadFile("../liturgy/testdata/2026-07-22.html") + if err != nil { + t.Fatal(err) + } + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Write(html) + })) + defer srv.Close() + liturgy.SetBaseURL(srv.URL + "/liturgia/%s/Ewangelia") + t.Setenv("XDG_CACHE_HOME", t.TempDir()) + t.Setenv("XDG_CONFIG_HOME", t.TempDir()) + + var out, errb bytes.Buffer + if code := Run([]string{"2026-07-22"}, nil, &out, &errb); code != 0 { + t.Fatalf("Run code=%d stderr=%q", code, errb.String()) + } + if !strings.Contains(out.String(), "Święto św. Marii Magdaleny") { + t.Errorf("stdout missing day-info header: %q", out.String()) + } + + out.Reset() + errb.Reset() + if code := Run([]string{"2026-07-22", "-r"}, nil, &out, &errb); code != 0 { + t.Fatalf("Run --raw code=%d stderr=%q", code, errb.String()) + } + if strings.Contains(out.String(), "Święto św. Marii Magdaleny") { + t.Errorf("--raw stdout should omit the day-info header: %q", out.String()) + } +} + // TestDateTokenAnyPosition exercises extractDate directly: the date token // is found regardless of where it appears among other flags. func TestDateTokenAnyPosition(t *testing.T) { |
