53 lines
2.3 KiB
Go
53 lines
2.3 KiB
Go
package web
|
|
|
|
import (
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"gitea.dooplex.hu/admin/felhom-controller/internal/settings"
|
|
)
|
|
|
|
// W13 (rehearsal 2026-10-20): the init page's mount-name box was empty („a household does not know what to type") and
|
|
// a press with an empty box did nothing visible — only the browser's tooltip, from `required`. The box now holds the
|
|
// next free hdd_N, the hint says „Hagyd így, ha nem tudod", the form is novalidate and the press answers a bad name
|
|
// with a visible sentence (the server checks the name again: mountWhere).
|
|
func TestW13_StorageInitSuggestsTheNextFreeNameAndNeverFailsSilently(t *testing.T) {
|
|
if got := nextFreeMountName(nil); got != "hdd_1" {
|
|
t.Fatalf("no drive: %q", got)
|
|
}
|
|
reg := []settings.StoragePath{{Path: "/mnt/hdd_1"}, {Path: "/mnt/hdd_3/"}, {Path: "/mnt/felhom-drives/nas"}, {Path: "/mnt/hdd_2", Decommissioned: true}}
|
|
if got := nextFreeMountName(reg); got != "hdd_4" {
|
|
t.Fatalf("hdd_1, hdd_2 (decommissioned) and hdd_3 taken: %q", got)
|
|
}
|
|
if got := nextFreeMountName(reg[:2]); got != "hdd_2" {
|
|
t.Fatalf("hdd_1 and hdd_3 taken: %q", got)
|
|
}
|
|
|
|
s := testServer(t)
|
|
s.loadTemplates()
|
|
if err := s.settings.AddStoragePath(settings.StoragePath{Path: "/mnt/hdd_1"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, page := range []string{"storage_init", "storage_attach"} {
|
|
rr := httptest.NewRecorder()
|
|
s.storageWizardPageHandler(rr, httptest.NewRequest("GET", "/storage/init", nil), page)
|
|
body := rr.Body.String()
|
|
if !strings.Contains(body, `id="mount-name" class="form-control" placeholder="hdd_1" value="hdd_2"`) {
|
|
t.Errorf("%s: the mount name is not pre-filled with the next free name", page)
|
|
}
|
|
if !strings.Contains(body, "Hagyd így, ha nem tudod.") {
|
|
t.Errorf("%s: the hint does not say „Hagyd így, ha nem tudod.”", page)
|
|
}
|
|
// THE CONSEQUENCE: no browser-only refusal — the form never lets the browser swallow the press, and the
|
|
// press has a visible sentence for a bad name.
|
|
if !strings.Contains(body, `-form" novalidate onsubmit=`) {
|
|
t.Errorf("%s: the form is not novalidate — an empty name is refused by a tooltip only", page)
|
|
}
|
|
if !strings.Contains(body, "var bad=mountNameProblem();") || !strings.Contains(body, `id="mount-name-error"`) ||
|
|
!strings.Contains(body, "Írj be egy csatlakoztatási nevet.") {
|
|
t.Errorf("%s: a bad name has no visible answer", page)
|
|
}
|
|
}
|
|
}
|