1 package net.pterodactylus.sone.web.pages
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
11 import org.mockito.Mockito.verify
14 * Unit test for [MarkAsKnownPage].
16 class MarkAsKnownPageTest: WebPageTest() {
18 private val page = MarkAsKnownPage(template, webInterface)
20 override fun getPage() = page
23 fun `page returns correct path`() {
24 assertThat(page.path, equalTo("markAsKnown.html"))
28 fun `page does not require login`() {
29 assertThat(page.requiresLogin(), equalTo(false))
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"))
39 fun `posts can be marked as known`() {
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])
54 fun `replies can be marked as known`() {
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])
69 fun `sones can be marked as known`() {
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])
84 fun `different type redirects to invalid page`() {
86 addHttpRequestPart("type", "foo")
87 verifyRedirect("invalid.html")