1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.core.*
4 import net.pterodactylus.sone.test.*
5 import net.pterodactylus.sone.web.*
6 import net.pterodactylus.sone.web.page.*
7 import net.pterodactylus.util.web.Method.*
8 import org.hamcrest.MatcherAssert.*
9 import org.hamcrest.Matchers.*
11 import org.mockito.ArgumentMatchers.anyLong
12 import org.mockito.Mockito.never
13 import org.mockito.Mockito.verify
16 * Unit test for [RescuePage].
18 class RescuePageTest : WebPageTest(::RescuePage) {
20 private val soneRescuer = mock<SoneRescuer>()
23 fun setupSoneRescuer() {
24 whenever(core.getSoneRescuer(currentSone)).thenReturn(soneRescuer)
28 fun `page returns correct path`() {
29 assertThat(page.path, equalTo("rescue.html"))
33 fun `page requires login`() {
34 assertThat(page.requiresLogin(), equalTo(true))
38 fun `page returns correct title`() {
39 addTranslation("Page.Rescue.Title", "rescue page title")
40 assertThat(page.getPageTitle(soneRequest), equalTo("rescue page title"))
44 fun `get request sets rescuer in template context`() {
46 assertThat(templateContext["soneRescuer"], equalTo<Any>(soneRescuer))
51 fun `post request redirects to rescue page`() {
53 verifyRedirect("rescue.html")
57 fun `post request with fetch starts next fetch`() {
59 addHttpRequestPart("fetch", "true")
60 verifyRedirect("rescue.html") {
61 verify(soneRescuer).startNextFetch()
66 fun `page can be created by dependency injection`() {
67 assertThat(baseInjector.getInstance<RescuePage>(), notNullValue())
71 fun `page is annotated with correct menuname`() {
72 assertThat(page.menuName, equalTo("Rescue"))
76 fun `page is annotated with correct template path`() {
77 assertThat(page.templatePath, equalTo("/templates/rescue.html"))