mirror of
https://github.com/Kareadita/Kavita.git
synced 2026-03-17 07:11:02 -04:00
Co-authored-by: Amelia <77553571+Fesaa@users.noreply.github.com> Co-authored-by: Weblate (bot) <hosted@weblate.org> Co-authored-by: Adam Havránek <adamhavra@seznam.cz> Co-authored-by: Aindriú Mac Giolla Eoin <aindriu80@gmail.com> Co-authored-by: Dark77 <Dark77@pobox.sk> Co-authored-by: Frozehunter <frozehunter@me.com> Co-authored-by: Havokdan <havokdan@yahoo.com.br> Co-authored-by: Igor Dobrača <igor.dobraca@gmail.com> Co-authored-by: Karl B <karl.owl@proton.me> Co-authored-by: Morhain Olivier <sesram@users.noreply.hosted.weblate.org> Co-authored-by: daydreamrabbit <devrabbit90@gmail.com> Co-authored-by: karigane <169052233+karigane-cha@users.noreply.github.com> Co-authored-by: oxygen44k <iiccpp@outlook.com> Co-authored-by: Максим Горпиніч <gorpinicmaksim0@gmail.com> Co-authored-by: 無情天 <kofzhanganguo@126.com> Co-authored-by: 안세훈 <on9686@gmail.com>
88 lines
3.0 KiB
C#
88 lines
3.0 KiB
C#
using API.DTOs.Progress;
|
|
using API.Helpers;
|
|
using Xunit;
|
|
|
|
namespace API.Tests.Helpers;
|
|
#nullable enable
|
|
|
|
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/DocFragment[3]/body/h1/text().0", 2, "h1")]
|
|
[InlineData("/body/DocFragment[10].0", 9, null)]
|
|
public void GetEpubPositionDto2(string koreaderPosition, int page, string? endingTag)
|
|
{
|
|
var expected = EmptyProgressDto();
|
|
expected.PageNum = page;
|
|
var actual = EmptyProgressDto();
|
|
|
|
KoreaderHelper.UpdateProgressDto(actual, koreaderPosition);
|
|
if (!string.IsNullOrEmpty(endingTag))
|
|
{
|
|
Assert.EndsWith(endingTag, 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
|
|
};
|
|
}
|
|
}
|