diff options
Diffstat (limited to 'internal/tui/reader_test.go')
| -rw-r--r-- | internal/tui/reader_test.go | 58 |
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) |
