Convert view Sone page test to new web page test base
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / pages / MarkAsKnownPageTest.kt
1 package net.pterodactylus.sone.web.pages
2
3 import net.pterodactylus.sone.data.Post
4 import net.pterodactylus.sone.data.PostReply
5 import net.pterodactylus.sone.data.Sone
6 import net.pterodactylus.sone.test.mock
7 import net.pterodactylus.util.web.Method.POST
8 import org.hamcrest.MatcherAssert.assertThat
9 import org.hamcrest.Matchers.equalTo
10 import org.junit.Test
11 import org.mockito.Mockito.verify
12
13 /**
14  * Unit test for [MarkAsKnownPage].
15  */
16 class MarkAsKnownPageTest: WebPageTest() {
17
18         private val page = MarkAsKnownPage(template, webInterface)
19
20         override fun getPage() = page
21
22         @Test
23         fun `page returns correct path`() {
24                 assertThat(page.path, equalTo("markAsKnown.html"))
25         }
26
27         @Test
28         fun `page does not require login`() {
29                 assertThat(page.requiresLogin(), equalTo(false))
30         }
31
32         @Test
33         fun `page returns correct title`() {
34                 addTranslation("Page.MarkAsKnown.Title", "mark as known page title")
35                 assertThat(page.getPageTitle(freenetRequest), equalTo("mark as known page title"))
36         }
37
38         @Test
39         fun `posts can be marked as known`() {
40                 setMethod(POST)
41                 addHttpRequestPart("returnPage", "return.html")
42                 addHttpRequestPart("type", "post")
43                 addHttpRequestPart("id", "post1 post2 post3")
44                 val posts = listOf(mock<Post>(), mock<Post>())
45                 addPost("post1", posts[0])
46                 addPost("post3", posts[1])
47                 verifyRedirect("return.html") {
48                         verify(core).markPostKnown(posts[0])
49                         verify(core).markPostKnown(posts[1])
50                 }
51         }
52
53         @Test
54         fun `replies can be marked as known`() {
55                 setMethod(POST)
56                 addHttpRequestPart("returnPage", "return.html")
57                 addHttpRequestPart("type", "reply")
58                 addHttpRequestPart("id", "reply1 reply2 reply3")
59                 val replies = listOf(mock<PostReply>(), mock<PostReply>())
60                 addPostReply("reply1", replies[0])
61                 addPostReply("reply3", replies[1])
62                 verifyRedirect("return.html") {
63                         verify(core).markReplyKnown(replies[0])
64                         verify(core).markReplyKnown(replies[1])
65                 }
66         }
67
68         @Test
69         fun `sones can be marked as known`() {
70                 setMethod(POST)
71                 addHttpRequestPart("returnPage", "return.html")
72                 addHttpRequestPart("type", "sone")
73                 addHttpRequestPart("id", "sone1 sone2 sone3")
74                 val sones = listOf(mock<Sone>(), mock<Sone>())
75                 addSone("sone1", sones[0])
76                 addSone("sone3", sones[1])
77                 verifyRedirect("return.html") {
78                         verify(core).markSoneKnown(sones[0])
79                         verify(core).markSoneKnown(sones[1])
80                 }
81         }
82
83         @Test
84         fun `different type redirects to invalid page`() {
85                 setMethod(POST)
86                 addHttpRequestPart("type", "foo")
87                 verifyRedirect("invalid.html")
88         }
89
90 }