mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-06-04 22:25:36 -04:00
* Added a lot of tests * More tests! Added a Parser.NormalizePath to normalize all paths within Kavita. * Fixed a bug where MarkChaptersAsUnread implementation wasn't consistent between different files and lead to extra row generation for no reason. * Added more unit tests * Found a better implementation for Natural Sorting. Added tests and validate it works. Next commit will swap out natural Sort for new Extension. * Replaced NaturalSortComparer with OrderByNatural. * Drastically simplified and sped up FindFirstEntry for finding cover images in archives * Initial fix for a epub bug where metadata defines key as absolute path but document uses a relative path. We now have a hack to correct for the epub.
178 lines
5.2 KiB
C#
178 lines
5.2 KiB
C#
using System.Collections.Generic;
|
|
using API.Entities;
|
|
using API.Entities.Enums;
|
|
using API.Extensions;
|
|
using API.Tests.Helpers;
|
|
using Xunit;
|
|
|
|
namespace API.Tests.Extensions;
|
|
|
|
public class VolumeListExtensionsTests
|
|
{
|
|
#region FirstWithChapters
|
|
|
|
[Fact]
|
|
public void FirstWithChapters_ReturnsVolumeWithChapters()
|
|
{
|
|
var volumes = new List<Volume>()
|
|
{
|
|
EntityFactory.CreateVolume("0", new List<Chapter>()),
|
|
EntityFactory.CreateVolume("1", new List<Chapter>()
|
|
{
|
|
EntityFactory.CreateChapter("1", false),
|
|
EntityFactory.CreateChapter("2", false),
|
|
}),
|
|
};
|
|
|
|
Assert.Equal(volumes[1].Number, volumes.FirstWithChapters(false).Number);
|
|
Assert.Equal(volumes[1].Number, volumes.FirstWithChapters(true).Number);
|
|
}
|
|
|
|
[Fact]
|
|
public void FirstWithChapters_Book()
|
|
{
|
|
var volumes = new List<Volume>()
|
|
{
|
|
EntityFactory.CreateVolume("1", new List<Chapter>()
|
|
{
|
|
EntityFactory.CreateChapter("3", false),
|
|
EntityFactory.CreateChapter("4", false),
|
|
}),
|
|
EntityFactory.CreateVolume("0", new List<Chapter>()
|
|
{
|
|
EntityFactory.CreateChapter("1", false),
|
|
EntityFactory.CreateChapter("0", true),
|
|
}),
|
|
};
|
|
|
|
Assert.Equal(volumes[0].Number, volumes.FirstWithChapters(true).Number);
|
|
}
|
|
|
|
[Fact]
|
|
public void FirstWithChapters_NonBook()
|
|
{
|
|
var volumes = new List<Volume>()
|
|
{
|
|
EntityFactory.CreateVolume("1", new List<Chapter>()
|
|
{
|
|
EntityFactory.CreateChapter("3", false),
|
|
EntityFactory.CreateChapter("4", false),
|
|
}),
|
|
EntityFactory.CreateVolume("0", new List<Chapter>()
|
|
{
|
|
EntityFactory.CreateChapter("1", false),
|
|
EntityFactory.CreateChapter("0", true),
|
|
}),
|
|
};
|
|
|
|
Assert.Equal(volumes[0].Number, volumes.FirstWithChapters(false).Number);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region GetCoverImage
|
|
|
|
[Fact]
|
|
public void GetCoverImage_ArchiveFormat()
|
|
{
|
|
var volumes = new List<Volume>()
|
|
{
|
|
EntityFactory.CreateVolume("1", new List<Chapter>()
|
|
{
|
|
EntityFactory.CreateChapter("3", false),
|
|
EntityFactory.CreateChapter("4", false),
|
|
}),
|
|
EntityFactory.CreateVolume("0", new List<Chapter>()
|
|
{
|
|
EntityFactory.CreateChapter("1", false),
|
|
EntityFactory.CreateChapter("0", true),
|
|
}),
|
|
};
|
|
|
|
Assert.Equal(volumes[0].Number, volumes.GetCoverImage(MangaFormat.Archive).Number);
|
|
}
|
|
|
|
[Fact]
|
|
public void GetCoverImage_EpubFormat()
|
|
{
|
|
var volumes = new List<Volume>()
|
|
{
|
|
EntityFactory.CreateVolume("1", new List<Chapter>()
|
|
{
|
|
EntityFactory.CreateChapter("3", false),
|
|
EntityFactory.CreateChapter("4", false),
|
|
}),
|
|
EntityFactory.CreateVolume("0", new List<Chapter>()
|
|
{
|
|
EntityFactory.CreateChapter("1", false),
|
|
EntityFactory.CreateChapter("0", true),
|
|
}),
|
|
};
|
|
|
|
Assert.Equal(volumes[1].Name, volumes.GetCoverImage(MangaFormat.Epub).Name);
|
|
}
|
|
|
|
[Fact]
|
|
public void GetCoverImage_PdfFormat()
|
|
{
|
|
var volumes = new List<Volume>()
|
|
{
|
|
EntityFactory.CreateVolume("1", new List<Chapter>()
|
|
{
|
|
EntityFactory.CreateChapter("3", false),
|
|
EntityFactory.CreateChapter("4", false),
|
|
}),
|
|
EntityFactory.CreateVolume("0", new List<Chapter>()
|
|
{
|
|
EntityFactory.CreateChapter("1", false),
|
|
EntityFactory.CreateChapter("0", true),
|
|
}),
|
|
};
|
|
|
|
Assert.Equal(volumes[1].Name, volumes.GetCoverImage(MangaFormat.Pdf).Name);
|
|
}
|
|
|
|
[Fact]
|
|
public void GetCoverImage_ImageFormat()
|
|
{
|
|
var volumes = new List<Volume>()
|
|
{
|
|
EntityFactory.CreateVolume("1", new List<Chapter>()
|
|
{
|
|
EntityFactory.CreateChapter("3", false),
|
|
EntityFactory.CreateChapter("4", false),
|
|
}),
|
|
EntityFactory.CreateVolume("0", new List<Chapter>()
|
|
{
|
|
EntityFactory.CreateChapter("1", false),
|
|
EntityFactory.CreateChapter("0", true),
|
|
}),
|
|
};
|
|
|
|
Assert.Equal(volumes[0].Name, volumes.GetCoverImage(MangaFormat.Image).Name);
|
|
}
|
|
|
|
[Fact]
|
|
public void GetCoverImage_ImageFormat_NoSpecials()
|
|
{
|
|
var volumes = new List<Volume>()
|
|
{
|
|
EntityFactory.CreateVolume("2", new List<Chapter>()
|
|
{
|
|
EntityFactory.CreateChapter("3", false),
|
|
EntityFactory.CreateChapter("4", false),
|
|
}),
|
|
EntityFactory.CreateVolume("1", new List<Chapter>()
|
|
{
|
|
EntityFactory.CreateChapter("1", false),
|
|
EntityFactory.CreateChapter("0", true),
|
|
}),
|
|
};
|
|
|
|
Assert.Equal(volumes[1].Name, volumes.GetCoverImage(MangaFormat.Image).Name);
|
|
}
|
|
|
|
|
|
#endregion
|
|
}
|