aboutsummaryrefslogtreecommitdiff
path: root/internal/tui/reader_test.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-07-24 22:13:06 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-07-24 22:13:06 +0200
commit1b4134d883544beba3fc51704322cef2a875a7d2 (patch)
treec3b74799fcc1f62acd6eedfb734245015ade50cb /internal/tui/reader_test.go
parent1ab07867b425cfa8da207b904a297df29b1b177a (diff)
downloadlectio-1b4134d883544beba3fc51704322cef2a875a7d2.tar.gz
lectio-1b4134d883544beba3fc51704322cef2a875a7d2.zip
lectio-ui reader: go-to-chapter jump (c)
Inside a book, 'c' opens a centered prompt showing the book's chapter range (e.g. "1-21: ") and accepts a chapter number to jump straight there, instead of scrolling (handy for Psalm 119 etc). Digits only, backspace edits, Enter clamps to the valid range and opens that chapter at its top, Esc cancels. New modeChapterJump + updateChapterJump/jumpToChapter/ viewChapterJump; i18n ReaderJumpChapter/ReaderJumpChapterKeys (en/pl) and 'c' added to the reading keybar. Only offered when the book has >1 chapter.
Diffstat (limited to 'internal/tui/reader_test.go')
-rw-r--r--internal/tui/reader_test.go58
1 files changed, 58 insertions, 0 deletions
diff --git a/internal/tui/reader_test.go b/internal/tui/reader_test.go
index 904836e..9d324ba 100644
--- a/internal/tui/reader_test.go
+++ b/internal/tui/reader_test.go
@@ -165,6 +165,64 @@ func TestReaderBookmarkFlow(t *testing.T) {
}
}
+func TestReaderChapterJump(t *testing.T) {
+ m := enReader(t)
+ m = win(m, 80, 24)
+ m = key(m, runes("jn"))
+ m = key(m, tea.KeyMsg{Type: tea.KeyEnter}) // open John 1 (21 chapters)
+ if m.mode != modeRead {
+ t.Fatal("did not enter reading")
+ }
+ // c opens the jump prompt
+ m = key(m, runes("c"))
+ if m.mode != modeChapterJump {
+ t.Fatalf("c did not open the chapter-jump prompt (mode=%v)", m.mode)
+ }
+ if hi := m.chapters[len(m.chapters)-1]; hi != 21 {
+ t.Fatalf("John should have 21 chapters, got %d", hi)
+ }
+ if v := m.View(); !strings.Contains(v, "1-21") || !strings.Contains(v, "go to chapter") {
+ t.Errorf("jump prompt missing range/label:\n%s", v)
+ }
+ // non-digit keys are ignored; only digits accumulate
+ m = key(m, runes("x1"))
+ m = key(m, runes("4"))
+ if m.chapJumpBuf != "14" {
+ t.Fatalf("buffer = %q want 14 (non-digits filtered)", m.chapJumpBuf)
+ }
+ m = key(m, tea.KeyMsg{Type: tea.KeyBackspace})
+ m = key(m, runes("2")) // -> "12"
+ m = key(m, tea.KeyMsg{Type: tea.KeyEnter})
+ if m.mode != modeRead {
+ t.Fatalf("enter did not return to reading (mode=%v)", m.mode)
+ }
+ if m.currentChapter() != 12 {
+ t.Errorf("jumped to chapter %d want 12", m.currentChapter())
+ }
+ if m.scroll != 0 {
+ t.Errorf("jump should reset scroll, got %d", m.scroll)
+ }
+
+ // out-of-range clamps to the last chapter
+ m = key(m, runes("c"))
+ m = key(m, runes("999"))
+ m = key(m, tea.KeyMsg{Type: tea.KeyEnter})
+ if m.currentChapter() != 21 {
+ t.Errorf("999 should clamp to 21, got %d", m.currentChapter())
+ }
+
+ // esc cancels without moving
+ m = key(m, runes("c"))
+ m = key(m, runes("3"))
+ m = key(m, tea.KeyMsg{Type: tea.KeyEsc})
+ if m.mode != modeRead {
+ t.Fatalf("esc did not return to reading (mode=%v)", m.mode)
+ }
+ if m.currentChapter() != 21 {
+ t.Errorf("esc changed chapter to %d want 21", m.currentChapter())
+ }
+}
+
func TestReaderRemembersPlace(t *testing.T) {
dir := t.TempDir()
t.Setenv("XDG_DATA_HOME", dir)