Skip to content

Commit 48cf46c

Browse files
Fix snapping issues
1 parent f8b2ef3 commit 48cf46c

4 files changed

Lines changed: 420 additions & 227 deletions

File tree

src/__tests__/components/Interlinearizer.test.tsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,45 @@ describe('Interlinearizer', () => {
838838
expect(screen.queryByText('Chapter 2')).not.toBeInTheDocument();
839839
});
840840

841+
it('tags each inline chapter header with its chapter number for snap targeting', () => {
842+
renderInterlinearizer({
843+
book: GEN_TWO_CHAPTER_BOOK,
844+
scrRef: { book: 'GEN', chapterNum: 1, verseNum: 1 },
845+
continuousScroll: false,
846+
});
847+
848+
expect(screen.getByText('Chapter 1')).toHaveAttribute('data-chapter-start', '1');
849+
expect(screen.getByText('Chapter 2')).toHaveAttribute('data-chapter-start', '2');
850+
});
851+
852+
it('highlights the first verse of a chapter when the reference names verse 0 (the heading)', () => {
853+
renderInterlinearizer({
854+
book: GEN_TWO_CHAPTER_BOOK,
855+
scrRef: { book: 'GEN', chapterNum: 2, verseNum: 0 },
856+
continuousScroll: false,
857+
});
858+
859+
// Verse 0 names the chapter heading, which is not a verse; the active-verse marker still lands
860+
// on the chapter's first segment so a verse stays highlighted.
861+
const activeIds = new Set(
862+
capturedSegmentViewPropsList.filter((p) => p.isActive).map((p) => p.segment.id),
863+
);
864+
expect([...activeIds]).toEqual(['GEN 2:1']);
865+
});
866+
867+
it('scrolls the chapter heading to the top when the reference names verse 0', () => {
868+
const scrollSpy = jest.spyOn(Element.prototype, 'scrollIntoView');
869+
renderInterlinearizer({
870+
book: GEN_TWO_CHAPTER_BOOK,
871+
scrRef: { book: 'GEN', chapterNum: 2, verseNum: 0 },
872+
continuousScroll: false,
873+
});
874+
875+
// The snap targets the chapter-2 heading element rather than the active verse-1 segment.
876+
const heading = screen.getByText('Chapter 2');
877+
expect(scrollSpy.mock.contexts).toContain(heading);
878+
});
879+
841880
it('renders the snap-to-active-verse button when segments are present', () => {
842881
renderInterlinearizer({ book: GEN_1_MULTI_BOOK });
843882

0 commit comments

Comments
 (0)