mirror of
https://github.com/Kareadita/Kavita.git
synced 2026-01-18 18:05:57 -05:00
73 lines
2.4 KiB
C#
73 lines
2.4 KiB
C#
using API.DTOs.Progress;
|
|
using API.Helpers;
|
|
using Xunit;
|
|
|
|
namespace API.Tests.Helpers;
|
|
|
|
|
|
public class KoreaderHelperTests
|
|
{
|
|
|
|
[Theory]
|
|
[InlineData("/body/DocFragment[11]/body/div/a", 10, null)]
|
|
[InlineData("/body/DocFragment[1]/body/div/p[40]", 0, 40)]
|
|
public void GetEpubPositionDto(string koreaderPosition, int page, int? pNumber)
|
|
{
|
|
var expected = EmptyProgressDto();
|
|
expected.BookScrollId = pNumber.HasValue ? $"//BODY/DIV/P[{pNumber}]" : null;
|
|
expected.PageNum = page;
|
|
var actual = EmptyProgressDto();
|
|
|
|
KoreaderHelper.UpdateProgressDto(actual, koreaderPosition);
|
|
Assert.Equal(expected.BookScrollId?.ToLowerInvariant(), actual.BookScrollId);
|
|
Assert.Equal(expected.PageNum, actual.PageNum);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("/body/DocFragment[8]/body/div/p[28]/text().264", 7, 28)]
|
|
public void GetEpubPositionDtoWithExtraXpath(string koreaderPosition, int page, int? pNumber)
|
|
{
|
|
var expected = EmptyProgressDto();
|
|
expected.BookScrollId = pNumber.HasValue ? $"//BODY/DIV/P[{pNumber}]" : null;
|
|
expected.PageNum = page;
|
|
var actual = EmptyProgressDto();
|
|
|
|
KoreaderHelper.UpdateProgressDto(actual, koreaderPosition);
|
|
Assert.Equal(expected.BookScrollId?.ToLowerInvariant(), actual.BookScrollId);
|
|
Assert.Equal(expected.PageNum, actual.PageNum);
|
|
}
|
|
|
|
|
|
|
|
[Theory]
|
|
[InlineData("//body/p[20]", 5, "/body/DocFragment[5]/body/p[20]")]
|
|
[InlineData(null, 10, "/body/DocFragment[10]/body/p[1]")] // I've not seen a null/just an a from Koreader in testing
|
|
public void GetKoreaderPosition(string scrollId, int page, string koreaderPosition)
|
|
{
|
|
var given = EmptyProgressDto();
|
|
given.BookScrollId = scrollId;
|
|
given.PageNum = page;
|
|
|
|
Assert.Equal(koreaderPosition.ToUpperInvariant(), KoreaderHelper.GetKoreaderPosition(given).ToUpperInvariant());
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("./Data/AesopsFables.epub", "8795ACA4BF264B57C1EEDF06A0CEE688")]
|
|
public void GetKoreaderHash(string filePath, string hash)
|
|
{
|
|
Assert.Equal(KoreaderHelper.HashContents(filePath), hash);
|
|
}
|
|
|
|
private static ProgressDto EmptyProgressDto()
|
|
{
|
|
return new ProgressDto
|
|
{
|
|
ChapterId = 0,
|
|
PageNum = 0,
|
|
VolumeId = 0,
|
|
SeriesId = 0,
|
|
LibraryId = 0
|
|
};
|
|
}
|
|
}
|