diff options
Diffstat (limited to 'internal/tui/reader_test.go')
| -rw-r--r-- | internal/tui/reader_test.go | 48 |
1 files changed, 42 insertions, 6 deletions
diff --git a/internal/tui/reader_test.go b/internal/tui/reader_test.go index 9d324ba..7bce759 100644 --- a/internal/tui/reader_test.go +++ b/internal/tui/reader_test.go @@ -30,6 +30,18 @@ func key(m ReaderModel, k tea.KeyMsg) ReaderModel { return nm.(ReaderModel) } +// requireCorpus skips the test when corpus `code` is not embedded in this +// build. The optional corpora (wuj, drb, grb) compile in only with +// `-tags fullbible` (or when dropped into the user corpora dir); mirrors the +// helper in internal/bible so these tests run under fullbible and skip -- not +// fail -- on the default vul-only build. +func requireCorpus(t *testing.T, code string) { + t.Helper() + if _, ok := bible.Meta(code); !ok { + t.Skipf("corpus %q not embedded; build with -tags fullbible", code) + } +} + func runes(s string) tea.KeyMsg { return tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune(s)} } func win(m ReaderModel, w, h int) ReaderModel { @@ -55,6 +67,8 @@ func TestReaderFilterAndOpen(t *testing.T) { nm, _ := m.Update(tea.WindowSizeMsg{Width: 80, Height: 24}) m = nm.(ReaderModel) m = key(m, runes("jn")) + // Fuzzy filtering and entering read mode come from the book table and the + // model's state machine -- independent of any corpus being embedded. if len(m.matches) == 0 || m.books[m.matches[0]].Canonical != "John" { t.Fatalf("filter 'jn' top = %v", m.books[m.matches[m.pickSel]]) } @@ -62,15 +76,25 @@ func TestReaderFilterAndOpen(t *testing.T) { if m.mode != modeRead { t.Fatalf("did not enter read mode") } - if m.books[m.bookIdx].Canonical != "John" || len(m.verses) == 0 { - t.Errorf("opened book=%q verses=%d", m.books[m.bookIdx].Canonical, len(m.verses)) - } - if !strings.Contains(m.View(), "1") { // chapter 1 header - t.Errorf("read view missing chapter:\n%s", m.View()) - } + // The reader's first version is wuj (see enReader): its verses and chapter + // header need the optional wuj corpus embedded. + t.Run("wuj verses", func(t *testing.T) { + requireCorpus(t, "wuj") + if m.books[m.bookIdx].Canonical != "John" || len(m.verses) == 0 { + t.Errorf("opened book=%q verses=%d", m.books[m.bookIdx].Canonical, len(m.verses)) + } + if !strings.Contains(m.View(), "1") { // chapter 1 header + t.Errorf("read view missing chapter:\n%s", m.View()) + } + }) } func TestReaderChapterAndVersion(t *testing.T) { + // Whole-test guard: the reader's first version is wuj (see enReader), so the + // very first read-mode step below indexes m.chapters[m.chapPos] -- which + // panics on an empty chapter list when wuj is not embedded. The chapter + // stepping and version cycling that follow are all a wuj reading session. + requireCorpus(t, "wuj") m := enReader(t) nm, _ := m.Update(tea.WindowSizeMsg{Width: 80, Height: 24}) m = nm.(ReaderModel) @@ -107,6 +131,10 @@ func TestReaderFuzzyScore(t *testing.T) { } func TestReaderBookmarkFlow(t *testing.T) { + // The whole flow reads and bookmarks verses of John from wuj (the reader's + // first version); "m" only opens the verse picker when len(verses)>0, so + // the optional wuj corpus must be embedded. + requireCorpus(t, "wuj") m := enReader(t) m = win(m, 80, 24) m = key(m, runes("jn")) @@ -166,6 +194,10 @@ func TestReaderBookmarkFlow(t *testing.T) { } func TestReaderChapterJump(t *testing.T) { + // Reads John from wuj (the reader's first version); "c" only opens the + // chapter-jump prompt when the book has >1 chapter loaded, so the optional + // wuj corpus must be embedded. + requireCorpus(t, "wuj") m := enReader(t) m = win(m, 80, 24) m = key(m, runes("jn")) @@ -224,6 +256,10 @@ func TestReaderChapterJump(t *testing.T) { } func TestReaderRemembersPlace(t *testing.T) { + // Persisting/restoring a reading position needs real verses (savePlace + // no-ops when len(verses)==0); the reader's first version is wuj, so the + // optional wuj corpus must be embedded. + requireCorpus(t, "wuj") dir := t.TempDir() t.Setenv("XDG_DATA_HOME", dir) tbl, _ := bible.LoadBookTable(nil) |
