🚧 Add HTML output to game state
[rhynodge.git] / src / test / kotlin / net / pterodactylus / rhynodge / filters / webpages / epicgames / FreeGamesStateTest.kt
1 package net.pterodactylus.rhynodge.filters.webpages.epicgames
2
3 import net.pterodactylus.rhynodge.Reaction
4 import org.hamcrest.MatcherAssert.assertThat
5 import org.hamcrest.Matchers.contains
6 import org.hamcrest.Matchers.equalTo
7 import org.jsoup.Jsoup
8 import org.junit.Test
9 import java.time.Instant
10 import java.time.ZoneOffset
11
12 class FreeGamesStateTest {
13
14         @Test
15         fun `can create free games state`() {
16                 FreeGamesState(emptySet())
17         }
18
19         @Test
20         fun `state lists all games in text output`() {
21                 val output = state.output(Reaction("", null, null, null)).text("text/plain")
22                 assertThat(
23                         output, equalTo(
24                                 listOf(
25                                         "Good Game: 1970-01-01 00:16:40 - 1970-01-01 00:33:20 (https://good.game/image.jpg)",
26                                         "Best Game: 1970-01-01 00:33:20 - 1970-01-01 00:50:00 (https://best.game/image.webp)",
27                                         "Better Game: 1970-01-01 00:50:00 - 1970-01-01 01:06:40 (https://better.game/image.png)",
28                                 ).joinToString("\n")
29                         )
30                 )
31         }
32
33         @Test
34         fun `state lists all games in HTML output`() {
35                 val output = state.output(Reaction("", null, null, null)).text("text/html")
36                 val parsedOutput = Jsoup.parse(output)
37                 assertThat(
38                         parsedOutput.select(".game").map {
39                                 listOf(
40                                         it.select(".game-title").text(),
41                                         it.select(".game-image img").attr("src"),
42                                         it.select(".game-start").text(),
43                                         it.select(".game-end").text()
44                                 ).joinToString(", ")
45                         }, contains(
46                                 "Good Game, https://good.game/image.jpg, 1970-01-01 00:16:40, 1970-01-01 00:33:20",
47                                 "Best Game, https://best.game/image.webp, 1970-01-01 00:33:20, 1970-01-01 00:50:00",
48                                 "Better Game, https://better.game/image.png, 1970-01-01 00:50:00, 1970-01-01 01:06:40",
49                         )
50                 )
51         }
52
53 }
54
55 private val freeGames = setOf(
56         FreeGame("Good Game", "https://good.game/image.jpg", Instant.ofEpochSecond(1000), Instant.ofEpochSecond(2000)),
57         FreeGame("Better Game", "https://better.game/image.png", Instant.ofEpochSecond(3000), Instant.ofEpochSecond(4000)),
58         FreeGame("Best Game", "https://best.game/image.webp", Instant.ofEpochSecond(2000), Instant.ofEpochSecond(3000)),
59 )
60 private val state = FreeGamesState(freeGames, timezone = ZoneOffset.UTC)