Replace Preferences with Kotlin version
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / pages / UnfollowSonePageTest.kt
1 package net.pterodactylus.sone.web.pages
2
3 import net.pterodactylus.sone.test.getInstance
4 import net.pterodactylus.sone.web.baseInjector
5 import net.pterodactylus.util.web.Method.POST
6 import org.hamcrest.MatcherAssert.assertThat
7 import org.hamcrest.Matchers.equalTo
8 import org.hamcrest.Matchers.notNullValue
9 import org.junit.Test
10 import org.mockito.Mockito.verify
11
12 /**
13  * Unit test for [UnfollowSonePage].
14  */
15 class UnfollowSonePageTest: WebPageTest(::UnfollowSonePage) {
16
17         @Test
18         fun `page returns correct path`() {
19             assertThat(page.path, equalTo("unfollowSone.html"))
20         }
21
22         @Test
23         fun `page requires login`() {
24             assertThat(page.requiresLogin(), equalTo(true))
25         }
26
27         @Test
28         fun `page returns correct page title`() {
29             addTranslation("Page.UnfollowSone.Title", "unfollow page title")
30                 assertThat(page.getPageTitle(freenetRequest), equalTo("unfollow page title"))
31         }
32
33         @Test
34         fun `get request does not redirect`() {
35                 verifyNoRedirect { }
36         }
37
38         @Test
39         fun `post request unfollows a single sone and redirects to return page`() {
40                 setMethod(POST)
41                 addHttpRequestPart("returnPage", "return.html")
42                 addHttpRequestPart("sone", "sone-id")
43                 verifyRedirect("return.html") {
44                         verify(core).unfollowSone(currentSone, "sone-id")
45                 }
46         }
47
48         @Test
49         fun `post request unfollows two sones and redirects to return page`() {
50                 setMethod(POST)
51                 addHttpRequestPart("returnPage", "return.html")
52                 addHttpRequestPart("sone", "sone-id1, sone-id2")
53                 verifyRedirect("return.html") {
54                         verify(core).unfollowSone(currentSone, "sone-id1")
55                         verify(core).unfollowSone(currentSone, "sone-id2")
56                 }
57         }
58
59         @Test
60         fun `page can be created by dependency injection`() {
61             assertThat(baseInjector.getInstance<UnfollowSonePage>(), notNullValue())
62         }
63
64 }