From 2c56df23734fffd5556abd37c5dfb95ef3028292 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Fri, 30 Oct 2026 22:07:58 -0700 Subject: [PATCH] Test that a failed provided image falls back to a thumbnail found in HTML. --- .../ArticleThumbnailFinderTests.swift | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Modules/Images/Tests/ImagesTests/ArticleThumbnailFinderTests.swift b/Modules/Images/Tests/ImagesTests/ArticleThumbnailFinderTests.swift index e1ccef253..65991ce53 100644 --- a/Modules/Images/Tests/ImagesTests/ArticleThumbnailFinderTests.swift +++ b/Modules/Images/Tests/ImagesTests/ArticleThumbnailFinderTests.swift @@ -75,6 +75,24 @@ private typealias ArticleAttachment = Articles.Attachment #expect(finder.thumbnailURL(for: articleWithImage, mode: .small) == "https://example.com/uploads/second-photo.jpg") } + @Test func failedProvidedImageFallsBackToHTMLThumbnail() async { + let imageDatabase = ImageDatabase(databasePath: ":memory:") + let finder = ArticleThumbnailFinder(imageDatabase: imageDatabase) + let article = makeArticle(contentHTML: #"

"#, thumbnailURL: "https://example.com/thumbnail.jpg") + + // The HTML isn’t parsed while the provided image is usable. + await finder.discoverThumbnailURLs(for: [article]) + #expect(finder.thumbnailURL(for: article, mode: .small) == "https://example.com/thumbnail.jpg") + #expect(await imageDatabase.fetchArticleThumbnails(articleIDs: ["1"]).isEmpty) + + imageDatabase.recordFailure(url: "https://example.com/thumbnail.jpg", statusCode: 404) + finder.thumbnailURLDidFail("https://example.com/thumbnail.jpg") + #expect(finder.thumbnailURL(for: article, mode: .small) == nil) + + await finder.discoverThumbnailURLs(for: [article]) + #expect(finder.thumbnailURL(for: article, mode: .small) == "https://example.com/uploads/photo.jpg") + } + @Test func savedHTMLThumbnailIsLoadedWithoutDiscovery() async { let imageDatabase = ImageDatabase(databasePath: ":memory:") let article = makeArticle(contentHTML: #"

"#)