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