75 lines
1.9 KiB
Go
75 lines
1.9 KiB
Go
package tui
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/MDietermann/ArduinoArchSetup/internal/config"
|
|
"github.com/MDietermann/ArduinoArchSetup/internal/module"
|
|
"github.com/MDietermann/ArduinoArchSetup/internal/theming"
|
|
)
|
|
|
|
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 != theming.Default().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)
|
|
}
|
|
}
|
|
|