X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Frhynodge%2Ffilters%2Fwebpages%2Fepicgames%2FFreeGamesStateTest.kt;fp=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Frhynodge%2Ffilters%2Fwebpages%2Fepicgames%2FFreeGamesStateTest.kt;h=15679c7a876c022381d47d7eb502bc008cbf741c;hb=cce17237a408a44339d4301ea7664ab87edbdf26;hp=0000000000000000000000000000000000000000;hpb=e16655e79e97ac633595ffaa0b4d0dcab8a89eef;p=rhynodge.git diff --git a/src/test/kotlin/net/pterodactylus/rhynodge/filters/webpages/epicgames/FreeGamesStateTest.kt b/src/test/kotlin/net/pterodactylus/rhynodge/filters/webpages/epicgames/FreeGamesStateTest.kt new file mode 100644 index 0000000..15679c7 --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/rhynodge/filters/webpages/epicgames/FreeGamesStateTest.kt @@ -0,0 +1,60 @@ +package net.pterodactylus.rhynodge.filters.webpages.epicgames + +import net.pterodactylus.rhynodge.Reaction +import org.hamcrest.MatcherAssert.assertThat +import org.hamcrest.Matchers.contains +import org.hamcrest.Matchers.equalTo +import org.jsoup.Jsoup +import org.junit.Test +import java.time.Instant +import java.time.ZoneOffset + +class FreeGamesStateTest { + + @Test + fun `can create free games state`() { + FreeGamesState(emptySet()) + } + + @Test + fun `state lists all games in text output`() { + val output = state.output(Reaction("", null, null, null)).text("text/plain") + assertThat( + output, equalTo( + listOf( + "Good Game: 1970-01-01 00:16:40 - 1970-01-01 00:33:20 (https://good.game/image.jpg)", + "Best Game: 1970-01-01 00:33:20 - 1970-01-01 00:50:00 (https://best.game/image.webp)", + "Better Game: 1970-01-01 00:50:00 - 1970-01-01 01:06:40 (https://better.game/image.png)", + ).joinToString("\n") + ) + ) + } + + @Test + fun `state lists all games in HTML output`() { + val output = state.output(Reaction("", null, null, null)).text("text/html") + val parsedOutput = Jsoup.parse(output) + assertThat( + parsedOutput.select(".game").map { + listOf( + it.select(".game-title").text(), + it.select(".game-image img").attr("src"), + it.select(".game-start").text(), + it.select(".game-end").text() + ).joinToString(", ") + }, contains( + "Good Game, https://good.game/image.jpg, 1970-01-01 00:16:40, 1970-01-01 00:33:20", + "Best Game, https://best.game/image.webp, 1970-01-01 00:33:20, 1970-01-01 00:50:00", + "Better Game, https://better.game/image.png, 1970-01-01 00:50:00, 1970-01-01 01:06:40", + ) + ) + } + +} + +private val freeGames = setOf( + FreeGame("Good Game", "https://good.game/image.jpg", Instant.ofEpochSecond(1000), Instant.ofEpochSecond(2000)), + FreeGame("Better Game", "https://better.game/image.png", Instant.ofEpochSecond(3000), Instant.ofEpochSecond(4000)), + FreeGame("Best Game", "https://best.game/image.webp", Instant.ofEpochSecond(2000), Instant.ofEpochSecond(3000)), +) +private val state = FreeGamesState(freeGames, timezone = ZoneOffset.UTC)