feat: begin tui implementation

This commit is contained in:
Philip Henning 2025-08-13 14:39:27 +02:00
parent b81f11f711
commit 1b66db10e2
9 changed files with 200 additions and 154 deletions

30
tests/tui_test.go Normal file
View file

@ -0,0 +1,30 @@
package tests
import (
"strings"
"testing"
"hosts-go/internal/core"
"hosts-go/internal/tui"
tea "github.com/charmbracelet/bubbletea"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestModelSelection(t *testing.T) {
sample := `127.0.0.1 localhost
192.168.1.10 example.com`
lines := strings.Split(sample, "\n")
hf, _, err := core.ParseHostsContent(lines)
require.NoError(t, err)
m := tui.NewModel(hf)
require.NotNil(t, m.SelectedEntry())
assert.Equal(t, "localhost", m.SelectedEntry().Hostname)
// Move selection down
nm, _ := m.Update(tea.KeyMsg{Type: tea.KeyDown})
m = nm.(tui.Model)
assert.Equal(t, "example.com", m.SelectedEntry().Hostname)
}