Part E: the stale zero-toggle line tells the truth (v0.126.0)
- offboxWarningDisplay(lastWarning, toggledCount) — pure DISPLAY pick, no state mutation: a persisted 'nincs mentésre jelölt alkalmazás' run-result is replaced by 'A kijelölés módosult az utolsó futás óta — a következő távoli mentés már tartalmazza.' once ≥1 app is toggled; 0 toggled keeps the v0.123.0 honesty verbatim; every other warning (quota, partial) passes through untouched - replacement renders NEUTRAL (exception-color principle: reassurance, not deviation); the untouched original keeps the warn color - unit + render tests; red-proven (pick removed → 1-enabled case fails at both levels)
This commit is contained in:
@@ -653,10 +653,37 @@ func (s *Server) backupsOffboxData(data map[string]interface{}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
data["OffboxToggledCount"] = offboxToggled
|
data["OffboxToggledCount"] = offboxToggled
|
||||||
|
// Part E (v0.126.0): the LastWarning DISPLAY pick — never a state mutation.
|
||||||
|
if offboxTgt != nil {
|
||||||
|
data["OffboxWarningDisplay"] = offboxWarningDisplay(offboxTgt.LastWarning, offboxToggled)
|
||||||
|
} else {
|
||||||
|
data["OffboxWarningDisplay"] = ""
|
||||||
|
}
|
||||||
// SLICE 4 soft-quota usage bar (rendered only when a quota is set — shared model).
|
// SLICE 4 soft-quota usage bar (rendered only when a quota is set — shared model).
|
||||||
data["OffboxQuotaPct"] = backup.OffboxQuotaPercent(offboxTgt)
|
data["OffboxQuotaPct"] = backup.OffboxQuotaPercent(offboxTgt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// offboxStaleWarningMarker is the substring the zero-toggled offbox run writes into
|
||||||
|
// LastWarning (backup/offbox.go); offboxSelectionChangedLine replaces it once the
|
||||||
|
// selection has moved on.
|
||||||
|
const (
|
||||||
|
offboxStaleWarningMarker = "nincs mentésre jelölt alkalmazás"
|
||||||
|
offboxSelectionChangedLine = "A kijelölés módosult az utolsó futás óta — a következő távoli mentés már tartalmazza."
|
||||||
|
)
|
||||||
|
|
||||||
|
// offboxWarningDisplay picks what the Távoli mentés page shows for the persisted
|
||||||
|
// Offbox.LastWarning. A zero-toggled run records "Sikeres — nincs mentésre jelölt
|
||||||
|
// alkalmazás…"; once the customer HAS toggled apps that line is stale and misleading —
|
||||||
|
// replace it with the honest "selection changed, the next run covers it" note.
|
||||||
|
// Pure display logic: the persisted LastWarning is never touched, and every other
|
||||||
|
// warning (quota, partial failure) passes through verbatim.
|
||||||
|
func offboxWarningDisplay(lastWarning string, toggledCount int) string {
|
||||||
|
if toggledCount >= 1 && strings.Contains(lastWarning, offboxStaleWarningMarker) {
|
||||||
|
return offboxSelectionChangedLine
|
||||||
|
}
|
||||||
|
return lastWarning
|
||||||
|
}
|
||||||
|
|
||||||
// backupsHandler renders the Áttekintés page: storage overview, whole-guest Rendszermentés and
|
// backupsHandler renders the Áttekintés page: storage overview, whole-guest Rendszermentés and
|
||||||
// the status stat cards.
|
// the status stat cards.
|
||||||
func (s *Server) backupsHandler(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) backupsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
package web
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"gitea.dooplex.hu/admin/felhom-controller/internal/settings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// v0.126.0 Part E — the stale zero-toggle warning line tells the truth. Display-pick only:
|
||||||
|
// the persisted LastWarning is never mutated; the page swaps the stale "nincs mentésre
|
||||||
|
// jelölt alkalmazás" run-result for the selection-changed note once ≥1 app is toggled.
|
||||||
|
// COMPANION red-proof (recorded in REPORT): make offboxWarningDisplay return lastWarning
|
||||||
|
// unconditionally → TestOffboxWarningDisplay_Pick's 1-enabled case FAILS.
|
||||||
|
|
||||||
|
const staleZeroToggleWarning = "Sikeres — nincs mentésre jelölt alkalmazás volt a futáskor."
|
||||||
|
|
||||||
|
func TestOffboxWarningDisplay_Pick(t *testing.T) {
|
||||||
|
// warning + ≥1 enabled → the replacement line
|
||||||
|
if got := offboxWarningDisplay(staleZeroToggleWarning, 1); got != offboxSelectionChangedLine {
|
||||||
|
t.Errorf("stale warning + 1 toggled: got %q, want the selection-changed line", got)
|
||||||
|
}
|
||||||
|
// warning + 0 enabled → the original line, verbatim (the v0.123.0 honesty stays)
|
||||||
|
if got := offboxWarningDisplay(staleZeroToggleWarning, 0); got != staleZeroToggleWarning {
|
||||||
|
t.Errorf("stale warning + 0 toggled: got %q, want the original warning unchanged", got)
|
||||||
|
}
|
||||||
|
// any OTHER warning passes through regardless of toggles (quota, partial failure)
|
||||||
|
quota := "A tároló a keret 84%-át használja (42/50 GB)."
|
||||||
|
if got := offboxWarningDisplay(quota, 3); got != quota {
|
||||||
|
t.Errorf("non-stale warning must pass through verbatim, got %q", got)
|
||||||
|
}
|
||||||
|
// no warning → no line
|
||||||
|
if got := offboxWarningDisplay("", 2); got != "" {
|
||||||
|
t.Errorf("empty warning must stay empty, got %q", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestOffboxWarningDisplay_RemotePageRender(t *testing.T) {
|
||||||
|
// ≥1 toggled: the page shows the replacement, NOT the stale line.
|
||||||
|
data := appRowSplitData()
|
||||||
|
data["Offbox"] = &settings.OffboxTarget{
|
||||||
|
Enabled: true, Host: "nas.local", LastStatus: "ok", EscrowState: "escrowed",
|
||||||
|
LastWarning: staleZeroToggleWarning,
|
||||||
|
}
|
||||||
|
data["OffboxWarningDisplay"] = offboxWarningDisplay(staleZeroToggleWarning, 1)
|
||||||
|
html := renderBackupPage(t, "backups_remote", data)
|
||||||
|
if !strings.Contains(html, offboxSelectionChangedLine) {
|
||||||
|
t.Error("selection-changed note missing with 1 app toggled")
|
||||||
|
}
|
||||||
|
if strings.Contains(html, staleZeroToggleWarning) {
|
||||||
|
t.Error("the stale zero-toggle line still renders alongside the replacement")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 0 toggled: the original warning + the v0.123.0 zero-toggle hint, unchanged.
|
||||||
|
data = appRowSplitData()
|
||||||
|
data["OffboxApps"] = []OffboxAppRow{{Name: "calibre-web", DisplayName: "Calibre-Web", Slug: "calibre-web", Enabled: false}}
|
||||||
|
data["OffboxToggledCount"] = 0
|
||||||
|
data["Offbox"] = &settings.OffboxTarget{
|
||||||
|
Enabled: true, Host: "nas.local", LastStatus: "ok", EscrowState: "escrowed",
|
||||||
|
LastWarning: staleZeroToggleWarning,
|
||||||
|
}
|
||||||
|
data["OffboxWarningDisplay"] = offboxWarningDisplay(staleZeroToggleWarning, 0)
|
||||||
|
html = renderBackupPage(t, "backups_remote", data)
|
||||||
|
if !strings.Contains(html, staleZeroToggleWarning) {
|
||||||
|
t.Error("0 toggled: the original run warning must render unchanged")
|
||||||
|
}
|
||||||
|
if strings.Contains(html, offboxSelectionChangedLine) {
|
||||||
|
t.Error("0 toggled: the selection-changed note must NOT render")
|
||||||
|
}
|
||||||
|
if !strings.Contains(html, "Nincs távoli mentésre jelölt alkalmazás — jelölj ki legalább egyet.") {
|
||||||
|
t.Error("0 toggled: the v0.123.0 hint must stay")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -50,7 +50,9 @@
|
|||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if .Offbox.LastError}}<p class="form-hint" style="color:var(--crit)">Utolsó hiba: {{.Offbox.LastError}}</p>{{end}}
|
{{if .Offbox.LastError}}<p class="form-hint" style="color:var(--crit)">Utolsó hiba: {{.Offbox.LastError}}</p>{{end}}
|
||||||
{{if .Offbox.LastWarning}}<p class="form-hint" style="color:var(--warn)">{{.Offbox.LastWarning}}</p>{{end}}
|
{{/* Part E: display pick — a stale zero-toggle warning is replaced once the selection
|
||||||
|
changed (neutral color: the replacement is reassurance, not a deviation). */}}
|
||||||
|
{{if .OffboxWarningDisplay}}<p class="form-hint"{{if eq .OffboxWarningDisplay .Offbox.LastWarning}} style="color:var(--warn)"{{end}}>{{.OffboxWarningDisplay}}</p>{{end}}
|
||||||
{{if and .OffboxConfigured (ne .Offbox.EscrowState "escrowed")}}
|
{{if and .OffboxConfigured (ne .Offbox.EscrowState "escrowed")}}
|
||||||
<div class="card" style="border-left:3px solid var(--warn);margin:.75rem 0;padding:.75rem 1rem">
|
<div class="card" style="border-left:3px solid var(--warn);margin:.75rem 0;padding:.75rem 1rem">
|
||||||
<p class="form-hint" style="color:var(--warn);margin:0 0 .5rem">A távoli mentés a kulcs letétbe helyezésére vár — a mentés addig nem fut (így nem keletkezik visszaállíthatatlan másolat). Futtasd a letéti szertartást, majd erősítsd meg.</p>
|
<p class="form-hint" style="color:var(--warn);margin:0 0 .5rem">A távoli mentés a kulcs letétbe helyezésére vár — a mentés addig nem fut (így nem keletkezik visszaállíthatatlan másolat). Futtasd a letéti szertartást, majd erősítsd meg.</p>
|
||||||
|
|||||||
Reference in New Issue
Block a user