Skip to content

Commit

Permalink
Chapter only reference crashes if the chapter is not present in the b… (
Browse files Browse the repository at this point in the history
#771)

* Chapter only reference crashes if the chapter is not present in the book.

* Add test to document reference behavior

* Change to test against missing chapter which originally crashed
  • Loading branch information
davidmoore1 authored and aidanpscott committed Jan 27, 2025
1 parent 9abbe1a commit 7b12589
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
31 changes: 31 additions & 0 deletions src/lib/scripts/scripture-reference-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe('Scripture Reference Utilities', () => {
const book3 = allBookNames['JUD'];
const book4 = allBookNames['EXO'];
const book5 = allBookNames['MAT'];
const book6 = allBookNames['LUK'];
const test0 = `${book1} 3`; // John 3
const test1 = `${book1} 3${cvs}16`; // John 3:16
const test2 = `${book1} 3${cvs}16${cls} 3${cvs}17`; // John 3:16; 3:17
Expand All @@ -39,6 +40,7 @@ describe('Scripture Reference Utilities', () => {
const test11 = `${book1} 3${cvs}16${roc}5${cvs}13`; // John 3:16-5:13
const test12 = `${book4} 20${cvs}13${cls} ${book5} 5${cvs}17${lov}20${rov}22`; // Exodus 20:13; Matthew 5:17,20-22
const test13 = `Exo 3${cvs}13`; // Exo 3:13
const test14 = `${book6} 3${cvs}2b${rov}20`; // Luke 3:2b-20
const ref: { docSet: string; book: string; collection: string } = {
docSet: 'eng_C01',
book: 'MAT',
Expand Down Expand Up @@ -591,6 +593,35 @@ describe('Scripture Reference Utilities', () => {
expect(result).toContain('verse":"13"');
});
});
describe('Verse with letter (Luke 3:2b-20) Chapter 20 missing.', () => {
let result: any;
beforeEach(() => {
result = generateHTMLTest(
test14,
'',
'MAT',
ref,
config.bookCollections,
catalog[0]
);
});
it('has two results and does not crash', () => {
const linkCount = result.match(/<a/g).length;
expect(linkCount).toEqual(2);
});
it('has book ID', () => {
expect(result).toContain('book&quot;:&quot;LUK&quot;');
});
it('has valid texts', () => {
expect(result).toContain('>Luke 3:2</a>b-<');
expect(result).toContain('>20</a>');
});
it('treats number after verse as whole chapter reference', () => {
// Not necessarily saying this is good, but it is consistent with
// the app behavior and is not crashing
expect(result).toContain('chapter&quot;:&quot;20&quot;');
});
});
});
describe('isBibleBook', () => {
let item: { collection: string; book: string };
Expand Down
7 changes: 6 additions & 1 deletion src/lib/scripts/scripture-reference-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,12 @@ function lastVerseInChapter(book: string, chapter: string, docSet: string): stri
}
const books = runtimeCatalog.documents;
const chapters = books.find((d) => d.bookCode === book).versesByChapters;
const verses = Object.keys(chapters[chapter]);
const chapterEntry = chapters[chapter];
if (!chapterEntry) {
// Requested Chapter not found in book
return '0';
}
const verses = Object.keys(chapterEntry);
const lastVerse = verses[verses.length - 1];
return lastVerse;
}
Expand Down
2 changes: 1 addition & 1 deletion test_data/data/catalog.js

Large diffs are not rendered by default.

0 comments on commit 7b12589

Please sign in to comment.