mirror of
https://github.com/shokinn/hosts-go.git
synced 2025-08-23 08:33:02 +00:00
feat: begin tui implementation
This commit is contained in:
parent
b81f11f711
commit
1b66db10e2
9 changed files with 200 additions and 154 deletions
30
tests/tui_test.go
Normal file
30
tests/tui_test.go
Normal 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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue