fix(kobo): fix epub cfi parsing for kobo progress sync (#861)

This commit is contained in:
Alex
2026-04-25 14:49:08 +01:00
committed by GitHub
parent 59fcfb1689
commit 3fda81b539
2 changed files with 53 additions and 41 deletions
@@ -272,6 +272,33 @@ class EpubCfiServiceTest {
assertTrue(earlyLocation.contentSourceProgressPercent() < laterLocation.contentSourceProgressPercent());
}
@Test
void resolveCfiLocation_webReaderStyleTerminalTextStepResolvesDeepIntoChapter() {
String earlyCfi = "epubcfi(/6/2!/4/2/2/1:0)";
String laterCfi = "epubcfi(/6/2!/4/2/4/1:10)";
EpubCfiService.CfiLocation earlyLocation = service.resolveCfiLocation(testEpubFile, earlyCfi).orElseThrow();
EpubCfiService.CfiLocation laterLocation = service.resolveCfiLocation(testEpubFile, laterCfi).orElseThrow();
assertEquals("chapter1.xhtml", earlyLocation.href());
assertEquals("chapter1.xhtml", laterLocation.href());
assertNotNull(earlyLocation.contentSourceProgressPercent());
assertNotNull(laterLocation.contentSourceProgressPercent());
assertTrue(earlyLocation.contentSourceProgressPercent() > 10f);
assertTrue(laterLocation.contentSourceProgressPercent() > earlyLocation.contentSourceProgressPercent() + 10f);
}
@Test
void resolveCfiLocation_rangeCfiUsesRangeEndPosition() {
String rangeCfi = "epubcfi(/6/2!/4/2,/2/1:0,/4/1:10)";
EpubCfiService.CfiLocation location = service.resolveCfiLocation(testEpubFile, rangeCfi).orElseThrow();
assertEquals("chapter1.xhtml", location.href());
assertNotNull(location.contentSourceProgressPercent());
assertTrue(location.contentSourceProgressPercent() > 30f);
}
@Test
void resolveCfiLocation_invalidCfiReturnsEmpty() {
assertTrue(service.resolveCfiLocation(testEpubFile, "invalid").isEmpty());