aboutsummaryrefslogtreecommitdiffstats
path: root/tui
diff options
context:
space:
mode:
authorAdam Mathes <adam@adammathes.com>2026-02-12 21:35:46 -0800
committerAdam Mathes <adam@adammathes.com>2026-02-12 21:35:46 -0800
commitde96851d8eb0a0b45d7bf0cee67339fea54349f0 (patch)
treed9ca55835743e2254732ea68a674e7007f3554eb /tui
parent8a8f516ebd1115eed6256cd1b60be6393fd42c26 (diff)
downloadneko-de96851d8eb0a0b45d7bf0cee67339fea54349f0.tar.gz
neko-de96851d8eb0a0b45d7bf0cee67339fea54349f0.tar.bz2
neko-de96851d8eb0a0b45d7bf0cee67339fea54349f0.zip
wip: tui updates (buggy)
Diffstat (limited to 'tui')
-rw-r--r--tui/tui_test.go68
1 files changed, 68 insertions, 0 deletions
diff --git a/tui/tui_test.go b/tui/tui_test.go
index de9caf0..f34707f 100644
--- a/tui/tui_test.go
+++ b/tui/tui_test.go
@@ -1,14 +1,41 @@
package tui
import (
+ "path/filepath"
"strings"
"testing"
+ "adammathes.com/neko/config"
+ "adammathes.com/neko/models"
"adammathes.com/neko/models/feed"
"adammathes.com/neko/models/item"
tea "github.com/charmbracelet/bubbletea"
)
+func setupTestDB(t *testing.T) {
+ t.Helper()
+ config.Config.DBFile = filepath.Join(t.TempDir(), "test.db")
+ models.InitDB()
+ t.Cleanup(func() {
+ if models.DB != nil {
+ models.DB.Close()
+ }
+ })
+}
+
+func seedData(t *testing.T) {
+ t.Helper()
+ f := &feed.Feed{Url: "http://example.com", Title: "Test Feed", Category: "tech"}
+ f.Create()
+
+ i := &item.Item{
+ Title: "Test Item",
+ Url: "http://example.com/1",
+ FeedId: f.Id,
+ }
+ i.Create()
+}
+
func TestNewModel(t *testing.T) {
m := NewModel()
if m.state != viewFeeds {
@@ -89,4 +116,45 @@ func TestStateTransitions(t *testing.T) {
if v := tm5m.View(); !strings.Contains(v, "Test Item") {
t.Error("View should contain Item title in content view")
}
+
+ // Test scrolling in content view
+ // Scroll down
+ tmS1, _ := tm5m.Update(tea.KeyMsg{Type: tea.KeyDown})
+ // Home/End
+ tmS2, _ := tmS1.(Model).Update(tea.KeyMsg{Type: tea.KeyEnd})
+ tmS3, _ := tmS2.(Model).Update(tea.KeyMsg{Type: tea.KeyHome})
+
+ if tmS3.(Model).state != viewContent {
+ t.Errorf("Should stay in viewContent, got %v", tmS3.(Model).state)
+ }
+}
+
+func TestTuiCommands(t *testing.T) {
+ setupTestDB(t)
+ seedData(t)
+
+ m := NewModel()
+ cmd := m.Init()
+ if cmd == nil {
+ t.Fatal("Init should return a command")
+ }
+
+ msg := loadFeeds()
+ feeds, ok := msg.(feedsMsg)
+ if !ok || len(feeds) == 0 {
+ t.Errorf("loadFeeds should return feedsMsg, got %T", msg)
+ }
+
+ msg2 := loadItems(feeds[0].Id)()
+ _, ok = msg2.(itemsMsg)
+ if !ok {
+ t.Errorf("loadItems should return itemsMsg, got %T", msg2)
+ }
+}
+
+func TestItemString(t *testing.T) {
+ is := itemString("hello")
+ if is.FilterValue() != "hello" {
+ t.Errorf("Expected 'hello', got %s", is.FilterValue())
+ }
}