diff --git a/API.Benchmark/API.Benchmark.csproj b/API.Benchmark/API.Benchmark.csproj
index cbf7d76f9..bd78c1a8d 100644
--- a/API.Benchmark/API.Benchmark.csproj
+++ b/API.Benchmark/API.Benchmark.csproj
@@ -12,7 +12,7 @@
-
+
diff --git a/API.Tests/API.Tests.csproj b/API.Tests/API.Tests.csproj
index 4f268a38a..782385ffc 100644
--- a/API.Tests/API.Tests.csproj
+++ b/API.Tests/API.Tests.csproj
@@ -7,16 +7,16 @@
-
-
-
-
+
+
+
+
runtime; build; native; contentfiles; analyzers; buildtransitive
all
-
+
runtime; build; native; contentfiles; analyzers; buildtransitive
all
diff --git a/API.Tests/Services/ReaderServiceTests.cs b/API.Tests/Services/ReaderServiceTests.cs
index 05d076b3f..7f1ead893 100644
--- a/API.Tests/Services/ReaderServiceTests.cs
+++ b/API.Tests/Services/ReaderServiceTests.cs
@@ -820,7 +820,7 @@ public class ReaderServiceTests
}
[Fact]
- public async Task GetPrevChapterIdAsync_ShouldMoveFromVolumeToSpecial()
+ public async Task GetPrevChapterIdAsync_ShouldMoveFromSpecialToVolume()
{
await ResetDB();
@@ -856,10 +856,10 @@ public class ReaderServiceTests
var readerService = new ReaderService(_unitOfWork, Substitute.For>());
- var prevChapter = await readerService.GetPrevChapterIdAsync(1, 1, 1, 1);
- Assert.NotEqual(-1, prevChapter);
+ var prevChapter = await readerService.GetPrevChapterIdAsync(1, 2, 3, 1);
+ Assert.Equal(2, prevChapter);
var actualChapter = await _unitOfWork.ChapterRepository.GetChapterAsync(prevChapter);
- Assert.Equal("B.cbz", actualChapter.Range);
+ Assert.Equal("2", actualChapter.Range);
}
[Fact]
@@ -973,6 +973,60 @@ public class ReaderServiceTests
Assert.Equal(-1, prevChapter);
}
+ [Fact]
+ public async Task GetPrevChapterIdAsync_ShouldFindNoPrevChapterFromVolumeWithZeroChapterAndHasNormalChapters2()
+ {
+ await ResetDB();
+
+ _context.Series.Add(new Series()
+ {
+ Name = "Test",
+ Library = new Library() {
+ Name = "Test LIb",
+ Type = LibraryType.Manga,
+ },
+ Volumes = new List()
+ {
+ EntityFactory.CreateVolume("0", new List()
+ {
+ EntityFactory.CreateChapter("5", false, new List()),
+ EntityFactory.CreateChapter("6", false, new List()),
+ EntityFactory.CreateChapter("7", false, new List()),
+
+ }),
+ EntityFactory.CreateVolume("1", new List()
+ {
+ EntityFactory.CreateChapter("1", false, new List()),
+ EntityFactory.CreateChapter("2", false, new List()),
+ }),
+ EntityFactory.CreateVolume("2", new List()
+ {
+ EntityFactory.CreateChapter("3", false, new List()),
+ EntityFactory.CreateChapter("4", false, new List()),
+ }),
+ }
+ });
+
+ _context.AppUser.Add(new AppUser()
+ {
+ UserName = "majora2007"
+ });
+
+ await _context.SaveChangesAsync();
+
+ var readerService = new ReaderService(_unitOfWork, Substitute.For>());
+
+ var prevChapter = await readerService.GetPrevChapterIdAsync(1, 2,5, 1);
+ var chapterInfoDto = await _unitOfWork.ChapterRepository.GetChapterInfoDtoAsync(prevChapter);
+ Assert.Equal(1, float.Parse(chapterInfoDto.ChapterNumber));
+
+ // This is first chapter of first volume
+ prevChapter = await readerService.GetPrevChapterIdAsync(1, 2,4, 1);
+ Assert.Equal(-1, prevChapter);
+ //chapterInfoDto = await _unitOfWork.ChapterRepository.GetChapterInfoDtoAsync(prevChapter);
+
+ }
+
[Fact]
public async Task GetPrevChapterIdAsync_ShouldFindNoPrevChapterFromChapter()
{
diff --git a/API/API.csproj b/API/API.csproj
index edda546eb..764ed1c2c 100644
--- a/API/API.csproj
+++ b/API/API.csproj
@@ -40,40 +40,40 @@
-
-
-
-
+
+
+
+
-
+
-
-
-
+
+
+
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
+
-
+
-
-
+
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
+
+
diff --git a/API/Services/ReaderService.cs b/API/Services/ReaderService.cs
index 36a98317b..4568a2d84 100644
--- a/API/Services/ReaderService.cs
+++ b/API/Services/ReaderService.cs
@@ -302,7 +302,8 @@ public class ReaderService : IReaderService
if (currentVolume.Number == 0)
{
- var chapterId = GetNextChapterId(currentVolume.Chapters.OrderByNatural(x => x.Range).Reverse(), currentChapter.Number, dto => dto.Number);
+ var chapterId = GetNextChapterId(currentVolume.Chapters.OrderByNatural(x => x.Range).Reverse(), currentChapter.Range,
+ dto => dto.Range);
if (chapterId > 0) return chapterId;
}
@@ -311,11 +312,12 @@ public class ReaderService : IReaderService
if (volume.Number == currentVolume.Number)
{
var chapterId = GetNextChapterId(currentVolume.Chapters.OrderBy(x => double.Parse(x.Number), _chapterSortComparerForInChapterSorting).Reverse(),
- currentChapter.Number, dto => dto.Number);
+ currentChapter.Range, dto => dto.Range);
if (chapterId > 0) return chapterId;
}
if (volume.Number == currentVolume.Number - 1)
{
+ if (currentVolume.Number - 1 == 0) break; // If we have walked all the way to chapter volume, then we should break so logic outside can work
var lastChapter = volume.Chapters
.OrderBy(x => double.Parse(x.Number), _chapterSortComparerForInChapterSorting).LastOrDefault();
if (lastChapter == null) return -1;
diff --git a/Kavita.Common/Kavita.Common.csproj b/Kavita.Common/Kavita.Common.csproj
index 29229740c..408e0484b 100644
--- a/Kavita.Common/Kavita.Common.csproj
+++ b/Kavita.Common/Kavita.Common.csproj
@@ -9,10 +9,10 @@
-
+
-
-
+
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive