Files
Archduino/internal/tui/state_test.go
MDietermann 4f7411ca95 refactor: retire tui.BuiltinThemes in favor of theming.List
Make internal/theming.List the single source of truth for themes:

- Drop tui.BuiltinThemes, tui.ThemeByID, and the NvChadTheme field on
  tui.Theme. tui.Theme is now a thin {ID, Name} display value.
- Wizard populates its dropdown from theming.List() and uses
  DisplayName for the label.
- neovim.resolvedTheme uses theming.Get (with theming.List()[0] as a
  fallback) instead of a caller-supplied []tui.Theme slice.
- neovim.New signature loses the themes []tui.Theme parameter; update
  cmd/archduino/main.go and all neovim tests to match.

Break the resulting neovim→theming import cycle (theming previously
imported neovim for WriteChadrc) by inverting the dependency:
theming exposes a ChadrcWriter function hook, and neovim registers
its WriteChadrc into it via package init. The theming test stubs
ChadrcWriter directly to exercise the chadrc-rewrite branch without
pulling neovim in and re-creating the cycle.

Delete the now-obsolete TestBuiltinThemesCarryNvChadName / TestThemeByID*
tests in internal/tui/state_test.go — their coverage lives in the
theming package's own tests.
2026-04-14 13:35:10 +02:00

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.List()[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)
}
}