package web import ( "bytes" "strings" "testing" "gitea.dooplex.hu/admin/felhom-controller/internal/stacks" ) // v0.280.0 — the app page's two new presses render only where they belong (one render per branch: a seam built // and never wired is this project's commonest silent defect). ASCII fragments of the Hungarian copy. func renderAppInfoWith(t *testing.T, extra map[string]interface{}) string { t.Helper() s := securityHarness(t) s.loadTemplates() data := map[string]interface{}{ "Page": "stacks", "Title": "T", "Domain": "example.hu", "Stack": stacks.Stack{Name: "gapp", Deployed: true, State: "running"}, "Meta": stacks.Metadata{DisplayName: "G", Slug: "gapp"}, "AppInfo": stacks.AppInfo{Tagline: "t", DefaultCreds: "admin / admin123"}, "HasAppInfo": true, "CSRFToken": "tok", } for k, v := range extra { data[k] = v } var buf bytes.Buffer if err := s.tmpl.ExecuteTemplate(&buf, "app_info", data); err != nil { t.Fatalf("render: %v", err) } return buf.String() } func TestSetupGatePage_TheCardAndItsButton(t *testing.T) { closedNoProbe := renderAppInfoWith(t, map[string]interface{}{"SetupGateClosed": true}) if !strings.Contains(closedNoProbe, `id="setup-gate-card"`) || !strings.Contains(closedNoProbe, "/apps/gapp/setup-gate/open") || !strings.Contains(closedNoProbe, "Kész, beállítottam") { t.Fatal("closed, no probe: the card or its button is missing") } closedProbe := renderAppInfoWith(t, map[string]interface{}{"SetupGateClosed": true, "SetupGateHasProbe": true}) // v0.281.0: a probe app has the press too — the server asks the probe before it opens (TestSetupGateButton_*). if !strings.Contains(closedProbe, `id="setup-gate-card"`) || !strings.Contains(closedProbe, "/apps/gapp/setup-gate/open") || !strings.Contains(closedProbe, "magától észreveszi") { t.Fatal("closed with a probe: want the card, the 'notices it by itself' line and the press") } if open := renderAppInfoWith(t, nil); strings.Contains(open, `id="setup-gate-card"`) { t.Fatal("an app with no closed gate shows the gate card") } } func TestKnownLoginPage_TheChangedItButton(t *testing.T) { warn := renderAppInfoWith(t, map[string]interface{}{"KnownLoginLine": "This app starts with a known, shared password: admin / admin123."}) if !strings.Contains(warn, "/apps/gapp/default-login/changed") || !strings.Contains(warn, "Megv") { t.Fatal("the default is named, but there is no 'I changed it' press") } if plain := renderAppInfoWith(t, nil); strings.Contains(plain, "/apps/gapp/default-login/changed") { t.Fatal("'I changed it' shown with no default named") } if replaced := renderAppInfoWith(t, map[string]interface{}{"DefaultLoginReplaced": true, "KnownLoginLine": ""}); strings.Contains(replaced, "admin / admin123") { t.Fatal("the default card is still shown after it was replaced") } }