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)