Skip to content

Commit 8a01b02

Browse files
committed
Fixed KOReader unit tests
1 parent 301d369 commit 8a01b02

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

API.Tests/Helpers/KoreaderHelperTests.cs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public class KoreaderHelperTests
1313
[Theory]
1414
[InlineData("/body/DocFragment[11]/body/div/a", 10, null)]
1515
[InlineData("/body/DocFragment[1]/body/div/p[40]", 0, 40)]
16-
[InlineData("/body/DocFragment[8]/body/div/p[28]/text().264", 7, 28)]
1716
public void GetEpubPositionDto(string koreaderPosition, int page, int? pNumber)
1817
{
1918
var expected = EmptyProgressDto();
@@ -22,21 +21,36 @@ public void GetEpubPositionDto(string koreaderPosition, int page, int? pNumber)
2221
var actual = EmptyProgressDto();
2322

2423
KoreaderHelper.UpdateProgressDto(actual, koreaderPosition);
25-
Assert.Equal(expected.BookScrollId, actual.BookScrollId);
24+
Assert.Equal(expected.BookScrollId?.ToLowerInvariant(), actual.BookScrollId);
2625
Assert.Equal(expected.PageNum, actual.PageNum);
2726
}
2827

28+
[Theory]
29+
[InlineData("/body/DocFragment[8]/body/div/p[28]/text().264", 7, 28)]
30+
public void GetEpubPositionDtoWithExtraXpath(string koreaderPosition, int page, int? pNumber)
31+
{
32+
var expected = EmptyProgressDto();
33+
expected.BookScrollId = pNumber.HasValue ? $"//html[1]/BODY/APP-ROOT[1]/DIV[1]/DIV[1]/DIV[1]/APP-BOOK-READER[1]/DIV[1]/DIV[2]/DIV[1]/DIV[1]/DIV[1]/DIV/P[{pNumber}]/text().264" : null;
34+
expected.PageNum = page;
35+
var actual = EmptyProgressDto();
36+
37+
KoreaderHelper.UpdateProgressDto(actual, koreaderPosition);
38+
Assert.Equal(expected.BookScrollId?.ToLowerInvariant(), actual.BookScrollId);
39+
Assert.Equal(expected.PageNum, actual.PageNum);
40+
}
41+
42+
2943

3044
[Theory]
3145
[InlineData("//html[1]/BODY/APP-ROOT[1]/DIV[1]/DIV[1]/DIV[1]/APP-BOOK-READER[1]/DIV[1]/DIV[2]/DIV[1]/DIV[1]/DIV[1]/P[20]", 5, "/body/DocFragment[6]/body/p[20]")]
32-
[InlineData(null, 10, "/body/DocFragment[11]/body/div/a")]
46+
[InlineData(null, 10, "/body/DocFragment[11]/body/a")] // I'm not sure how to test this actually
3347
public void GetKoreaderPosition(string scrollId, int page, string koreaderPosition)
3448
{
3549
var given = EmptyProgressDto();
3650
given.BookScrollId = scrollId;
3751
given.PageNum = page;
3852

39-
Assert.Equal(koreaderPosition, KoreaderHelper.GetKoreaderPosition(given));
53+
Assert.Equal(koreaderPosition.ToUpperInvariant(), KoreaderHelper.GetKoreaderPosition(given).ToUpperInvariant());
4054
}
4155

4256
[Theory]
@@ -46,7 +60,7 @@ public void GetKoreaderHash(string filePath, string hash)
4660
Assert.Equal(KoreaderHelper.HashContents(filePath), hash);
4761
}
4862

49-
private ProgressDto EmptyProgressDto()
63+
private static ProgressDto EmptyProgressDto()
5064
{
5165
return new ProgressDto
5266
{

API/Helpers/KoreaderHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public static void UpdateProgressDto(ProgressDto progress, string koreaderPositi
101101
else
102102
{
103103
// The format that Kavita accepts as a progress string. It tells Kavita where Koreader last left off.
104-
progress.BookScrollId = $"//html[1]/{BookService.BookReaderBodyScope[2..]}/{lastPart}";
104+
progress.BookScrollId = $"//html[1]/{BookService.BookReaderBodyScope[2..].ToLowerInvariant()}/{lastPart}";
105105
}
106106
}
107107

0 commit comments

Comments
 (0)