Validate render identity and daypart fallbacks
This commit is contained in:
@@ -704,6 +704,26 @@ func TestRenderDaypartTemplatesUseRichHelperFields(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderTodayUsesDaypartFallbackWhenRowsAreNotDisplayable(t *testing.T) {
|
||||
rendered, err := Render("today", testTodayRenderContext{
|
||||
Report: testTodayReportContext{Title: "Today", ForecastDateLabel: "Monday, June 15, 2026"},
|
||||
GeneratedText: testTomorrowGeneratedText{Summary: "Today summary."},
|
||||
Modules: testTodayModules{Dayparts: []testTomorrowDaypart{
|
||||
{Key: "morning", Summary: testDaypartSummary{DisplayName: "Morning"}},
|
||||
}},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Render() error = %v", err)
|
||||
}
|
||||
text := string(rendered)
|
||||
if !strings.Contains(text, "## Daypart Forecast\n- No daypart forecast details are available.") {
|
||||
t.Fatalf("rendered template missing daypart fallback:\n%s", text)
|
||||
}
|
||||
if strings.Contains(text, "- **Morning:**") {
|
||||
t.Fatalf("rendered template included an unavailable daypart row:\n%s", text)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderTomorrowOmitsPrecipitationTimingWithoutWindows(t *testing.T) {
|
||||
rendered, err := Render("tomorrow", testTomorrowRenderContext{
|
||||
Report: testTomorrowReportContext{
|
||||
@@ -1013,6 +1033,15 @@ type testTodayModules struct {
|
||||
TodayPlanning *testTodayPlanning
|
||||
}
|
||||
|
||||
func (modules testTodayModules) HasDaypartDetails() bool {
|
||||
for _, daypart := range modules.Dayparts {
|
||||
if daypart.Summary.DominantConditionDisplay != "" || daypart.Summary.DominantCondition != "" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type testDailyModules struct {
|
||||
Dayparts []testDailyDaypart
|
||||
PrecipTiming *testPrecipTiming
|
||||
|
||||
Reference in New Issue
Block a user