✨ Use @TemplatePath annotations on most pages
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / pages / CreateReplyPageTest.kt
index 01f3361..ec56267 100644 (file)
@@ -2,22 +2,21 @@ package net.pterodactylus.sone.web.pages
 
 import net.pterodactylus.sone.data.Post
 import net.pterodactylus.sone.data.Sone
+import net.pterodactylus.sone.test.getInstance
 import net.pterodactylus.sone.test.mock
-import net.pterodactylus.sone.web.pages.WebPageTest
-import net.pterodactylus.sone.web.pages.CreateReplyPage
+import net.pterodactylus.sone.web.baseInjector
+import net.pterodactylus.sone.web.page.*
 import net.pterodactylus.util.web.Method.POST
 import org.hamcrest.MatcherAssert.assertThat
 import org.hamcrest.Matchers.equalTo
+import org.hamcrest.Matchers.notNullValue
 import org.junit.Test
 import org.mockito.Mockito.verify
 
 /**
  * Unit test for [CreateReplyPage].
  */
-class CreateReplyPageTest: WebPageTest() {
-
-       private val page = CreateReplyPage(template, webInterface)
-       override fun getPage() = page
+class CreateReplyPageTest: WebPageTest(::CreateReplyPage) {
 
        @Test
        fun `page returns correct path`() {
@@ -31,7 +30,7 @@ class CreateReplyPageTest: WebPageTest() {
 
        @Test
        fun `reply is created correctly`() {
-               request("", POST)
+               setMethod(POST)
                addHttpRequestPart("returnPage", "return.html")
                addHttpRequestPart("post", "post-id")
                addHttpRequestPart("text", "new text")
@@ -43,7 +42,7 @@ class CreateReplyPageTest: WebPageTest() {
 
        @Test
        fun `reply is filtered`() {
-               request("", POST)
+               setMethod(POST)
                addHttpRequestPart("returnPage", "return.html")
                addHttpRequestPart("post", "post-id")
                addHttpRequestPart("text", "new http://localhost:12345/KSK@foo text")
@@ -56,7 +55,7 @@ class CreateReplyPageTest: WebPageTest() {
 
        @Test
        fun `reply is created with correct sender`() {
-               request("", POST)
+               setMethod(POST)
                addHttpRequestPart("returnPage", "return.html")
                addHttpRequestPart("post", "post-id")
                addHttpRequestPart("text", "new text")
@@ -70,7 +69,7 @@ class CreateReplyPageTest: WebPageTest() {
 
        @Test
        fun `empty text sets parameters in template contexty`() {
-               request("", POST)
+               setMethod(POST)
                addHttpRequestPart("returnPage", "return.html")
                addHttpRequestPart("post", "post-id")
                addHttpRequestPart("text", "  ")
@@ -83,11 +82,21 @@ class CreateReplyPageTest: WebPageTest() {
 
        @Test
        fun `user is redirected to no permissions page if post does not exist`() {
-               request("", POST)
+               setMethod(POST)
                addHttpRequestPart("returnPage", "return.html")
                addHttpRequestPart("post", "post-id")
                addHttpRequestPart("text", "new text")
                verifyRedirect("noPermission.html")
        }
 
+       @Test
+       fun `page can be created by dependency injection`() {
+           assertThat(baseInjector.getInstance<CreateReplyPage>(), notNullValue())
+       }
+
+       @Test
+       fun `page is annotated with correct template path`() {
+           assertThat(page.templatePath, equalTo("/templates/createReply.html"))
+       }
+
 }