feat(tui): add shared WizardState seeded from config and registry
This commit is contained in:
72
internal/tui/state_test.go
Normal file
72
internal/tui/state_test.go
Normal file
@@ -0,0 +1,72 @@
|
||||
package tui
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/MDietermann/ArduinoArchSetup/internal/config"
|
||||
"github.com/MDietermann/ArduinoArchSetup/internal/module"
|
||||
)
|
||||
|
||||
type fakeModule struct{ id, name, desc string }
|
||||
|
||||
func (f fakeModule) Meta() module.Meta {
|
||||
return module.Meta{ID: f.id, Name: f.name, Description: f.desc}
|
||||
}
|
||||
func (f fakeModule) Detect(context.Context) (module.State, error) { return nil, nil }
|
||||
func (f fakeModule) Plan(context.Context, module.State) (module.Plan, error) {
|
||||
return module.Plan{}, nil
|
||||
}
|
||||
func (f fakeModule) Apply(context.Context, module.Plan, module.Reporter) error { return nil }
|
||||
func (f fakeModule) Verify(context.Context) error { return nil }
|
||||
|
||||
func TestNewWizardStatePreTicksAllByDefault(t *testing.T) {
|
||||
reg := module.NewRegistry()
|
||||
_ = reg.Register(fakeModule{id: "a", name: "Alpha"})
|
||||
_ = reg.Register(fakeModule{id: "b", name: "Bravo"})
|
||||
|
||||
s := NewWizardState(config.Config{}, reg)
|
||||
if len(s.Modules) != 2 {
|
||||
t.Fatalf("modules = %d", len(s.Modules))
|
||||
}
|
||||
for _, m := range s.Modules {
|
||||
if !m.Selected {
|
||||
t.Errorf("%s not selected", m.ID)
|
||||
}
|
||||
}
|
||||
if s.ThemeID != BuiltinThemes[0].ID {
|
||||
t.Errorf("theme = %q", s.ThemeID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewWizardStateRespectsDisabled(t *testing.T) {
|
||||
reg := module.NewRegistry()
|
||||
_ = reg.Register(fakeModule{id: "a"})
|
||||
_ = reg.Register(fakeModule{id: "b"})
|
||||
|
||||
s := NewWizardState(config.Config{DisabledModules: []string{"a"}}, reg)
|
||||
for _, m := range s.Modules {
|
||||
switch m.ID {
|
||||
case "a":
|
||||
if m.Selected {
|
||||
t.Error("a should be unticked")
|
||||
}
|
||||
case "b":
|
||||
if !m.Selected {
|
||||
t.Error("b should be ticked")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSelectedIDsOnlyReturnsChecked(t *testing.T) {
|
||||
s := WizardState{Modules: []ModuleChoice{
|
||||
{ID: "a", Selected: true},
|
||||
{ID: "b", Selected: false},
|
||||
{ID: "c", Selected: true},
|
||||
}}
|
||||
got := s.SelectedIDs()
|
||||
if len(got) != 2 || got[0] != "a" || got[1] != "c" {
|
||||
t.Fatalf("got %v", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user