🚧 Add Loaders to all template-using pages
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / pages / IndexPageTest.kt
index ead3cbb..e52accb 100644 (file)
@@ -5,13 +5,17 @@ import com.google.common.base.Predicate
 import net.pterodactylus.sone.data.Post
 import net.pterodactylus.sone.data.Sone
 import net.pterodactylus.sone.notify.PostVisibilityFilter
+import net.pterodactylus.sone.test.getInstance
 import net.pterodactylus.sone.test.mock
 import net.pterodactylus.sone.test.whenever
 import net.pterodactylus.sone.utils.Pagination
+import net.pterodactylus.sone.web.baseInjector
+import net.pterodactylus.sone.web.page.*
 import org.hamcrest.MatcherAssert.assertThat
 import org.hamcrest.Matchers.contains
 import org.hamcrest.Matchers.emptyIterable
 import org.hamcrest.Matchers.equalTo
+import org.hamcrest.Matchers.notNullValue
 import org.junit.Before
 import org.junit.Test
 import org.mockito.ArgumentMatchers
@@ -19,7 +23,7 @@ import org.mockito.ArgumentMatchers
 /**
  * Unit test for [IndexPage].
  */
-class IndexPageTest: WebPageTest2({ template, webInterface -> IndexPage(template, webInterface, postVisibilityFilter) }) {
+class IndexPageTest: WebPageTest({ template, webInterface, loaders -> IndexPage(template, webInterface, loaders, postVisibilityFilter) }) {
 
        companion object {
                private val postVisibilityFilter = mock<PostVisibilityFilter>()
@@ -38,7 +42,7 @@ class IndexPageTest: WebPageTest2({ template, webInterface -> IndexPage(template
        @Test
        fun `page returns correct title`() {
                whenever(l10n.getString("Page.Index.Title")).thenReturn("index page title")
-           assertThat(page.getPageTitle(freenetRequest), equalTo("index page title"))
+           assertThat(page.getPageTitle(soneRequest), equalTo("index page title"))
        }
 
        @Before
@@ -134,7 +138,7 @@ class IndexPageTest: WebPageTest2({ template, webInterface -> IndexPage(template
        fun `index page sets page correctly`() {
                val posts = listOf(createPost(3000), createPost(2000), createPost(1000))
                whenever(currentSone.posts).thenReturn(posts)
-               core.preferences.postsPerPage = 1
+               core.preferences.newPostsPerPage = 1
                addHttpRequestParameter("page", "2")
                page.processTemplate(freenetRequest, templateContext)
                @Suppress("UNCHECKED_CAST")
@@ -143,7 +147,7 @@ class IndexPageTest: WebPageTest2({ template, webInterface -> IndexPage(template
 
        @Test
        fun `index page without posts sets correct pagination`() {
-               core.preferences.postsPerPage = 1
+               core.preferences.newPostsPerPage = 1
                page.processTemplate(freenetRequest, templateContext)
                @Suppress("UNCHECKED_CAST")
                (templateContext["pagination"] as Pagination<Post>).let { pagination ->
@@ -151,4 +155,14 @@ class IndexPageTest: WebPageTest2({ template, webInterface -> IndexPage(template
                }
        }
 
+       @Test
+       fun `page can be created by dependency injection`() {
+           assertThat(baseInjector.getInstance<IndexPage>(), notNullValue())
+       }
+
+       @Test
+       fun `page is annotated with correct menuname`() {
+           assertThat(page.menuName, equalTo("Index"))
+       }
+
 }