From: David ‘Bombe’ Roden Date: Sun, 30 Apr 2023 05:34:19 +0000 (+0200) Subject: ✅ Add test for “Poorly Drawn Lines” X-Git-Tag: v2~46 X-Git-Url: https://git.pterodactylus.net/?p=rhynodge.git;a=commitdiff_plain;h=dede8612b6a32658db53d6d828c48289bd007b47 ✅ Add test for “Poorly Drawn Lines” --- diff --git a/src/main/java/net/pterodactylus/rhynodge/filters/comics/PoorlyDrawnLinesComicFilter.java b/src/main/java/net/pterodactylus/rhynodge/filters/comics/PoorlyDrawnLinesComicFilter.java index 865e302..c01f5a9 100644 --- a/src/main/java/net/pterodactylus/rhynodge/filters/comics/PoorlyDrawnLinesComicFilter.java +++ b/src/main/java/net/pterodactylus/rhynodge/filters/comics/PoorlyDrawnLinesComicFilter.java @@ -26,6 +26,8 @@ import net.pterodactylus.rhynodge.filters.ComicSiteFilter; import com.google.common.base.Optional; import org.jsoup.nodes.Document; +import static java.util.Arrays.stream; + /** * {@link ComicSiteFilter} implementation that can parse Poorly Drawn Lines * comics. @@ -36,12 +38,13 @@ public class PoorlyDrawnLinesComicFilter extends ComicSiteFilter { @Override protected Optional extractTitle(Document document) { - return Optional.of(document.select("#post img").attr("alt")); + return Optional.of(document.select(".share-mobile .social a.facebook").attr("href")) + .transform(href -> stream(href.split("&t=")).skip(1).findFirst().orElse("")); } @Override protected List extractImageUrls(Document document) { - return Arrays.asList(document.select("#post img").attr("src")); + return Arrays.asList(document.select(".comic img").attr("src")); } @Override diff --git a/src/test/kotlin/net/pterodactylus/rhynodge/filters/comics/PoorlyDrawnLinesComicFilterTest.kt b/src/test/kotlin/net/pterodactylus/rhynodge/filters/comics/PoorlyDrawnLinesComicFilterTest.kt new file mode 100644 index 0000000..4d31c13 --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/rhynodge/filters/comics/PoorlyDrawnLinesComicFilterTest.kt @@ -0,0 +1,28 @@ +package net.pterodactylus.rhynodge.filters.comics + +import net.pterodactylus.rhynodge.filters.ResourceLoader +import net.pterodactylus.rhynodge.states.ComicState +import net.pterodactylus.rhynodge.states.ComicState.Strip +import net.pterodactylus.rhynodge.states.HtmlState +import org.hamcrest.MatcherAssert.assertThat +import org.hamcrest.Matchers.contains +import org.junit.Test + +class PoorlyDrawnLinesComicFilterTest { + + private val filter = PoorlyDrawnLinesComicFilter() + private val htmlState: HtmlState = ResourceLoader + .loadDocument(javaClass, "poorly-drawn-lines.html", baseUrl) + .let { HtmlState(baseUrl, it) } + + @Test + fun `comic is extracted correctly`() { + val comicState = filter.filter(htmlState) as ComicState + assertThat(comicState.comics(), contains( + ComicState.Comic("A New Day").add(Strip("https://poorlydrawnlines.com/wp-content/uploads/2023/04/a_new_day.png", "")) + )) + } + +} + +private const val baseUrl = "https://poorlydrawnlines.com/" diff --git a/src/test/resources/net/pterodactylus/rhynodge/filters/comics/poorly-drawn-lines.html b/src/test/resources/net/pterodactylus/rhynodge/filters/comics/poorly-drawn-lines.html new file mode 100644 index 0000000..a5b1cc1 --- /dev/null +++ b/src/test/resources/net/pterodactylus/rhynodge/filters/comics/poorly-drawn-lines.html @@ -0,0 +1,3762 @@ + + + + Poorly Drawn Lines + + + + + + + + + + + + + + + + + + + +facebookCreated with Sketch. instagramCreated with Sketch. left-navCreated with Sketch. mailCreated with Sketch. menuCreated with Sketch. pdl-title Slice 1Created with Sketch. right-navCreated with Sketch. shareCreated with Sketch. shuffleCreated with Sketch. left-navCreated with Sketch. tumblrCreated with Sketch. twitterCreated with Sketch.
+
+
+ +
+
+ +
+ contact + + + +
+
+
+
+
+ + + +
+ +
+ + + + + + + +