Add language-aware article sorting
This commit is contained in:
@@ -8,7 +8,7 @@ namespace Jellyfin.Plugin.Multilang.Tests;
|
||||
public sealed class ItemsProxySortingTests
|
||||
{
|
||||
[Fact]
|
||||
public void GetSortArticlesUsesBuiltInLocaleFallback()
|
||||
public void GetSortArticlesUsesBuiltInLanguageFallback()
|
||||
{
|
||||
var articles = ItemsProxySorting.GetSortArticles(new SortArticleCatalog(), [], "sv-FI");
|
||||
|
||||
@@ -27,7 +27,7 @@ public sealed class ItemsProxySortingTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetSortArticlesPrefersConfiguredExactLocale()
|
||||
public void GetSortArticlesPrefersConfiguredExactLanguage()
|
||||
{
|
||||
var articles = ItemsProxySorting.GetSortArticles(
|
||||
new SortArticleCatalog(),
|
||||
@@ -40,6 +40,32 @@ public sealed class ItemsProxySortingTests
|
||||
Assert.Equal(["exact"], articles);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetSortArticlesIncludesAlwaysIgnoredArticlesFromOtherLanguages()
|
||||
{
|
||||
var articles = ItemsProxySorting.GetSortArticles(
|
||||
new SortArticleCatalog(),
|
||||
[
|
||||
new SortArticleEntry { Language = "en", Articles = "a, an, the", AlwaysApply = true },
|
||||
new SortArticleEntry { Language = "it", Articles = "il, lo, la" }
|
||||
],
|
||||
"it");
|
||||
|
||||
Assert.Equal(["a", "an", "the", "il", "lo", "la"], articles);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetSortArticlesReturnsNoneWhenArticleIgnoringIsDisabled()
|
||||
{
|
||||
var articles = ItemsProxySorting.GetSortArticles(
|
||||
new SortArticleCatalog(),
|
||||
[new SortArticleEntry { Language = "en", Articles = "a, an, the", AlwaysApply = true }],
|
||||
"en",
|
||||
ignoreArticles: false);
|
||||
|
||||
Assert.Empty(articles);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplySortsByTitleAfterLeadingArticles()
|
||||
{
|
||||
@@ -54,6 +80,41 @@ public sealed class ItemsProxySortingTests
|
||||
Assert.Equal(["Avatar", "A Beautiful Mind", "The Matrix"], ItemNames(root));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyUsesEachTitlesLanguageForArticleRemoval()
|
||||
{
|
||||
var root = ItemsRoot("La La Land", "La vita e bella", "Terminator", "The Matrix");
|
||||
var articles = new Dictionary<string, string[]>(StringComparer.Ordinal)
|
||||
{
|
||||
["La La Land"] = [],
|
||||
["La vita e bella"] = ["il", "lo", "la"],
|
||||
["Terminator"] = [],
|
||||
["The Matrix"] = ["a", "an", "the"]
|
||||
};
|
||||
|
||||
ItemsProxySorting.Apply(
|
||||
root,
|
||||
new ItemsProxyControls("SortName", "Ascending", "", 0, 0, "en-US", ""),
|
||||
CultureInfo.GetCultureInfo("en-US"),
|
||||
item => articles[item["Name"]!.GetValue<string>()]);
|
||||
|
||||
Assert.Equal(["La La Land", "The Matrix", "Terminator", "La vita e bella"], ItemNames(root));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyStripsApostropheArticles()
|
||||
{
|
||||
var root = ItemsRoot("L'avventura", "The Matrix");
|
||||
|
||||
ItemsProxySorting.Apply(
|
||||
root,
|
||||
new ItemsProxyControls("SortName", "Ascending", "", 0, 0, "en-US", ""),
|
||||
CultureInfo.GetCultureInfo("en-US"),
|
||||
item => item["Name"]!.GetValue<string>() == "L'avventura" ? ["l'"] : ["the"]);
|
||||
|
||||
Assert.Equal(["L'avventura", "The Matrix"], ItemNames(root));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyPadsNumbersDuringTitleSort()
|
||||
{
|
||||
|
||||
@@ -29,6 +29,7 @@ public sealed class ItemsProxyTransformerResolutionTests
|
||||
|
||||
Assert.True(result.Change);
|
||||
Assert.Equal("Finnish overview", result.Value);
|
||||
Assert.Equal("fi", result.Language);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -37,11 +38,12 @@ public sealed class ItemsProxyTransformerResolutionTests
|
||||
var result = ItemsProxyTransformer.ResolveField(
|
||||
TitleField,
|
||||
[OriginalAction, LanguagePrefix + "en"],
|
||||
Facts(originalTitle: "Original title"),
|
||||
Facts(originalTitle: "Original title", originalLanguage: "en"),
|
||||
TextTranslations(("en", TitleField, "English title")));
|
||||
|
||||
Assert.True(result.Change);
|
||||
Assert.Equal("Original title", result.Value);
|
||||
Assert.Equal("en", result.Language);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -55,6 +57,7 @@ public sealed class ItemsProxyTransformerResolutionTests
|
||||
|
||||
Assert.False(result.Change);
|
||||
Assert.Null(result.Value);
|
||||
Assert.Null(result.Language);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -145,13 +148,13 @@ public sealed class ItemsProxyTransformerResolutionTests
|
||||
return result;
|
||||
}
|
||||
|
||||
private static FactsData Facts(string originalTitle = "")
|
||||
private static FactsData Facts(string originalTitle = "", string originalLanguage = "")
|
||||
=> new(
|
||||
"item",
|
||||
"tmdb",
|
||||
"movie",
|
||||
originalTitle,
|
||||
"",
|
||||
originalLanguage,
|
||||
"",
|
||||
"[]",
|
||||
"[]",
|
||||
|
||||
Reference in New Issue
Block a user