using MangaReader.Core.Http;
using MangaReader.Core.Sources.NatoManga.Pages;
using MangaReader.Tests.Utilities;
using NSubstitute;
using Shouldly;

namespace MangaReader.Tests.Sources.NatoManga.Pages;

public class NatoMangaPageTests
{
    [Fact]
    public async Task Get_Pages()
    {
        string mangaHtml = await ReadJsonResourceAsync("Manga-Chapter-Response.html");

        IHttpService httpService = Substitute.For<IHttpService>();

        httpService.GetStringAsync(Arg.Any<string>(), CancellationToken.None)
            .Returns(Task.FromResult(mangaHtml));

        HtmlLoader htmlLoader = new(httpService);

        NatoMangaPageProvider pageProvider = new(htmlLoader);
        IReadOnlyList<string> pageImageUrls = await pageProvider.GetPageImageUrlsAsync("/test-url", CancellationToken.None);

        pageImageUrls.Count.ShouldBe(13);
        pageImageUrls[0].ShouldBe("https://img-r1.2xstorage.com/gal-cant-be-kind-to-otaku/69/0.webp");
        pageImageUrls[12].ShouldBe("https://img-r1.2xstorage.com/gal-cant-be-kind-to-otaku/69/12.webp");
    }

    private static async Task<string> ReadJsonResourceAsync(string resourceName)
    {
        return await ResourceHelper.ReadJsonResourceAsync($"MangaReader.Tests.Sources.NatoManga.Pages.{resourceName}");
    }
}