package web import ( "net/http" "net/http/httptest" "strings" "testing" "time" "gitea.dooplex.hu/admin/felhom-controller/internal/settings" ) // R-365 follow-up: at 0 days left the reminder bar's `{{if .RecoveryAbandonDays}}` is false, so a // countdown whose due moment had PASSED fell back to the undecided-box reminder text — the deletion // vanished from the bar on the very day it is due — and offered „Ne emlékeztessen újra" over it. The // consequence asserted through the real data path (addRecoveryBanner, reading a real countdown from // settings) and the real layout: the bar says the deletion is due since the date, and offers no // reminder opt-out; a running countdown (negative control) still says „N nap múlva". func TestR365_BannerSaysDueAtZeroDays(t *testing.T) { render := func(t *testing.T, due time.Time) string { f := newRecoveryFixture(t) if err := f.sett.SetOffboxTarget(&settings.OffboxTarget{ Enabled: true, Host: "nas.local", Port: 22, User: "felhom", RepoPath: "/srv/repo", Schedule: "daily", EscrowState: "escrowed", AbandonAt: due.UTC().Format(time.RFC3339), AbandonStartedAt: due.Add(-30 * 24 * time.Hour).UTC().Format(time.RFC3339), }); err != nil { t.Fatal(err) } f.s.recoveryInterrupts() // advances the situation's epoch, exactly as the landing page does rr := httptest.NewRecorder() f.s.backupsRemoteHandler(rr, httptest.NewRequest(http.MethodGet, "/backups/remote", nil)) body := rr.Body.String() i := strings.Index(body, `alert-banner alert-banner-warning`) if i < 0 { t.Fatalf("setup: the reminder bar did not render (status %d)", rr.Code) } j := strings.Index(body[i:], "\n") if j < 0 { j = len(body) - i } return body[i : i+j] } overdue := time.Now().Add(-20 * time.Hour) bar := render(t, overdue) if !strings.Contains(bar, "óta esedékes") || !strings.Contains(bar, overdue.UTC().Format("2006-01-02")) { t.Errorf("R-365: at 0 days the bar does not say the deletion is due:\n%s", bar) } if strings.Contains(bar, "remind-optout") { t.Errorf("R-365: at 0 days the bar offers to stop reminders over a due deletion") } bar = render(t, time.Now().Add(2*24*time.Hour+time.Hour)) if !strings.Contains(bar, "nap múlva") || strings.Contains(bar, "óta esedékes") { t.Errorf("a running countdown must keep its „N nap múlva” sentence:\n%s", bar) } }