Show optional columns
[rhynodge.git] / src / test / kotlin / net / pterodactylus / rhynodge / webpages / weather / WeatherTriggerTest.kt
index 48dfe89..ee4b53b 100644 (file)
@@ -5,6 +5,7 @@ import net.pterodactylus.rhynodge.State
 import org.hamcrest.MatcherAssert.assertThat
 import org.hamcrest.Matchers.`is`
 import org.hamcrest.Matchers.containsString
+import org.hamcrest.Matchers.not
 import org.junit.Test
 import org.mockito.Mockito.mock
 import java.io.File
@@ -85,4 +86,48 @@ class WeatherTriggerTest {
         assertThat(htmlText, containsString("http://28"))
     }
 
+    @Test
+    fun outputContainsColumnHeadersForAllColumns() {
+        val currentState = WeatherState("Weather", ZonedDateTime.of(2016, 5, 28, 0, 0, 0, 0, of("Europe/Berlin")))
+        currentState += HourState(0, 10, 11, 0.12, 13.0, WindDirection.SOUTHSOUTHEAST, 14, 15, 0.16, "17", "http://18")
+        currentState += HourState(1, 20, 21, 0.22, 23.0, WindDirection.NORTHNORTHWEST, 24, 25, 0.26, "27", "http://28")
+        trigger.mergeStates(previousState, currentState)
+        val reaction = mock(Reaction::class.java)
+        val output = trigger.output(reaction)
+        val htmlText = output.text("text/html", -1)
+        assertThat(htmlText, containsString("Time"))
+        assertThat(htmlText, containsString("Temperature"))
+        assertThat(htmlText, containsString("feels like"))
+        assertThat(htmlText, containsString("Chance of Rain"))
+        assertThat(htmlText, containsString("Amount"))
+        assertThat(htmlText, containsString("Wind from"))
+        assertThat(htmlText, containsString("Speed"))
+        assertThat(htmlText, containsString("Gusts"))
+        assertThat(htmlText, containsString("Humidity"))
+        assertThat(htmlText, containsString("Description"))
+        assertThat(htmlText, containsString("Image"))
+    }
+
+    @Test
+    fun outputDoesNotContainColumnHeadersForMissingColumns() {
+        val currentState = WeatherState("Weather", ZonedDateTime.of(2016, 5, 28, 0, 0, 0, 0, of("Europe/Berlin")))
+        currentState += HourState(0, 10, null, 0.12, 13.0, WindDirection.SOUTHSOUTHEAST, 14, null, null, "17", "http://18")
+        currentState += HourState(1, 20, null, 0.22, 23.0, WindDirection.NORTHNORTHWEST, 24, null, null, "27", "http://28")
+        trigger.mergeStates(previousState, currentState)
+        val reaction = mock(Reaction::class.java)
+        val output = trigger.output(reaction)
+        val htmlText = output.text("text/html", -1)
+        assertThat(htmlText, containsString("Time"))
+        assertThat(htmlText, containsString("Temperature"))
+        assertThat(htmlText, not(containsString("feels like")))
+        assertThat(htmlText, containsString("Chance of Rain"))
+        assertThat(htmlText, containsString("Amount"))
+        assertThat(htmlText, containsString("Wind from"))
+        assertThat(htmlText, containsString("Speed"))
+        assertThat(htmlText, not(containsString("Gusts")))
+        assertThat(htmlText, not(containsString("Humidity")))
+        assertThat(htmlText, containsString("Description"))
+        assertThat(htmlText, containsString("Image"))
+    }
+
 }