using StellaOps.Feedser.Normalization.Text;

namespace StellaOps.Feedser.Normalization.Tests;

public sealed class DescriptionNormalizerTests
{
    [Fact]
    public void Normalize_RemovesMarkupAndCollapsesWhitespace()
    {
        var candidates = new[]
        {
            new LocalizedText("<p>Hello\n\nworld!</p>", "en-US"),
        };

        var result = DescriptionNormalizer.Normalize(candidates);

        Assert.Equal("hello world!", result.Text.ToLowerInvariant());
        Assert.Equal("en", result.Language);
    }

    [Fact]
    public void Normalize_FallsBackToPreferredLanguage()
    {
        var candidates = new[]
        {
            new LocalizedText("Bonjour", "fr"),
            new LocalizedText("Hello", "en-GB"),
        };

        var result = DescriptionNormalizer.Normalize(candidates);

        Assert.Equal("Hello", result.Text);
        Assert.Equal("en", result.Language);
    }

    [Fact]
    public void Normalize_ReturnsDefaultWhenEmpty()
    {
        var result = DescriptionNormalizer.Normalize(Array.Empty<LocalizedText>());

        Assert.Equal(string.Empty, result.Text);
        Assert.Equal("en", result.Language);
    }
}
