aboutsummaryrefslogtreecommitdiff
path: root/internal/tui/tui_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/tui/tui_test.go')
-rw-r--r--internal/tui/tui_test.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/internal/tui/tui_test.go b/internal/tui/tui_test.go
index 330259d..f99c4ac 100644
--- a/internal/tui/tui_test.go
+++ b/internal/tui/tui_test.go
@@ -5,6 +5,8 @@ import (
"strings"
"testing"
+ tea "github.com/charmbracelet/bubbletea"
+
"github.com/lukaszkasprzak/lectio/internal/config"
"github.com/lukaszkasprzak/lectio/internal/liturgy"
)
@@ -161,3 +163,41 @@ func TestFooterKeysLocalised(t *testing.T) {
t.Errorf("pl View() footer missing %q: %q", "q wyjście", out)
}
}
+
+func TestJumpToDate(t *testing.T) {
+ send := func(m Model, s string) Model {
+ for _, r := range s {
+ nm, _ := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{r}})
+ m = nm.(Model)
+ }
+ return m
+ }
+
+ m := New(config.Default(), "2026-07-22", "wuj")
+ m = send(m, "d")
+ if !m.jumping {
+ t.Fatal("'d' did not enter jump mode")
+ }
+ m = send(m, "2026-01-02")
+ if m.jumpBuf != "2026-01-02" {
+ t.Fatalf("jumpBuf = %q", m.jumpBuf)
+ }
+ nm, _ := m.Update(tea.KeyMsg{Type: tea.KeyEnter})
+ m = nm.(Model)
+ if m.jumping {
+ t.Error("still in jump mode after Enter")
+ }
+ if m.date != "2026-01-02" {
+ t.Errorf("date = %q, want 2026-01-02", m.date)
+ }
+
+ // Esc cancels without changing the date.
+ m2 := New(config.Default(), "2026-07-22", "wuj")
+ m2 = send(m2, "d")
+ m2 = send(m2, "2099")
+ nm2, _ := m2.Update(tea.KeyMsg{Type: tea.KeyEsc})
+ m2 = nm2.(Model)
+ if m2.jumping || m2.jumpBuf != "" || m2.date != "2026-07-22" {
+ t.Errorf("esc did not cancel cleanly: jumping=%v buf=%q date=%q", m2.jumping, m2.jumpBuf, m2.date)
+ }
+}