1 package net.pterodactylus.rhynodge.filters.webpages.savoy
3 import net.pterodactylus.rhynodge.Reaction
4 import org.hamcrest.MatcherAssert.assertThat
5 import org.hamcrest.Matchers.contains
6 import org.hamcrest.Matchers.containsInAnyOrder
7 import org.hamcrest.Matchers.containsString
8 import org.hamcrest.Matchers.empty
9 import org.hamcrest.Matchers.equalTo
10 import org.hamcrest.Matchers.not
11 import org.jsoup.Jsoup
12 import org.jsoup.nodes.Element
13 import org.jsoup.nodes.TextNode
15 import java.time.LocalDateTime
17 class MovieStateTest {
20 fun `summary contains date of earliest movie`() {
21 val movieState = MovieState(
23 Movie("1", "", "", listOf(Performance(LocalDateTime.of(2024, 2, 12, 18, 45), "", ""))),
24 Movie("2", "", "", listOf(Performance(LocalDateTime.of(2024, 3, 12, 15, 30), "", ""))),
25 Movie("3", "", "", listOf(Performance(LocalDateTime.of(2024, 2, 11, 21, 15), "", "")))
28 assertThat(movieState.output(Reaction("", null, null, null)).summary(), containsString("2024-02-11"))
32 fun `movie state without new movies is not triggered`() {
33 assertThat(MovieState(emptySet(), emptySet()).triggered(), equalTo(false))
37 fun `movie state with a new movie is triggered`() {
38 assertThat(MovieState(emptySet(), setOf(Movie("1", "", ""))).triggered(), equalTo(true))
42 fun `html output does not contain a section for new movies if there are no new movies`() {
43 val movieState = MovieState(emptySet(), emptySet())
44 val output = movieState.output(Reaction("", null, null, null))
45 val document = Jsoup.parse(output.text("text/html"))
46 assertThat(document.select("section.new-movies"), empty())
50 fun `html output does contain a section for new movie if there are new movies`() {
51 val movieState = MovieState(emptySet(), setOf(Movie("1", "", ""), Movie("2", "", "")))
52 val output = movieState.output(Reaction("", null, null, null))
53 val document = Jsoup.parse(output.text("text/html"))
54 assertThat(document.select("section.new-movies"), not(empty()))
58 fun `new movies section contains description of movies`() {
59 val movieState = MovieState(emptySet(), setOf(Movie("1", "", "Movie 1 is cool."), Movie("2", "", "Movie 2 is bad.")))
60 val output = movieState.output(Reaction("", null, null, null))
61 val document = Jsoup.parse(output.text("text/html"))
62 assertThat(document.select("section.new-movies .description").map(Element::text), contains("Movie 1 is cool.", "Movie 2 is bad."))
66 fun `new movies section contains the titles of all new movies`() {
67 val movieState = MovieState(emptySet(), setOf(Movie("New Movie", "", ""), Movie("Even Newer Movie", "", "")))
68 val output = movieState.output(Reaction("", null, null, null))
69 val document = Jsoup.parse(output.text("text/html"))
70 assertThat(document.select("section.new-movies li.movie .name").textNodes().map(TextNode::text), containsInAnyOrder("New Movie", "Even Newer Movie"))
74 fun `html output contains section for the daily programme`() {
75 val movieState = MovieState(emptySet(), emptySet())
76 val output = movieState.output(Reaction("", null, null, null))
77 val document = Jsoup.parse(output.text("text/html"))
78 assertThat(document.select("section.daily-programmes"), not(empty()))
82 fun `html output contains a section for each day with a movie`() {
83 val movieState = MovieState(
85 movie("Movie 1", "", "", "20240212-1845", "20240213-1330", "20240214-1815"),
86 movie("Movie 2", "", "", "20240212-2030", "20240213-1745", "20240214-1430"),
87 movie("Movie 3", "", "", "20240213-2015", "20240214-1730"),
88 movie("Movie 4", "", "", "20240216-1000"),
91 val output = movieState.output(Reaction("", null, null, null))
92 val html = output.text("text/html")
93 val document = Jsoup.parse(html)
94 assertThat(document.select("section.daily-programmes li.day").map { it.attr("data-date") }, contains("2024-02-12", "2024-02-13", "2024-02-14", "2024-02-16"))
98 fun `html output contains the correct movies within each day`() {
99 val movieState = MovieState(
101 movie("Movie 1", "https://cdn.premiumkino.de/movie/3047/81c49774d7828a898ae1d525ffd135af_w300.jpg", "", "20240212-1845", "20240213-1330", "20240214-1815"),
102 movie("Movie 2", "https://cdn.premiumkino.de/movie/1066/aba09af737677ff6a15676ae588098b1_w300.jpg", "", "20240212-2030", "20240213-1745", "20240214-1430"),
103 movie("Movie 3", "https://cdn.premiumkino.de/movie/7300/14d1b21dee51a82a7b096ca282bf01c8_w300.png", "", "20240213-2015", "20240214-1730"),
104 movie("Movie 4", "https://cdn.premiumkino.de/movie/6080/cef2b33483d2898ddb472c955c58ea20_w300.jpg", "", "20240216-1000"),
106 movie("Movie 1", "https://cdn.premiumkino.de/movie/3047/81c49774d7828a898ae1d525ffd135af_w300.jpg", "", "20240212-1845", "20240213-1330", "20240214-1815"),
107 movie("Movie 2", "https://cdn.premiumkino.de/movie/1066/aba09af737677ff6a15676ae588098b1_w300.jpg", "", "20240212-1845", "20240213-1330", "20240214-1815")
110 val output = movieState.output(Reaction("", null, null, null))
111 val html = output.text("text/html")
112 val document = Jsoup.parse(html)
114 document.select("section.daily-programmes li.day[data-date='2024-02-12'] li.performance").map { it.select(".time").text() + " - " + it.select(".name").text() }, contains(
115 "18:45 - Movie 1", "20:30 - Movie 2"
121 fun `html output contains the correct release type for movies`() {
122 val movieState = MovieState(
124 movie("Movie 1", "https://cdn.premiumkino.de/movie/3047/81c49774d7828a898ae1d525ffd135af_w300.jpg", "", "20240212-1845" to "2D OV", "20240213-1330" to "2D", "20240214-1815" to "2D OmeU"),
127 val output = movieState.output(Reaction("", null, null, null))
128 val html = output.text("text/html")
129 val document = Jsoup.parse(html)
131 document.select("section.daily-programmes li.performance")
132 .map { performance -> listOf(".name", ".time", ".type").map { performance.select(it).text() }.joinToString(" - ") }, contains(
133 "Movie 1 - 18:45 - 2D OV", "Movie 1 - 13:30 - 2D", "Movie 1 - 18:15 - 2D OmeU"
140 private fun dateTime(dateTimeString: String) = LocalDateTime.of(
141 dateTimeString.substring(0..3).toInt(),
142 dateTimeString.substring(4..5).toInt(),
143 dateTimeString.substring(6..7).toInt(),
144 dateTimeString.substring(9..10).toInt(),
145 dateTimeString.substring(11..12).toInt(),
148 private fun movie(name: String, imageUrl: String, description: String = "", vararg times: String) =
149 times.map(::dateTime)
150 .map { Performance(it, "", "https://link/$it") }
151 .let { Movie(name, imageUrl, description, it) }
153 private fun movie(name: String, imageUrl: String, description: String = "", vararg timesAndTypes: Pair<String, String>) =
154 timesAndTypes.map { Performance(it.first.let(::dateTime), it.second, "https://link/${it.first}") }
155 .let { Movie(name, imageUrl, description, it) }