Add test for index page without any posts
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 5 May 2017 20:49:20 +0000 (22:49 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 5 May 2017 20:52:16 +0000 (22:52 +0200)
src/test/kotlin/net/pterodactylus/sone/web/pages/IndexPageTest.kt

index 990aacf..6d87f3a 100644 (file)
@@ -11,6 +11,7 @@ import net.pterodactylus.sone.utils.Pagination
 import net.pterodactylus.util.web.Method.GET
 import org.hamcrest.MatcherAssert.assertThat
 import org.hamcrest.Matchers.contains
+import org.hamcrest.Matchers.emptyIterable
 import org.hamcrest.Matchers.equalTo
 import org.junit.Before
 import org.junit.Test
@@ -146,4 +147,15 @@ class IndexPageTest : WebPageTest() {
                assertThat((templateContext["pagination"] as Pagination<Post>).page, equalTo(2))
        }
 
+       @Test
+       fun `index page without posts sets correct pagination`() {
+               request("", GET)
+               core.preferences.postsPerPage = 1
+               page.processTemplate(freenetRequest, templateContext)
+               @Suppress("UNCHECKED_CAST")
+               (templateContext["pagination"] as Pagination<Post>).let { pagination ->
+                       assertThat(pagination.items, emptyIterable())
+               }
+       }
+
 }