hosts-go/tests/tui_test.go

47 lines
1.1 KiB
Go

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)
}
func TestViewModeStatusBar(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)
nm, _ := m.Update(tea.WindowSizeMsg{Width: 80, Height: 20})
m = nm.(tui.Model)
view := m.View()
assert.Contains(t, view, "VIEW MODE")
assert.Contains(t, view, "[✓] localhost")
assert.Contains(t, view, "[ ] example.com")
}