feat(tui): add six-screen Huh wizard for installer input
This commit is contained in:
74
internal/tui/wizard/wizard_test.go
Normal file
74
internal/tui/wizard/wizard_test.go
Normal file
@@ -0,0 +1,74 @@
|
||||
package wizard
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/MDietermann/ArduinoArchSetup/internal/module"
|
||||
"github.com/MDietermann/ArduinoArchSetup/internal/modules/hello"
|
||||
"github.com/MDietermann/ArduinoArchSetup/internal/tui"
|
||||
)
|
||||
|
||||
func TestSyncSelected(t *testing.T) {
|
||||
orig := []tui.ModuleChoice{
|
||||
{ID: "a", Selected: false},
|
||||
{ID: "b", Selected: true},
|
||||
{ID: "c", Selected: true},
|
||||
}
|
||||
got := syncSelected(orig, []string{"a", "c"})
|
||||
want := map[string]bool{"a": true, "b": false, "c": true}
|
||||
for _, m := range got {
|
||||
if m.Selected != want[m.ID] {
|
||||
t.Errorf("%s selected=%v, want %v", m.ID, m.Selected, want[m.ID])
|
||||
}
|
||||
}
|
||||
if orig[0].Selected {
|
||||
t.Error("orig mutated")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderPlanWithHello(t *testing.T) {
|
||||
reg := module.NewRegistry()
|
||||
_ = reg.Register(hello.Module{Path: t.TempDir() + "/marker"})
|
||||
out := renderPlan(context.Background(), reg, []string{"hello"})
|
||||
if !strings.Contains(out, "hello") {
|
||||
t.Fatalf("output missing hello: %q", out)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderPlanEmpty(t *testing.T) {
|
||||
if got := renderPlan(context.Background(), module.NewRegistry(), nil); got != "No modules selected." {
|
||||
t.Fatalf("got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseIntClamp(t *testing.T) {
|
||||
cases := map[string]int{
|
||||
"": 1,
|
||||
" ": 1,
|
||||
"abc": 1,
|
||||
"0": 1,
|
||||
"-5": 1,
|
||||
"3": 3,
|
||||
"12": 12,
|
||||
}
|
||||
for in, want := range cases {
|
||||
got, _ := parseIntClamp(in, 1)
|
||||
if got != want {
|
||||
t.Errorf("parseIntClamp(%q) = %d, want %d", in, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunCancelledContextReturnsNoConfirmation(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
_, confirmed, err := Run(ctx, module.NewRegistry(), tui.WizardState{})
|
||||
if err != nil && err != context.Canceled {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
}
|
||||
if confirmed {
|
||||
t.Fatal("confirmed=true on cancelled context")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user